Page 148 - DCAP407_DATA_STRUCTURE
P. 148

Unit 8:  Queues



                                    if(Q_F(*COUNT))
                                    {
                                        printf("Queue overflow");
                                        return;
                                    }
                                    *R=(*R+1) % SIZE;
                                    Q[*R]=num;
                                    *COUNT+=1;
                               }
                               void front_delete(int Q[], int *F, int *COUNT)
                               {
                                    if(Q_E(*COUNT))
                                    {
                                        printf("Queue underflow");
                                        return;
                                     }
                                    printf("The deleted element is %d\n", Q[*F]);
                                    *F=(*F+1) % SIZE;
                                    *COUNT-=1;
                               }

                               void display(int Q[], int F, int COUNT)
                               {
                                    int i,j;
                                    if(Q_E(COUNT))
                                    {
                                        printf("Queue is empty\n");
                                        return;
                                    }
                                    printf("The contents of the queue are:\n");
                                     i=F;
                                     for(j=1;j<=COUNT; j++)
                                    {
                                        printf("%d\n", Q[i]);
                                        i=(i+1) % SIZE;
                                    }
                                    printf("\n");
                               }
                               void main()
                               {
                                    int choice, num, COUNT, F, R, Q[20];
                                    clrscr();
                                    F=0;
                                    R=-1;
                                    COUNT=0;
                                    for(;;)
                                    {
                                       printf("1. iInsert at front\n");
                                       printf("2. Delete at rear end\n");
                                       printf("3. Display\n");
                                       printf("4. Exit\n");
                                       scanf("%d", &choice);

                                       switch(choice)
                                       {
                                          case 1: printf("Enter the number to be inserted\n");
                                      scanf("%d", &num);




                                        LOVELY PROFESSIONAL UNIVERSITY                          141
   143   144   145   146   147   148   149   150   151   152   153