#define size 50 /* number of elements in an array */

#include <stdio.h>

/* This file provides a shell for processing
   the Dutch National Flag Problem, as described at
   http://www.walker.cs.grinnell.edu/courses/161.sp10/labs/lab-loop-inv-pic.shtml#Flag
*/

typedef enum { red, white, blue} color;

void printArray (color arr[]);

int main (void) {
  /* declaration of a colors array with initialization */
  color colors [size] = {blue, red, white, red, white, 
                         blue, blue, white, white, red,
                         red, red, white, red, blue,
 
                         white, white, white, blue, blue,
                         red, red, red, blue, white,
                         red, blue, white, white, blue,
                         red, blue, blue, white, red,

                         white, blue, white, red, red,
                         blue, red, white, blue, red,
                         white, red, blue, white, blue};

  
  printf ("the initial array is:\n");
  printArray (colors);

  /* processing goes here */


  /* printing the resulting array */

  printf ("the final array is array is:\n");
  printArray (colors);

  return 0;
}


void printArray (color arr[])
/* printing the color array, 10 colors to a row */
{ int i;
  for (i = 0; i < size; i++) 
    {
      switch(arr[i]) 
        {
        case red:
          printf ("red   ");
          break;
        case white:
          printf ("white ");
          break;
        case blue:
          printf ("blue  ");
          break;
        default:
          printf ("error ");
        }
      /* move to new line every 10th item */
      if (i % 10 == 0)
        printf ("\n");
    }
  printf ("\narray printed\n");
}
