Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Python Basic Programs/bubble_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Bubble Sort for array of random numbers
import random
#intialize array
array = random.sample(range(1,100),30) # select 30 numbers from a range of 100
temp_variable =0

#print the orginal non sorted array
print ("Elements of the array: ", array)

#sort the array in ascendind order
for i in range(0, len(array)):
for j in range(i+1, len(array)):
if (array[i] > array[j]):
temp_variable = array[i]
array[i] = array[j]
array[j] = temp_variable

print()

print("Sorted array in ascending order: ")
print(array)