//冒泡排序
procedure fSort(var inX:array of double)
var temp:double
i,j,n:integer
flag:boolean
Begin
for i:=Low(inX) to High(inX) do
for j := Low(inX) to High(inX) - 1 do
if inX[j] > inX[j + 1] then
begin
temp := inX[j]
inX[j] := inX[j + 1]
inX[j + 1] := temp
end
end;
//折半查找:
function BinarySearch(A: Array of integer
low:integer
high:integer
k:integer ):integer
//假设A是升序排列的
var
iLow,iHigh,iMid: integer
// 折半的下界,上界,和折半的中间值
begin
iLow:= low
iHigh:= high
iMid:= (iLow + iHigh) div 2
while (iLow <> iHigh) do
begin
if A[iMid] > K then
iHigh:= iMid
if A[iMid] < K then
iLow:= iMid
if A[iMid] = K then
begin
Result:= iMid
Break
end
iMid:= (iLow + iHigh) div 2
// 保证循环用
end
if (iLow = iHigh) then
result:= -1
// 返回-1表明没有找到
end;