指针的指针字符串排序

来源:互联网 发布:mac原唱变伴奏 编辑:程序博客网 时间:2024/05/18 09:36
<span style="font-size:18px;">#include<iostream>using namespace std;void sort(char* strings[], int n){char* temp;for (int i = 0; i < n; i++){for (int j = i + 1; j < n; j++){if (strcmp(strings[i], strings[j]) > 0){temp = strings[i];strings[i] = strings[j];strings[j] = temp;}}}}int main(){int n = 5;int i;char**p;char*strings[] = { "snkn", "kndg", "ljil", "nbdkj", "mklal" };p = strings;sort(p, n);for (int i = 0; i < n; i++){cout << strings[i] << endl;}system("pause");return 0;}</span>

0 0