Page 191 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 191

Fundamentals of Data Structures




                    Notes                break;
                                         case 3:
                                         display();
                                         break;
                                         case 4:
                                         exit(1);
                                         default:
                                         printf(“Wrong choice\n”);
                                       }
                                     }
                                   }
                                   enqueue()
                                   {
                                     int item;
                                     if (rear==MAX-1)          /* QUEUE FULL condition */
                                       printf(“Queue Overflow, Cannot insert more elements\n”);
                                     else
                                     {
                                       if (front==-1)         /*If queue is initially empty */
                                       front=0;
                                       printf(“Enter the data element that is to be inserted in queue: “);
                                       scanf(“%d”, &item);
                                       rear=rear+1;                   /* incrementing rear for holding the
                                   index of added ele*/
                                       queue[rear] = item ;
                                     }
                                   }
                                   dequeue()
                                   {
                                     if (front == -1 || front -> rear) /* queue empty condition */
                                     {
                                       printf(“Queue Underflow\n”);
                                       return ;
                                     }
                                     else
                                     {
                                       printf(“Element deleted from queue is : %d\n”, queue[front]);
                                       front++;
                                     }
                                   }
                                   display()
                                   {




          184                               LOVELY PROFESSIONAL UNIVERSITY
   186   187   188   189   190   191   192   193   194   195   196