#include<iostream>
using namespace std;
//指向指针的指针对五个字符串排序输出
void str_sort(char** p)
{
char* temp;
//冒泡法排序
for (int i = 0; i < 5; i++)
for (int j = 0; j < 4 - i; j++)
if (strcmp(*(p + j), *(p + j+1)) > 0)
{
temp = *(p + j);
*(p + j) = *(p + j + 1);
*(p + j + 1) = temp;
}
}
int main()
{
char* pstr[5], str[5][20];
for (int i = 0; i < 5; i++)
pstr[i] = str[i];
cout << "输入5个字符串 :" << endl;
for (int i = 0; i < 5; i++)
cin >> pstr[i];
char** p = pstr;
str_sort(p);
cout << "排序后 :" << endl;
for (int i = 0; i < 5; i++)
cout << pstr[i] << endl;
return 0;
}
谭浩强c++第三版6-19
最新推荐文章于 2024-09-09 12:31:15 发布