class sorting(object): def __init__(self,num_arrayt): self.num_array=num_array self.bucket=bucket def accept(self): for k in range (int(x)): n=raw_input("num ?") num_array.append(int(n)) def display(self): print(num_array) def qsort(self,l,r): if l<r : i,j,p=l,r+1,self.num_array[l] while i<j: i=i+1 while self.num_array[i]<p: i=1+i if i==int(x): break j=j-1 while self.num_array[j]>p: j=j-1 if i<j: self.num_array[i],self.num_array[j]=self.num_array[j],self.num_array[i] self.num_array[l],self.num_array[j]=self.num_array[j],self.num_array[l] self.qsort(l,j-1) self.qsort(j+1,r) def radix_sort(self,len1,n): i=1 while i<=len1: j=0 while j<n: x=self.num_array[j]%pow(10,i) if(i>1): x=self.num_array[j]/pow(10,i-1) k=0 while k<n: if self.bucket[x][k]==-1: self.bucket[x][k]=self.num_array[j] break; else: k=k+1 j=j+1 k=0 x=0 while x<10: y=0 while y<n: if(self.bucket[x][y]!=-1): self.num_array[k]=self.bucket[x][y] self.bucket[x][y]=-1 k=k+1 else: break; y=y+1 x=x+1 i=i+1 def digit(self,lenght): max=07 i=0 while(i<lenght): if(self.num_array[i]>max): max=a[i] i=i+1 len1=0 while(max!=0): max=max/10 len1=len1+1 return len1 def Shell(self): n=int(x) step=int(n/2) while(step>0): i=step while(i<n): temp=self.num_array[i] j=i while(j>=step): if(temp<self.num_array[j-step]): self.num_array[j]=self.num_array[j-step] else: break j=j-step self.num_array[j]=temp i+=1 step=int(step/2) num_array=[] bucket=[[],[],[],[],[],[],[],[],[],[]] x=raw_input("Enter how many no.u wanna to insert" ) obj=sorting(num_array) obj.accept() num=obj.digit(int(x)) obj.radix_sort(num,int(x)) obj.display() obj.qsort(0,int(x)-1)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question