-
Notifications
You must be signed in to change notification settings - Fork 0
/
bubble_sort.vsl
53 lines (46 loc) · 939 Bytes
/
bubble_sort.vsl
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
var array[10], i, j, temp, n
func main() begin
n := 10
// Initialize array with values
array[0] := 34
array[1] := 12
array[2] := 25
array[3] := 9
array[4] := 45
array[5] := 18
array[6] := 29
array[7] := 5
array[8] := 38
array[9] := 22
// Bubble sort
i := 0
while i < n-1 do begin
j := 0
while j < n-i-1 do begin
if array[j] > array[j+1] then begin
temp := array[j]
array[j] := array[j+1]
array[j+1] := temp
end
j := j + 1
end
i := i + 1
end
// Print sorted array
i := 0
while i < n do begin
print "Element ", i, ": ", array[i]
i := i + 1
end
end
//TESTCASE:
//Element 0: 5
//Element 1: 9
//Element 2: 12
//Element 3: 18
//Element 4: 22
//Element 5: 25
//Element 6: 29
//Element 7: 34
//Element 8: 38
//Element 9: 45