From b0a2b56e0f2610f73b9e003534abe0b6bec92319 Mon Sep 17 00:00:00 2001 From: anis Jradah Date: Sat, 29 Oct 2022 12:48:30 +0300 Subject: [PATCH] bubble sort in python with random numbers --- Python Basic Programs/bubble_sort.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Python Basic Programs/bubble_sort.py 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