.[题目分析] 建立递增有序的顺序表对每个输入数据应首先查找该数据在顺序表中的位置若表中没有该元素则插入之如已有该元素则不再插入为此采用折半查找方法
FUNC BinSearch(VAR asqlisttp;xinteger)integer;
∥在顺序表a中查找值为x的元素如查找成功返回值如x不在a中则返回查找失败时的较大下标值
low:=;high:=alast;found:=false;
WHILE(low<=high)AND NOT found DO
[mid:=(low+high)DIV ;
IF aelem[mid]=x THEN found:=true
ELSE IF aelem[mid]>x THEN high:=mid ELSE low:=mid+;
]
IF found=true THEN return()
ELSE return(low);∥当查找失败时low=high+
ENDF;∥结束对分查找函数
PROC create(VAR Lsqlisttp)∥本过程生成顺序表L
Llast:=;∥顺序表L初始化
read(x);
WHILE x<> DO∥设x=时退出输入
[k:=binsearch(Lx);∥去查找x元素
IF k<>∥不同元素才插入
THEN [FOR i:=Llast DOWNTO k DO Lelem[i+]:=Lelem[i];
Lelem[k]=x;Llast:= Llast+;∥插入元素x线性表长度增
]
read(x);
]
ENDP;∥结束过程creat
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []