/*-----------------------------------------------------------------*/
int main(void)
{
    char command;
    struct list_node_s* head_p1 = NULL;
    struct list_node_s* head_p2 = NULL;
    struct list_node_s* head_p3 = NULL;
    /* start with empty list */
    
    command = Get_command();
    while (command != 'q' && command != 'Q') {
        
        head_p1 = Build(head_p1);
        head_p2 = Build(head_p2);
        
        switch (command) {
            case 'u':
            case 'U':
                head_p3 = Union(head_p1, head_p2);
                printf("The union between the two sets is: ");
                Print(head_p3);
                break;
                
            case 'i':
            case 'I':
                head_p3 = Intersect(head_p1, head_p2);
                printf("The intersection of the two sets is: ");
                Print(head_p3);
                break;
                
            case 'd':
            case 'D':
                head_p3 = Difference(head_p1, head_p2);
                printf("The difference between the two sets is: ");
                Print(head_p3);
                break;
                
            default:
                printf("There is no %c command\n", command);
                printf("Please try again\n");
        }
        
        head_p1 = Free_list(head_p1);
        head_p2 = Free_list(head_p2);
        head_p3 = Free_list(head_p3);
        
        command = Get_command();
    }
    
    return 0;
} /* main */
Exemplo n.º 2
0
/*-----------------------------------------------------------------*/
int main(void) {
   char command;
   int  value;
   struct list_node_s* head_p = NULL;  
      /* start with empty list */

   command = Get_command();
   while (command != 'q' && command != 'Q') {
      switch (command) {
         case 'i': 
         case 'I': 
            value = Get_value();
            head_p = Insert(head_p, value);
            break;
         case 'p':
         case 'P':
            Print(head_p);
            break;
         case 'm': 
         case 'M':
            value = Get_value();
            if (Member(head_p, value))
               printf("%d is in the list\n", value);
            else
               printf("%d is not in the list\n", value);
            break;
         case 'd':
         case 'D':
            value = Get_value();
            head_p = Delete(head_p, value);
            break;
         case 'f':
         case 'F':
            head_p = Free_list(head_p);
            break;
         default:
            printf("There is no %c command\n", command);
            printf("Please try again\n");
      }
      command = Get_command();
   }

   head_p = Free_list(head_p);

   return 0;
}  /* main */
Exemplo n.º 3
0
/*-----------------------------------------------------------------*/
int main(void) {
   char command;
   int  value;
   struct list_node_s* head_p = NULL;  
      /* start with empty list */

   command = Get_command();
   while (command != 'q' && command != 'Q') {
      switch (command) {
         case 'i': 
         case 'I': 
            value = Get_value();
            Insert(head_p, value);
            break;
         case 'p':
         case 'P':
            Print(head_p);
            break;
         case 'm': 
         case 'M':
            value = Get_value();
            printf("Member not implemented\n");
            break;
         case 'd':
         case 'D':
            value = Get_value();
            printf("Delete not implemented\n");
            break;
         case 'f':
         case 'F':
            printf("Free list not implemented\n");
            break;
         default:
            printf("There is no %c command\n", command);
            printf("Please try again\n");
      }
      command = Get_command();
   }

   // Free_list

   return 0;
}  /* main */
Exemplo n.º 4
0
/*-----------------------------------------------------------------*/
int main(void) {
   char command;
   int  value;
   struct list_node_s* head_p = NULL;  /* start with empty list */

   command = Get_command();
   while (command != 'q' && command != 'Q') {
      switch (command) {
         case 'i': 
         case 'I': 
            value = Get_value();
            Insert(value, &head_p);  /* Ignore return value */
            break;
         case 'p':
         case 'P':
            Print(head_p);
            break;
         case 'm': 
         case 'M':
            value = Get_value();
            Member(value, head_p);   /* Ignore return value */
            break;
         case 'd':
         case 'D':
            value = Get_value();
            Delete(value, &head_p);  /* Ignore return value */
            break;
         default:
            printf("There is no %c command\n", command);
            printf("Please try again\n");
      }
      command = Get_command();
   }
   Free_list(&head_p);

   return 0;
}  /* main */
Exemplo n.º 5
0
int main(void) {
   set_t  *A_p = NULL, *B_p = NULL, *C_p = NULL;
   char   command;

   command = Get_command();
   while (command != 'q' && command != 'Q') {
      A_p = Read_set("A");
      B_p = Read_set("B");
      switch (command) {
         case 'u':
         case 'U':
            C_p = Union(A_p, B_p);
            Print_set(C_p, "C");
            Free_all_sets(&A_p, &B_p, &C_p);
            break;
         case 'i':
         case 'I':
            C_p = Intersection(A_p, B_p);
            Print_set(C_p, "C");
            Free_all_sets(&A_p, &B_p, &C_p);
            break;
         case 'd':
         case 'D':
            C_p = Difference(A_p, B_p);
            Print_set(C_p, "C");
            Free_all_sets(&A_p, &B_p, &C_p);
            break;
         default:
            printf("There is no %c command\n", command);
            printf("Please try again\n");
      } /* switch */
      command = Get_command();
   }  /* while */

   return 0;
}  /* main */
Exemplo n.º 6
0
/* ========================================================================== */
int main(void)
{
# ifdef DEBUG
    printf("\n\t\t######################################");
    printf("\n\t\t#!!!   Debugger mode turned on.   !!!#");
    printf("\n\t\t#!!!   File: %s               !!!#", __FILE__);
    printf("\n\t\t#!!!   Line: %d.                  !!!#", __LINE__);
    printf("\n\t\t######################################\n\n");
# endif
    struct set_s* a_p = NULL;
    struct set_s* b_p = NULL;
    struct set_s* c_p = NULL;
    struct set_s* C = NULL;
    int asize, bsize, csize;
    asize = bsize = csize = 0;
    char command;
    command = Get_command();

    if(command != 'q' && command != 'Q')
    {
        a_p = Read_set(a_p, &asize, 1);
        b_p = Read_set(b_p, &bsize, 2);
        csize = asize + bsize;
    }

   while (command != 'q' && command != 'Q')
   {
       switch (command)
       {
           case 'u':
           case 'U':
                printf("\n\nFinding the union of the two sets. \n");
                c_p = Union(a_p, asize, b_p, bsize, c_p, csize, C);
                Print(a_p, 1);
                Print(b_p, 2);
                printf("Union: ");
                Print(c_p, 3);
                printf("\n");
                break;
           case 'i':
           case 'I':
               printf("\n\nFinding the intersection of the two sets. \n");
               c_p = Intersection(a_p, asize, b_p, bsize, c_p, csize, C);
               Print(a_p, 1);
               Print(b_p, 2);
               printf("Intersection: ");
               Print(c_p, 3);
               printf("\n");
               break;
           case 'd':
           case 'D':
               printf("\n\nFinding the difference of the two sets. \n");
               c_p = Difference(a_p, asize, b_p, bsize, c_p, csize, C);
               Print(a_p, 1);
               Print(b_p, 2);
               printf("Difference: ");
               Print(c_p, 3);
               printf("\n");
               break;
           case '\n':
               printf("\n$ ");
               break;
           default:
               printf("There is no %c command\n", command);
               printf("Please try aga_pn\n");
       }

       // free lists and reset list sizes.
        a_p = Free_list(a_p);
        b_p = Free_list(b_p);
        c_p = Free_list(c_p);
        C = Free_list(C);
        asize = bsize = csize = 0;

       // get command for operation to perform.
       command = Get_command();

       // read in new lists and update csize.
       if(command != 'q' && command != 'Q')
       {
           a_p = Read_set(a_p, &asize, 1);
           b_p = Read_set(b_p, &bsize, 2);
           csize = asize + bsize;
       }
   }

    return 0;
}  /* main */