简单的用数组实现的基数排序

#include<stdio.h>
#include<stdlib.h>
struct tong{
	int cunchu[10];
	int youbiao;
};
void jisuh(int *head,int max){
	int i=0,k,j,zhong,jian,b10=1,m;
	struct tong shuzu[10];

	for(m=0;m<3;m++){//3趟排序
	    j=0;b10*=10;
	    	for(i=0;i<10;i++)
	             {
	             	shuzu[i].youbiao=0;
				 }//初始化
        for(j=0;j<max;j++)//每趟的处理 ,放进去
          {
          	zhong=(head[j]%b10-head[j]%(b10/10) )/(b10/10);
          	shuzu[zhong].cunchu[shuzu[zhong].youbiao]=head[j];
          	shuzu[zhong].youbiao++;

		  }
		  k=0;
	   for(i=0;i<10;i++)
	      {
	      	for(j=0;j<shuzu[i].youbiao;j++)
	      	{
	      		head[k]=shuzu[i].cunchu[j];
	      		k++;
			  }
		  }

}}
int main(void){
	int a[]={9,2,43,245,134,344,32};
	jisuh(a,7);
	int i;
	for(i=0;i<7;i++)
	 {
	 	printf("%d ",a[i]);
	 }
}
时间: 2024-08-02 07:26:40

简单的用数组实现的基数排序的相关文章

使用队列对数组排列,基数排序

使用队列对数组排列,基数排序 /* * 使用队列对数组排列,基数排序 *对于0~99的数字,基数排序将数组集扫描两次. * 第一次按个位上的数字进行排序, * 第二次按十位上的数字进行排序 * */ function Queue(){ this.dataStore = [];//存放队列的数组,初始化为空 this.enqueue = enqueue;//向队列尾部添加一个元素 this.dequeue = dequeue;//删除队首的元素 this.theFront = theFront;/

一个简单的json数组解析(阿里巴巴)

最近工作中遇到了json字符串解析的问题,但是项目中是有限制的,只能引用阿里巴巴和simple jar,所以我选择了Alibaba的jar,由于很长时间没用过json的东西了,有些淡忘,不免工作中遇到了会花费些许时间再去重拾记忆,所以写了一个简单的JSON 字符串数组的解析实例,仅此作为笔记,以后遇到了可以直接看一下,或许可以节省一时片刻的时间,时间就是金钱,就是生命,就是自信,就是信任... /** * */package com.test.pac1; import java.util.Arr

简单谈谈JS数组中的indexOf方法

前言 相信说到 indexOf 大家并不陌生,判断字符串是否包涵子字符串时特别常用,正则不熟练同学的利器.这篇文章就最近遇到的一个问题,用实例再说说说indexOf方法.本文是小知识点积累,不作为深入讨论的话题,因此这里没有解释indexOf()的第二个参数,相信大家都知道第二个参数的作用. String 类型的使用 温习一下大家熟知的字符串用法,举个 ? 1 2 3 4 5 let str = 'orange'; str.indexOf('o'); //0 str.indexOf('n');

简单的对数组内字符串排序方法

//  NSArray * sortedArray = [cache sortedArrayUsingSelector:@selector(compare:)]; { NSArray * arr1 = @[@"A",@"B",@"C",@"D"]; NSArray * arr2 = @[@"1",@"2",@"3"]; NSArray * arr3 = @[@&quo

POJ 2481 Cows 简单树状数组区间覆盖

点击打开链接 Cows Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 13334   Accepted: 4413 Description Farmer John's cows have discovered that the clover growing along the ridge of the hill (which we can think of as a one-dimensional number line

嵌套的for循环执行顺序。可以让内外for循环交替执行。简单解析json数组。求js中两个时间差值。

1.刚接到不久的工作任务,其中包含一个解析json数组,然后让解析后的数据显示在用zrender画出来的矩形上.效果如下所示(注:没有实际意义) 2.至于zrender等空闲了一定写上使用心得,东西很强大. 3.中间有一项是算计相邻的两个时间的时间差(所有这些时间都是在一个数组里),如图所示,算计相邻两个矩形上时间的差值.延伸一下可以是算一个数组里相邻两个数字的差值. 贴上我的代码 :  for (var m = 0; m < dataObj.length - 1; m++) {        

封装一个简单的动态数组

package com.immoc; import java.util.ArrayList; import java.util.List; /** * 实现动态数组 * */ public class Array <E> { private E[]data;; private int size; public Array(int capacity){ data = (E[]) new Object[capacity]; size = 0; } public Array(){ this(10);

bzoj 1270: [BeijingWc2008]雷涛的小猫 简单dp+滚动数组

1270: [BeijingWc2008]雷涛的小猫 Time Limit: 50 Sec  Memory Limit: 162 MB[Submit][Status][Discuss] Description   Input Output Sample Input Sample Output 8 HINT 思路:保存i+z的max值:上一行的dp值: #include<bits/stdc++.h> using namespace std; #define ll __int64 #define

tcl之变量-unset 简单变量和数组