桶排序&类 代码示范

桶排序

#include<iostream>
using namespace std;
int main(){
	int value;
	int a,max=100000;
	int list[max]={0};
	cin>>a;
	for(int i=0;i<a;i++){
		cin>>value;
		list[value]++;
	}
	for(int i=0;i<max;i++){
		for(int j=0;j<list[i];j++){
			cout<<i<<" ";
		}
	}
}

桶排序&类

#include <iostream>
#include "Tong.h"
using namespace std;
int main(){
	int a;
	cin>>a;
	tong t1;
	t1.get(a);
}
#include <iostream>
using namespace std;
class tong{
    private:
        int value;
        int max=100000;
        int list[100000]={0};
    public:
        void get(int m){
            for(int i=0;i<m;i++){
                cin>>value;
                list[value]++;
            }
            for(int i=0;i<max;i++){
                for(int j=0;j<list[i];j++){
                    cout<<i<<" ";
                }
            }
        }
};

 

posted @ 2024-01-28 11:15  王ys  阅读(10)  评论(0编辑  收藏  举报