『代码』··By/蜜汁炒酸奶

计数排序—C++

/*
功能:03计数排序
作者:wind
日期:2014-01-11
*/

#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 10;
typedef int KeyType;
typedef struct
{
	KeyType key;
	char data;
}RedType;
typedef struct
{
	RedType r[11];
	int length;
}SqList;
void InsertSort (SqList *L,int n)
{
	int *c=new int[11];
    int i,j;
	RedType tmp = L->r[1];
	//计算c[i]
	for(i =1;i<L->length;i++)
	{
		for( j=2;j<L->length;j++)
		{
			if (L->r[i].key<L->r[j].key)
			{
				c[i]++;
			}
		}

	}
	//按C[i]排序
	for(i = L->length;i>1;i++)
	{
		for(int j=1;j<L->length;j++)
		{
			if (c[i]<c[j])
			{
				 tmp = L->r[j];
				  L->r[i] = L->r[j];
				  L->r[j] = tmp;
			}
		}
	}
	delete[] c;
}
int main(void)
{




	system("pause");
	return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

预览
Loading comments...
0 条评论

暂无数据

example
预览