Iam_Sandeep

Untitled

Sep 14th, 2022
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. a=[0,0,1,0,1,2,1,2,2]
  2. '''
  3. selection sort:n^2
  4.  
  5. 1)bubble sort:n^2
  6.  
  7. 2)merge sort  :n log n
  8.  
  9. 3) O(n)
  10. '''
  11. x,y,z=0,0,0
  12.  
  13. for i in a:
  14.     if i==0:x+=1
  15.     elif i==1:y+=1
  16.     else:z+=1
  17. i=0
  18. while x:
  19.     a[i]=0
  20.     x=x-1
  21.     i=i+1
  22. while y:
  23.     a[i]=1
  24.     y=y-1
  25.     i=i+1
  26. while z:
  27.     a[i]=2
  28.     z=z-1
  29.     i=i+1
  30. print(a)
  31.    
Advertisement
Add Comment
Please, Sign In to add comment