From 61af8bf8db546e879050e271bd767482f5f15609 Mon Sep 17 00:00:00 2001 From: Ayushi Dixit <54481701+ayu16@users.noreply.github.com> Date: Sun, 4 Oct 2020 17:01:45 +0530 Subject: [PATCH] Create bubble_sort1.py --- Python/bubble_sort1.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Python/bubble_sort1.py diff --git a/Python/bubble_sort1.py b/Python/bubble_sort1.py new file mode 100644 index 0000000..c30e402 --- /dev/null +++ b/Python/bubble_sort1.py @@ -0,0 +1,25 @@ +# Python program for implementation of Bubble Sort + +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)): + print ("%d" %arr[i]),