Сортировка Шелла (Последовательность Хиббарда)
procedureSORT_Shell;
Var
d: array [0..29] of integer := (1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431, 67108863, 134217727, 268435455, 536870911, 1073741823);
g, w: integer;
c: boolean;
Begin
counter_iter := 0;
counter_sr := 0;
counter_per := 0;
t1 := 0;
t2 := 0;
textcolor(10);
Writeln;
Writeln('<< Подключена процедура сортировки Шелла >>');
Textcolor(7);
t1 := milliseconds;
while d[w + 1] <= Length(b) do
inc(w);
Repeat
g := d[w];
i := g;
Repeat
j := i - g;
if j + g >= Length(b) then break;
c := True;
Repeat
counter_sr := counter_sr + 1;
if b[j] <= b[(j + g)] then
c := False
Else
Begin
z := b[j];
b[j] := b[j + g];
b[j + g] := z;
k := Number_El[j];
Number_El[j] := Number_El[j + g];
counter_per := counter_per + 1;
Number_El[j + g] := k;
end;
dec(j, g);
until not ((j >= 0) and C);
inc(i);
until not (i <= Length(b));
dec(w);
until not (w <> -1);
t2 := milliseconds;
textcolor(10);
Writeln('<<Конец процедуры... >>');
Textcolor(7);
end;
Сортировка подсчётом
procedure SORT_Count;
Var
arr_sort_count, place: array of byte;
i, j, k: integer;
Begin
counter_iter := 0;
counter_sr := 0;
counter_per := 0;
t1 := 0;
t2 := 0;
t1 := milliseconds;
textcolor(10);
Writeln;
Writeln('<< Подключена процедура сортировки подсчётом >>');
Textcolor(7);
setlength(arr_sort_count, 256);
setlength(place, 257);
setlength(Number_El, High(b) + 1);
for i := 0 to High(b) do
inc(Arr_sort_count[b[i]]);
for i := 1 to 255 do
place[i] := place[i - 1] + Arr_sort_count[i];
for i := 0 to High(b) do
Begin
if place[b[i]] <>0 then //Если будет = 0 вылезет Outside index
Begin
Number_El[place[b[i]] - 1] := i;
dec(place[b[i]]);
End
end;
for i := 1 to 255 do
for j := 1 to Arr_sort_count[i] do
Begin
b[k] := i;
inc(k);
end;
textcolor(10);
Writeln('<<Конец процедуры... >>');
|
|
Textcolor(7);
t2 := milliseconds;
arr_sort_count := nil; //Очистка памяти
place := nil;
end;
Бинарный поиск
procedure Binary_Search;
Begin
cp := false;
if Time_CP >= B[0] then
Begin
cp := true;
left := 0; right := s;
while left <= right do
Begin
mid := (left + right) div 2;
if Time_CP < B[mid] then
right := mid - 1
Else
if ((mid) <= S) and (Time_CP >= B[mid]) then
left := mid + 1
Else
Begin
left := mid + 1;
right := mid;
if Time_CP = B[mid] then
Begin
left := mid + 1;
right := mid;
end;
end;
if time_cp - b[mid] <0 then
mid := mid - 1;
end;
end;
end;
Дата добавления: 2020-01-07; просмотров: 287; Мы поможем в написании вашей работы! |
Мы поможем в написании ваших работ!