计数排序
Description
实现计数排序,通过多次遍历数组,统计比每一个元素小的其它元素个数,根据该统计量对数据进行排序。
Input
输入的每一行表示一个元素为正整数的数组,所有值用空格隔开,第一个值为数值长度,其余为数组元素值。
Output
输出的每一行为排序结果,用空格隔开,末尾不要空格。
Sample Input 1
13 24 3 56 34 3 78 12 29 49 84 51 9 100
Sample Output 1
3 3 9 12 24 29 34 49 51 56 78 84 100
class courtSort:
def courtSort1(self,arr):
length = len(arr)
B=[1]*length
#C=[1]*length
for i in range(0,length):
cout=0;
for j in range(0,length):
if(int(arr[j])<int(arr[i])):
cout+=1;
B[i]=cout
for h in range(0,length):
for m in range(h, length):
if(B[h]>B[m]):
temp1=B[m]
B[m]=B[h]
B[h]=temp1
temp2=arr[m]
arr[m]=arr[h]
arr[h]=temp2
return arr
if '_main_':
try:
while True:
d=courtSort()
A=[]
D=[]
a=input()
s=a.split(' ')
A.extend(s)
A.remove(A[0])
D=d.courtSort1(A)
for j in range(len(D) - 1):
print(D[j], end=' ')
print(D[len(D) - 1])
except EOFError:
exit()