robby@nuchat.sccsi.com (Robert Oliver Jr.) (05/30/91)
Hello!
I need some help. I'm using a 286 with a math coprocessor. The code is
running under Turbo Pascal 6.0. I thank it is best to so the code and then
explane the problem.
program tsort;
uses Crt,dos;
type
list= array[1..20] of integer;
list1=array[1..20] of integer;
var
data: list;
data1:list1;
i: integer;
procedure quicksort(var a: list; Lo,Hi: integer);
procedure sort(left,right: integer);
var
index,match,curent,pos: integer;
test:longint;
begin
index:=left;
match:=right;
curent:=a[(left+right) DIV 2];
{test:=data1[(left+right)div 2];
test:=((left+right)div 2);}
repeat
while a[index]<curent do index:=index+1;
while curent<a[match] do match:=match-1;
data1[((left+right)Div 2)]:=index;
test:=index+1;
if index<=match then
begin
pos:=a[index];
a[index]:=a[match];
a[match]:=pos;
index:=index+1;
match:=match-1;
end;
until index>match;
data1[((left+right)Div 2)]:=index;
if left<match then sort(left,match);
if index<right then sort(index,right);
end;
begin {quicksort};
sort(Lo,Hi);
end;
begin {qsort}
clrscr;
Write('Now generating 20 random numbers...');
Randomize;
writeln;writeln;
for i:=1 to 20 do data[i]:=Random(2500);
for i:=1 to 20 do begin
gotoxy(1,i+3);
write(data[i]);
end;
quicksort(data,1,20);
gotoxy(1,3);
write('Indata Outdata Sortdata postion');
for i:=1 to 20 do begin
gotoxy(15,i+3);
write(data1[i]);
gotoxy(35,i+3);
Write(data[i]{:8});
gotoxy(50,i+3);
write(i);
end;
end.
(*************** This is what the code is producing **********************)
Now generating 20 randomm numbers......
Indata Outdata Sortdata Postion
1871 2 131 1
246 3 246 2
131 2 276 3
1119 5 327 4
1102 6 430 5
1848 7 474 6
1407 8 563 7
2101 8 848 8
276 10 1102 9
2450 14 1119 10
327 12 1407 11
1511 13 1511 12
1544 14 1544 13
1854 14 1560 14
1846 16 1846 15
563 17 1848 16
848 18 1854 17
430 19 1871 18
474 20 2101 19
1560 -10320 2450 20
(****************** This is what the code is to do ************************)
Now generating 20 randomm numbers......
Indata Outdata Sortdata Postion
1871 18 131 1
246 2 246 2
131 1 276 3
1119 10 327 4
1102 9 430 5
1848 16 474 6
1407 11 563 7
2101 19 848 8
276 3 1102 9
2450 20 1119 10
327 4 1407 11
1511 12 1511 12
1544 13 1544 13
1854 17 1560 14
1846 15 1846 15
563 7 1848 16
848 8 1854 17
430 5 1871 18
474 6 2101 19
1560 14 2450 20
What am I doing wrong?
How can I correct the Bug???????????
Thanks for the help.... Robert Oliver
robby@nuchat.sccsi.comdevisser@cs.utwente.nl (Jan de Visser) (06/03/91)
In article <1991May30.052548.9870@nuchat.sccsi.com>, robby@nuchat.sccsi.com (Robert Oliver Jr.) writes: |> Hello! |> |> I need some help. I'm using a 286 with a math coprocessor. The code is |> running under Turbo Pascal 6.0. I thank it is best to so the code and then |> explane the problem. |> |> [ (lots of) code and (lots of) numbers deleted ] |> |> What am I doing wrong? |> How can I correct the Bug??????????? |> |> Thanks for the help.... Robert Oliver |> robby@nuchat.sccsi.com Dear Robert, Do you seriously expect people, which all have their own work to do, to debug YABQR (Yet Another Boring Quicksort Routine) for you? Most of us have our own debugging to do! I will be happy to give you a clue on details, which cause the trouble, but you'll first have to identify the source of your problem. (Probably you won't need any more help by then ;). Good Luck, Jan. PS: Consult a book on algorithms. Maybe this will clear things up.