桶排序

主函数

#include <bits/stdc++.h>
#include "Sort.h"
using namespace std; 
int main(){
    int n;
    cin>>n;
    Sort.N = n;
    Sort.Cin();
    Sort.Cout();
    return 0;    
}

副函数

class a{
    private:
        int list[1000] = {0};
    public:
        int N;
        void Cin(){
            int x;
            for(int i = 0;i<N;i++){
                std::cin>>x;
                list[x]++;
            }    
        }
        void Cout(){
            for(int i = 0;i<1000;i++){
                if(list[i]!=0){
                    for(int j = 0;j<list[i];j++){
                        std::cout<<i<<" ";
                    }
                }
            }    
        }
}Sort;

 

posted @ 2024-01-28 11:18  王一行(小号)  阅读(4)  评论(0编辑  收藏  举报