-
Notifications
You must be signed in to change notification settings - Fork 0
/
testsort.pas
73 lines (64 loc) · 1.51 KB
/
testsort.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
(*
Copy of the sorting section of banzdemo.p with OCR errors fixed.
This is so I can make sure I understand it as it isn't actually
the usual bubble sort.
Adjusted fot the Online Pascal Compiler at
https://www.onlinegdb.com/.
*)
program SortingTest;
var
np: integer;
votes: array [1..10] of integer;
swaps : integer;
procedure setup() ;
begin
votes[1] := 5;
votes[2] := 1;
votes[3] := 4;
votes[4] := 2;
votes[5] := 3;
np := 5;
swaps := 0
end;
procedure sortfile();
(* ?bubblesort? ' 'votes' by votes *)
(* This isn't really bubblesort, but that is what the banzdemo
called it. this was slow in the before time, so the write is
to show it is working. It sorts descending *)
var ka, kb, kc: integer;
begin
write('Sorting data');
swaps := 0;
for ka := 1 to np-1 do
begin
write('.');
for kb := ka to np do
{ If v_ka less than v_kb then out of order }
if votes[kb] > votes[ka] then (* votes[ka] < votes[kb' *)
begin
swaps := swaps + 1;
kc := votes[ka];
votes[ka] := votes[kb];
votes[kb] := kc;
end;
end;
writeln();
end;
procedure print();
var ka: integer;
begin
write('Swaps=');
writeln(swaps);
write('np=');
writeln(np);
for ka := 1 to np do begin
writeln(votes[ka])
end
end;
begin
writeln('=====Sorting Test =========');
setup();
sortfile();
print();
writeln('===========================')
end.