|
1 |
| -{ |
2 |
| - NOTE: Things in the examples representing algorithms may contain the number |
3 |
| - '2' appending the name. This is because this method is already offered |
4 |
| - by Simba and is readily available. It is therefore recommended to not |
5 |
| - recreate the created (for speed, etc). |
6 |
| -} |
7 |
| -
|
8 |
| -//Sorts an array of Integers (TIA) using the bubble sorting algorithm in |
9 |
| - //ascending order (Lowest to Highest). |
10 |
| -procedure BubbleSort2(var TIA: TIntegerArray); |
11 |
| -var |
12 |
| - i, bI, TMP: Integer; |
13 |
| - UnSorted: Boolean; |
14 |
| -begin |
15 |
| - UnSorted := True; |
16 |
| - bI := High(TIA); |
17 |
| - while (UnSorted) do |
18 |
| - begin |
19 |
| - UnSorted := False; |
20 |
| - for i := bI downto 1 do |
21 |
| - if(TIA[i] < TIA[i - 1]) then |
22 |
| - begin |
23 |
| - TMP := TIA[i]; |
24 |
| - TIA[i] := TIA[i - 1]; |
25 |
| - TIA[i - 1] := TMP; |
26 |
| - UnSorted := True; |
27 |
| - end; |
28 |
| - end; |
29 |
| -end; |
30 |
| -
|
31 |
| -var |
32 |
| - UnsortedArray: TIntegerArray; |
33 |
| -
|
34 |
| -begin |
35 |
| - UnsortedArray := [5, 1, 23, -3, 9, -7]; |
36 |
| - BubbleSort2(UnsortedArray); |
37 |
| - Writeln(UnsortedArray); // Well, now the SortedArray :-P |
38 |
| -end. |
| 1 | +{ |
| 2 | + NOTE: Things in the examples representing algorithms may contain the number |
| 3 | + '2' appending the name. This is because this method is already offered |
| 4 | + by Simba and is readily available. It is therefore recommended to not |
| 5 | + recreate the created (for speed, etc). |
| 6 | +} |
| 7 | + |
| 8 | +//Sorts an array of Integers (TIA) using the bubble sorting algorithm in |
| 9 | + //ascending order (Lowest to Highest). |
| 10 | +procedure BubbleSort2(var TIA: TIntegerArray); |
| 11 | +var |
| 12 | + i, bI, TMP: Integer; |
| 13 | + UnSorted: Boolean; |
| 14 | +begin |
| 15 | + UnSorted := True; |
| 16 | + bI := High(TIA); |
| 17 | + while (UnSorted) do |
| 18 | + begin |
| 19 | + UnSorted := False; |
| 20 | + for i := bI downto 1 do |
| 21 | + if(TIA[i] < TIA[i - 1]) then |
| 22 | + begin |
| 23 | + TMP := TIA[i]; |
| 24 | + TIA[i] := TIA[i - 1]; |
| 25 | + TIA[i - 1] := TMP; |
| 26 | + UnSorted := True; |
| 27 | + end; |
| 28 | + end; |
| 29 | +end; |
| 30 | + |
| 31 | +var |
| 32 | + UnsortedArray: TIntegerArray; |
| 33 | + |
| 34 | +begin |
| 35 | + UnsortedArray := [5, 1, 23, -3, 9, -7]; |
| 36 | + BubbleSort2(UnsortedArray); |
| 37 | + Writeln(UnsortedArray); // Well, now the SortedArray :-P |
| 38 | +end. |
0 commit comments