Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- void swap_list(char **list1, char *list2, int i, int j) {
- char *t1;
- char t2;
- t1 = list1[i];
- t2 = list2[i];
- list1[i] = list1[j];
- list2[i] = list2[j];
- list1[j] = t1;
- list2[j] = t2;
- }
- void quick_sort(char **list1, char *list2, int left, int right)
- {
- int i, j;
- char *t, *middle;
- if (left >= right) return;
- middle = list1[(left + right) / 2];
- for (i = left, j = right;; i++, j--) {
- while (strcmp(list1[i], middle) < 0)
- i++;
- while (strcmp(list1[j], middle) > 0)
- j--;
- if (i >= j) break;
- swap_list(list1, list2, i, j);
- }
- quick_sort(list1, list2, left, i - 1);
- quick_sort(list1, list2, j + 1, right);
- }
- int main(void) {
- char *list1[] = {
- "Tottori", "Kochi", "Nara", "Wakayama", "Kagawa", "Shimane", "Okinawa",
- "Shiga", "Fukui", "Tokushima", "Nagasaki", "Saga", "Yamanashi", "Ehime",
- "Yamaguchi", "Mie", "Oita", "Iwate", "Miyazaki", "Ishikawa", "Toyama",
- "Akita", "Gifu", "Kyoto", "Okayama", "Aomori", "Kumamoto", "Kagoshima",
- "Gunma", "Hyogo", "Fukushima", "Miyagi", "Yamagata", "Nagano", "Hiroshima",
- "Ibaraki", "Tochigi", "Niigata", "Shizuoka", "Osaka", "Saitama", "Aichi",
- "Chiba", "Kanagawa", "Fukuoka", "Hokkaido", "Tokyo"
- };
- char list2[] = "iinauaawrs3aaodr keomaepk s ndoinmdoo diAkaeeh";
- int size = sizeof(list2) / sizeof(char);
- int i;
- quick_sort(list1, list2, 0, size - 1);
- for (i = 0; i < size; i++) {
- printf("%s\n", list1[i]);
- }
- printf("%s\n", list2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement