Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef enum {
- red, white, blue
- } color;
- void swap(color *a, color *b) {
- int t;
- t = *a;
- *a = *b;
- *b = t;
- }
- void flag(color a[], int n) {
- int i = 0, j = 0, k = n - 1;
- while (j <= k) {
- switch (a[j]) {
- case red:
- swap(&a[i++], &a[j++]);
- break;
- case white:
- j++;
- break;
- case blue:
- swap(&a[j], &a[k--]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement