一个简单的字符串排序示例:
// StringSort.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string>
#include <stdio.h>
void sort_str(char *pt[],int num)
{
char *temp;
int top,seek;
//排序算法:选择排序,通过双循环实现
for(top=0;top<num;top++)
for(seek=top+1;seek<num;seek++)
{
if(strcmp(pt[top],pt[seek])>0)
{
temp=pt[top];
pt[top]=pt[seek];
pt[seek]=temp;
}
}
}
char* sz[] = {
"182118351822",
"182C1821182F1821182C",
"182618361824182E18331820",
"182D18211833183018201828",
"1820182D180E18201820",
"182F1833182018281830",
"1820182D1824182D180E18201833",
"1824182F182E180E18201821182D",
"182118341822",
"182A1821182818251837",
"1825000A1821182A18211833",
"1826182818321823182E1823",
"1824182F18241830",
"182D182118351826"
};
int main(int argc, char* argv[])
{
sort_str(sz, 14);
for(int i=0; i<14; i++)
{
printf("%s\r\n", sz[i]);
}
return 0;
}