-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubble_Sort.py
More file actions
29 lines (23 loc) · 784 Bytes
/
Bubble_Sort.py
File metadata and controls
29 lines (23 loc) · 784 Bytes
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
"""
FUNCTION BubbleSort(MyList : ARRAY) RETURNS ARRAY
DECLARE Count, Current, Temp : INTEGER
FOR Count <- 1 TO LEN(MyList)
FOR Index <- 1 TO LEN(MyList) - Count
IF MyList[Index] > MyList[Index + 1] THEN
Temp = MyList[Index]
MyList[Index] = MyList[Index + 1]
MyList[Index + 1] = Temp
NEXT Index
NEXT Count
RETURNS MyList
ENDFUNCTION
"""
def BubbleSort(MyList):
Temp = 0;
for Count in range(0, len(MyList)-1):
for Index in range(len(MyList)-1-Count):
if MyList[Index] > MyList[Index + 1]:
MyList[Index], MyList[Index + 1] = MyList[Index + 1], MyList[Index]
return MyList
List = [10, 4, 7, 2, 3, 8, 1, 9, 5, 6]
print(BubbleSort(List))