From 15319692b5057e43f1def80ba75fa6a4bdef8920 Mon Sep 17 00:00:00 2001 From: RujutaKelkar <32394332+RujutaKelkar@users.noreply.github.com> Date: Tue, 16 Oct 2018 00:22:30 +0530 Subject: [PATCH] added code in python (#19274) * added code in python Added bubble sort code in python * fix: code formatting --- .../sorting-algorithms/bubble-sort/index.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/client/src/pages/guide/english/algorithms/sorting-algorithms/bubble-sort/index.md b/client/src/pages/guide/english/algorithms/sorting-algorithms/bubble-sort/index.md index eafa8636cb3..55325a67649 100644 --- a/client/src/pages/guide/english/algorithms/sorting-algorithms/bubble-sort/index.md +++ b/client/src/pages/guide/english/algorithms/sorting-algorithms/bubble-sort/index.md @@ -142,6 +142,21 @@ func bubbleSort(_ inputArray: [Int]) -> [Int] { } return numbers // return the sorted array } +``` +### Example in Python +```py + +def bubblesort( A ): + for i in range( len( A ) ): + for k in range( len( A ) - 1, i, -1 ): + if ( A[k] < A[k - 1] ): + swap( A, k, k - 1 ) + +def swap( A, x, y ): + tmp = A[x] + A[x] = A[y] + A[y] = tmp + ``` ### More Information