diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 46f10eb44..a1ad4161d 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -3,4 +3,5 @@ Nicole Mazzuca Marius Becker Gathros Jeremie Gillet (- Jie -) -Salim Khatib \ No newline at end of file +Salim Khatib +Hitesh C diff --git a/chapters/sorting_searching/bubble/code/python/bubblesort.py b/chapters/sorting_searching/bubble/code/python/bubblesort.py new file mode 100644 index 000000000..e1bc22831 --- /dev/null +++ b/chapters/sorting_searching/bubble/code/python/bubblesort.py @@ -0,0 +1,23 @@ +#!usr/bin/python3 + +#import section +import random + + +def bubble_sort(array): + len_array = len(array) + for i in range(len_array): + for j in range(len_array - i - 1): + if(array[j] > array[j+1]): + array[j], array[j+1] = array[j+1], array[j] #swap elements in the list + + +def main(): + number = [random.randint(0, 10000) for _ in range(10)] + print("Before Sorting {}".format(number)) + bubble_sort(number) + print("After Sorting {}".format(number)) + + +if __name__ == "__main__": + main()