首页 > 其他 > 详细

6-9 Sort Three Distinct Keys (20分)

时间:2020-04-21 16:08:24      阅读:125      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

 技术分享图片

 技术分享图片

 

 解题思路:注意时间复杂度要求是O(n)

void MySort( ElementType A[], int N ) {
    int i;
    ElementType b[3]= {0};
    for(i=0; i<N; i++) {
        b[A[i]]++;
    }
    i=0;
    while(b[1]--)
        A[i++]=1;
    while(b[2]--)
        A[i++]=2;
    while(b[0]--)
        A[i++]=0;
}

 

6-9 Sort Three Distinct Keys (20分)

原文:https://www.cnblogs.com/snzhong/p/12745180.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!