m2skills

bubble py

Apr 9th, 2017
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. def bubbleSort(myList2):
  2.     for i in range(len(myList2)):
  3.         for j in range((len(myList2)-1)):
  4.             if myList2[j] > myList2[j+1]:
  5.                 myList2[j],myList2[j+1] = myList2[j+1],myList2[j]
  6.  
  7.     return myList2
  8.  
  9. # main function
  10. print("Enter the array to be sorted : ")
  11. myList1 = list(map(int, input().strip().split(",")))
  12.  
  13. bubbleSort(myList1)
  14. print("The List after applying Bubble Sort is : ")
  15. print(myList1)
Add Comment
Please, Sign In to add comment