SHARE
TWEET

Untitled

a guest Sep 19th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top