Page 139 - DCAP407_DATA_STRUCTURE
P. 139

Data Structure



                                          {
                                          int added_item;
                                          if (rear==MAX-1)
                                          printf("Queue overflow\n");

                                          else
                                          {
                                          if (front==-1)              /*If queue is initially empty */
                                          front=0;
                                          printf("Enter an element to add in the queue : ");
                                          scanf("%d", &added_item);
                                          rear=rear+1;
                                          queue_arr[rear] = added_item ;

                                          }
                                                   }                             /*End of insert()*/
                                          void ins_delete()
                                          {
                                          if (front == -1 || front > rear)
                                          {

                                          printf("Queue underflow\n");
                                          return ;
                                          }
                                          else
                                          {
                                          printf("Element deleted from queue is : %d\n", queue_arr[front]);
                                          front=front+1;

                                          }
                                          }             /*End of delete() */
                                          void display()
                                          {
                                          int i;
                                          if (front == -1)

                                          printf("Queue is empty\n");
                                          else
                                          {
                                          printf("Elements in the queue:\n");
                                          for(i=front;i<= rear;i++)
                                          printf("%d ",queue_arr[i]);





                          132                     LOVELY PROFESSIONAL UNIVERSITY
   134   135   136   137   138   139   140   141   142   143   144