Example #1
0
int main()
{
  int choice;

  while(1)
  {
    printf("\nChoose an option \n1. Add Element \n2. Delete Element \n3. View Queue \n4. Exit \n");

    printf("Enter your choice: ");
    scanf("%d", &choice); // get choice from user

    if(choice==1)
    {
      addQueue(); // if choice 1 then call addQueue function
    }
    else if(choice==2)
    {
      deleteQueue(); // if choice 2 then call deleteQueue function
    }
    else if(choice==3)
    {
      viewQueue(); // if choice 3 then call viewQueue function
    }
    else if(choice==4)
    {
      return 0; // if choice 4 then exit
    }
    else
    {
      printf("\nEnter valid choice \n"); // invalid choice
    }
  }
}
Example #2
0
int main()
{
    int choice,cap,data;
    printf("1. create Queue(a queue is required before any other operation to be done on the queue\n");
    printf("2. insert an element in the queue Queue\n");
    printf("3. delete an element from the Queue\n");
    printf("4. delete the whole Queue\n");
    printf("5. view Queue\n");
    printf("6. exit\n");
    while(1)
    {
        printf("\nEnter your choice : ");
        fflush(stdin);
        scanf("%d",&choice);
        switch(choice)
        {
            case 1:
                printf("\nEnter the capacity of the Queue : ");
                scanf("%d",&cap);
                if(createQueue(cap)!=NULL)
                     printf("\nQueue has been created successfully");
                break;
            case 2:
                printf("\nEnter the data to be inserted : ");
                scanf("%d",&data);
                enQueue(createQueue(cap),data);
                break;
            case 3:
                deQueue(createQueue(cap));
                break;
            case 4:
                deleteQueue(createQueue(cap));
                break;
            case 5:
                viewQueue(createQueue(cap));
                break;
            case 6:
                exit(0);
            default:
                printf("\nInvalid choice");
        }
    }
    return 0;
}