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

字符序列排序—C++

/*
功能:01字符序列排序.cpp
作者:wind
日期:2014-01-11
*/

#include<stdio.h>
#include<stdlib.h>
/************************************************************************
函数名:void InsertSort (char *L)
功能:排序
参数:char *L   字符序列首地址
返回值:空
时间复杂度为O(n):n^2
************************************************************************/
void InsertSort (char *L)
{
	int i,j;
	char tmp=L[0];

	for(i=0;L[i];i++)
	{
		for (j=i+1;L[j];j++)
		{
              if (L[i]>L[j])
              {
				  tmp = L[i];
				  L[i] = L[j];
				  L[j] = tmp;
              }
		}
	}

}
int main(void)
{

	char L[10]={"abaabcccb"};
    printf("%sn",L);
	InsertSort(L);
	printf("%sn",L);
	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

预览
Loading comments...
0 条评论

暂无数据

example
预览