1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#include <iostream>
#include <cstring>
void sort(const char** beg, const char** end) {
for (const char **i = beg; i != end; ++i) {
const char *t = *i, **j = i;
for (const char **k = i - 1; j != beg && std::strcmp(t, *k) < 0; --j, --k)
*j = *k;
*j = t;
}
}
int main() {
const char *words[] = {
"one", "two", "three", "four", "five",
"six", "seven", "eight", "nine", "ten"
};
int size = sizeof words / sizeof words[0];
sort(words, words + size);
for (int i = 0; i < size; ++i)
std::cout << words[i] << '\n';
}
|