基数排序(有空再补)(咕咕咕)

本文深入解析基数排序算法,通过实例展示其排序过程,从最低位到最高位逐步进行模拟排序,适用于大数据集的高效排序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//基数排序
//从最低位开始排序,依次向最高位模拟。
//		第一次 
//	0		1		2		3		4		5		6		7		8		9
//	0 	    1	   512	   343	   64	   125	   216	   27		8	   729
//
//
//		第二次 
//	0		1		2		3		4		5		6		7		8		9
//	0 	   512	   125	    	   343	    	   64	   
//	1 	   216	    27	    	    	    	    	   
//	8 	     	   729	    	    	    	    	   	   
//
//
//		第三次 
//	0		1		2		3		4		5		6		7		8		9
//	0 	   125	   216	   343	    	   512	    	   729
//	1 	    	    	    	    	    	    	   
//	8 	     	   	    	    	    	    	   	   
// 27	       	    	    	    	   
// 64	   	    	    	    	    	   
//
#include<iostream>
using namespace std;
struct list{
	int element;
	struct list *next;
};
int main(){
	struct list *header[10];
	for(int i=0; i<10; ++i){
		header[i] = (list*)malloc(sizeof(list));
		header[i]->next = NULL;
	}
	int n;	cin >> n;
	int a[n],maxn = -1;
	for(int i=0; i<n; ++i){
		int t,k = 0;	cin >> t;
		a[i] = t;
		while(t){
			k++;
			t/=10;
		}
		if(k>maxn){
			maxn = k;
		}
	}
	for(int i=0; i<n; ++i){
		int t = a[i];
		t%=10;	
		list *temp = (list*)malloc(sizeof(list));
		temp->element = a[i];
		temp->next = NULL;
		list *tt = header[i];
		while(tt->next!=NULL){
			tt = tt->next;
		}
		tt->next = temp;
	}
	for(int i=1; i<maxn; ++i){
		for(int j=0; j<10; ++j){
			list *t = header[j];
			
		}
	}
	return 0;
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值