Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. typedef enum {
  2. red, white, blue
  3. } color;
  4.  
  5. void swap(color *a, color *b) {
  6. int t;
  7. t = *a;
  8. *a = *b;
  9. *b = t;
  10. }
  11.  
  12. void flag(color a[], int n) {
  13. int i = 0, j = 0, k = n - 1;
  14. while (j <= k) {
  15. switch (a[j]) {
  16. case red:
  17. swap(&a[i++], &a[j++]);
  18. break;
  19. case white:
  20. j++;
  21. break;
  22. case blue:
  23. swap(&a[j], &a[k--]);
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement