SHARE
TWEET

BucketSort for integer

michalkowalczyk Dec 8th, 2018 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Sat Dec  8 13:38:43 2018
  4.  
  5. @author: micha
  6. """
  7.  
  8. A=[]
  9. from random import randint    
  10. for i in range(0,100):
  11.     A.append(randint(1,100))
  12.  
  13. print(A)
  14. print()
  15.  
  16.  
  17. B=[0]*(len(A)+1)
  18.  
  19. def BucketSort(A):
  20.     n=len(A)
  21.    
  22.     for i in (A):
  23.        B[i]+=1     #zlicza ile jest tych samych liczb i zapisuje je do elementu o odpowiednim indeksie
  24.        
  25.        
  26.     j=0
  27.     for i in range(n+1):
  28.         while(B[i]>0):
  29.             A[j]= i
  30.             B[i]-=1
  31.             j+=1
  32.        
  33. BucketSort(A)
  34. print(A)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top