急啊!!!请求C++来解答:

来源:百度知道 编辑:UC知道 时间:2024/05/27 07:32:40
赵庆、李芳、张峰、王刚、黄欣、周鹏、孙欣、李苑、钟铭、朱峰
用排序的算法对上面的姓名进行排序,按照拼音首字母的顺序排。
(要求用顺序表实现)

#include<iostream>
using namespace std;

#define OK 1

void swap(char *p1,char *p2)
{
char p[20];
strcpy(p,p1);
strcpy(p1,p2);
strcpy(p2,p);
}

int main()
{
int i,j;
char str[10][20]={{"赵庆"},{"李芳"},{"张峰"},{"王刚"},{"黄欣"},{"周鹏"},{"孙欣"},{"李苑"},{"钟铭"},{"朱峰"} };
cout<<"排序前:"<<endl;
for(i=0; i<10; i++)
{
puts(str[i]);
}
for(i=0; i<10-1; i++)
for(j=i+1;j<10;j++)
if(strcmp(str[i],str[j])>0)
swap(str[i],str[j]);
cout<<"排序后:"<<endl;

for(i=0; i<10; i++)
{
puts(str[i]);
}
return OK;
}

//c++ STL实现
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace