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

按关键字升序排序—C++

/*
功能:02按关键字升序排序.cpp
作者:wind
日期:2014-01-11
*/

#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 1000;
typedef int KeyType;
typedef struct
{
	KeyType key;
	char data;
}RedType;
typedef struct
{
	RedType r[1001];
	int length;
}SqList;
//在L.r[i,L.length]中选择key最小的记录
int SelectMinKey(SqList *L,int i)
{
	int j=i;
	for(;i<L->length;i++)
	{
		if (L->r[i].key<L->r[i+1].key)
		{
			j = i;
		}
	}
	return j;
}
//按关键字升序排序
void SelectSort(SqList *L)
{

   int i=0,j=0;
   char tmp = L->r[1].data;
   for (i = 1;i<L->length;i++)
   {
	   j = SelectMinKey(L,i);
	   if (i != j )
	   {
		   tmp = L->r[i].data;
		   L->r[i].data = L->r[j].data;
           L->r[j].data = L->r[i].data;
	   }
   }
}
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

预览
Loading comments...
0 条评论

暂无数据

example
预览