/* Stacks with Arrays Lab
   Version 1:  Stack contains pointers to strings
   Version 2:  Stack contains arrays of real strings
   Version 3:  Stack contains pointers to strings
                  allocating space for strings as needed
   Version 4:  Stack contains arrays of real strings
                  copying strings in, returning a reference
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "stack.h" 

int
main (void) {
  /* identify stack variables */
  struct string_stack * pBillStack = initialize();
  struct string_stack * pMagStack = initialize();
  struct string_stack * pNotesStack = initialize();

  if (pBillStack == NULL || pMagStack == NULL || pNotesStack == NULL)
    return EXIT_FAILURE;
  
  printf ("Program to test stack operations\n");

  /* experiment with stacks */
  printf ("\npushing 3 items on billStack\n");
  push (pBillStack, "mortgage");
  push (pBillStack, "doctor's bill");
  push (pBillStack, "credit card");

  /* check status of stacks */
  printf ("billStack is %sempty\n",  isEmpty (pBillStack)  ? "" : "NOT ");
  printf ("magStack is %sempty\n",   isEmpty (pMagStack)   ? "" : "NOT ");
  printf ("notesStack is %sempty\n", isEmpty (pNotesStack) ? "" : "NOT ");

  printf ("size of billStack:  %lu\n", size(pBillStack));
  printf ("size of magStack:   %lu\n", size(pMagStack));
  printf ("size of notesStack: %lu\n", size (pNotesStack));

  printf ("\nbill stack:  ");
  print (pBillStack);

  printf ("mag stack:  ");
  print (pMagStack);

  printf ("notes stack:  ");
  print (pNotesStack);

  /* more experimentation with stacks */
  printf ("\npushing 2 items on magStack\n");
  push (pMagStack, "Communications of the ACM - March 2009");
  push (pMagStack, "CS Education Bulletin - Spring 2009");

  /* checking nth positions in stacks */
  printf ("\nfirst item from top in billStack:  %s\n", get (pBillStack, 1));
  printf ("second item from top in magStack:  %s\n", get (pMagStack, 2));
  printf ("third item from top in billStack:  %s\n\n", get (pBillStack, 3));

  /* checking pop operation on several stacks */
  printf ("item popped from bill stack:  %s (new size is %lu)\n",
          pop (pBillStack),
          size (pBillStack) ); 
  printf ("item popped from bill stack:  %s (new size is %lu)\n",
          pop (pBillStack),
          size (pBillStack) ); 
  printf ("item popped from bill stack:  %s (new size is %lu)\n",
          pop (pBillStack),
          size (pBillStack) ); 
  
  printf ("item popped from mag stack:  %s (new size is %lu)\n",
          pop (pMagStack),
          size (pMagStack) ); 
  printf ("item popped from mag stack:  %s (new size is %lu)\n",
          pop (pMagStack),
          size (pMagStack) ); 
  
  /* check status of stacks */
  printf ("billStack is %sempty\n",  isEmpty (pBillStack)  ? "" : "NOT ");
  printf ("magStack is %sempty\n",   isEmpty (pMagStack)   ? "" : "NOT ");
  printf ("notesStack is %sempty\n", isEmpty (pNotesStack) ? "" : "NOT ");

  printf ("size of billStack:  %lu\n", size (pBillStack));
  printf ("size of magStack:   %lu\n", size (pMagStack));
  printf ("size of notesStack: %lu\n", size (pNotesStack));

  free(pBillStack);
  free(pMagStack);
  free(pNotesStack);
  
  return EXIT_SUCCESS;
}
