#include "stdio.h"
#include "string.h"
void bubble_sort(char **pStrings);
int main(void) {
char strings[5][8] = {"ebadf", "qwerty", "assign", "execvp", "ghoul"};
char *pStrings[5];
for (int i = 0; i < 5; ++i) {
pStrings[i] = strings[i];
}
bubble_sort(pStrings);
for (int j = 0; j < 5; ++j) {
puts(*(pStrings + j));
}
}
void bubble_sort(char **pStrings) {
char *temp;
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4 - i - 1; ++j) {
if (strcmp(pStrings[j], pStrings[j + 1]) > 0) {
temp = pStrings[j];
pStrings[j] = pStrings[j + 1];
pStrings[j + 1] = temp;
}
}
}
}
按字典序对字符串进行冒泡排序(C语言)
最新推荐文章于 2024-03-27 21:26:00 发布