/* ++[ Machine Problem #3 ]++++++++++++++++++++++++++++++++++++++
   +								+
   + Zaczek, Mariusz						+
   + CS 223 - Monday 11:00am - 1:00 pm				+
   + 3/9/98							+
   + 								+
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */

/* ++[  main  ]++++++++++++++++++++++++++++++++++++++++++++++++++
   + Function: main()                                           +
   +                                                            +
   +   Takes: no values						+
   +                                                            +
   +   Returns: no values					+
   +                                                            +
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */

/* Include declarations */
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "sarr.h" 

/* Beginning of main body of code */
int main()
{
  /* Initialize counter, temporary string and array. */
  int counter=0;
  char string[300];
  StringArray my_array;

  /* Loop while a string is entered and until a zero is entered. */
  while((cin >> string) && (strcmp(string,"0") != 0))
  {
    /* Check if string entered is longer than 100 characters. If
       it is then output error and quit program. */
    if (strlen(string) >= 100)
    {
    cout << "\nERROR: String length exceeds maximum "
         << "number of characters: 100\n" << endl;
    return 0;
    }
    /* If string length is 1 then check to see if it is a command
       input ( i.e. a 1, 2, 3 or 4 ), and act accordingly. */
    if (strlen(string) == 1)
    {
      switch(atoi(string)) 
      {
        case 1:
           my_array.print();
  	   break;
        case 2:
           my_array.sortAscending();
	   break;
        case 3:
           my_array.sortDescending();
	   break;
        case 4:
           my_array.clearArray();
           break;
        default:
           my_array.insert(string);
      }
    }
    else
      my_array.insert(string);
  }
return 0;
}



