/* This program uses code from "Algorithms in C, Third Edition,"
 *               by Robert Sedgewick, Addison-Wesley, 1998.
 */

#include <stdio.h>
#include <stdlib.h>

#include "graphs.h"

main()
{ 
   graph g = NULL;
   
   while(1)
   {
      printf("\n");
      printf("MENU:\n");
      printf("0: Create new graph.\n");
      printf("1: Add an edge.\n");
      printf("2: Remove an edge.\n");
      printf("3: Print neighbors of an edge.\n");
      printf("4: Print graph.\n");
      printf("5: Exit");
      
      int command = -1;
      while(1)
      {
         printf("\n");
         printf("Enter command (0-5): ");
         scanf("%d", &command);
         if ((command >= 0) || (command <= 5))
         {
            break;
         }
      }
              
      if (command == 0)
      {
         int number = 0;
         while(number <= 0)
         {
            printf("Enter number of vertices: ");
            scanf("%d", &number);
         }
         
         destroyGraph(g);
         g = newGraph(number);
      }
              
      else if (command == 1)
      {
         int v1, v2;
         printf("Enter vertices: ");
         scanf("%d %d", &v1, &v2);
         addEdge(g, v1, v2);
      }
      
      else if (command == 2)
      {
         int v1, v2;
         printf("Enter vertices: ");
         scanf("%d %d", &v1, &v2);
         removeEdge(g, v1, v2);
      }

      else if (command == 3)
      {
         int v1;
         printf("Enter vertex: ");
         scanf("%d", &v1);
         printNeighbors(g, v1);
      }

      else if (command == 4)
      {
         printGraph(g);
      }
      
      else if (command == 5)
      {
         destroyGraph(g);
         return 0;
      }
   }
}
