Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- void swap(char *string) {
- for (int i = 0; string[i]; i++) {
- char c = string[i];
- if (islower(c)) string[i] = toupper(c);
- else if (isupper(c)) string[i] = tolower(c);
- }
- }
- void sort(char *string, int left, int right) {
- if (left >= right) return;
- int i = left, j = right;
- char tmp, pivot = string[rand() % (j - i) + i];
- while (1) {
- while (string[i] < pivot)
- i++;
- while (string[j] > pivot)
- j--;
- if (i >= j) break;
- tmp = string[i];
- string[i] = string[j];
- string[j] = tmp;
- i++;
- j--;
- }
- sort(string, left, i - 1);
- sort(string, j + 1, right);
- }
- int main(void) {
- char string[] = "cbaZYXcbaZYX";
- printf("Original: %s\n", string);
- swap(string);
- printf("Swap: %s\n", string);
- sort(string, 0, strlen(string) - 1);
- printf("Sort: %s\n", string);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement