diff --git a/Python/BubbleSort.py b/Python/BubbleSort.py new file mode 100644 index 0000000..6bd8c61 --- /dev/null +++ b/Python/BubbleSort.py @@ -0,0 +1,27 @@ + + +def bubbleSort(array): + + # loop to access each array element + for i in range(len(array)): + + # loop to compare array elements + for j in range(0, len(array) - i - 1): + + # compare two adjacent elements + # change > to < to sort in descending order + if array[j] > array[j + 1]: + + # swapping elements if elements + # are not in the intended order + temp = array[j] + array[j] = array[j+1] + array[j+1] = temp + + +data = [-2, 45, 0, 11, -9] + +bubbleSort(data) + +print('Sorted Array in Ascending Order:') +print(data)