From fd160e5b6a3b7c46be3194988649da15941d0a92 Mon Sep 17 00:00:00 2001 From: Ritesh8732 <47283395+Ritesh8732@users.noreply.github.com> Date: Thu, 24 Oct 2019 14:34:52 +0530 Subject: [PATCH] create bubble sort --- algorithms/bubble_sorting/bubble.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 algorithms/bubble_sorting/bubble.py diff --git a/algorithms/bubble_sorting/bubble.py b/algorithms/bubble_sorting/bubble.py new file mode 100644 index 0000000..ca00220 --- /dev/null +++ b/algorithms/bubble_sorting/bubble.py @@ -0,0 +1,23 @@ + +def bubbleSort(arr): + n = len(arr) + + # Traverse through all array elements + for i in range(n): + + # Last i elements are already in place + for j in range(0, n-i-1): + + # traverse the array from 0 to n-i-1 + # Swap if the element found is greater + # than the next element + if arr[j] > arr[j+1] : + arr[j], arr[j+1] = arr[j+1], arr[j] + +# Driver code to test above +arr = [64, 34, 25, 12, 22, 11, 90] + +bubbleSort(arr) + +print ("Sorted array is:") +for i in range(len(arr)):