Advertisement
SigmaBoy456

O(n^2) bubblesort python + OOP(inther) #2453

Feb 17th, 2025
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. class algorithms:
  2.     def bubblesort(self, li, *,reversed=False):
  3.         for i in range(len(li)):
  4.             for j in range(i+1,len(li)):
  5.                 if (li[i] < li[j] if reversed else li[i] > li[j]):
  6.                     li[i], li[j] = li[j], li[i]
  7. class Solution(algorithms):
  8.     pass
  9. Sol1 = Solution()
  10. unsortedarr = [3, 1, 2, 4, 5, 6, 7]
  11. unsortedrev = [3, 1, 2, 4, 5, 6, 7]
  12. print("WIth no reverse: ")
  13. Sol1.bubblesort(unsortedarr)
  14. print(unsortedarr)
  15. print("WIth Reversed:")
  16. Sol1.bubblesort(unsortedrev, reversed=True)
  17. print(unsortedrev)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement