diff --git a/Python Basic Programs/bubble_sort.py b/Python Basic Programs/bubble_sort.py new file mode 100644 index 0000000..19b118e --- /dev/null +++ b/Python Basic Programs/bubble_sort.py @@ -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) \ No newline at end of file