计数排序

计数排序

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()

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值