Page 179 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 179

Fundamentals of Data Structures




                    Notes          int dq[QUEUE_LENGTH];
                                   int front, rear, choice, x,y;
                                   main()
                                   {
                                    int choice,x;
                                    front = rear = -1; /* initialize the front and rear to null i.e. empty
                                   queue */
                                    printf (“enter 1 for addition and 2 to remove element from the front of
                                   the queue”);
                                    printf (“enter 3 for addition and 4 to remove element from the rear of
                                   the queue”);
                                    printf(“Enter your choice”);
                                    scanf(“%d”,&choice);
                                    switch (choice)
                                    {
                                    case 1:
                                    printf (“Enter element to be added :”);
                                    scanf(“%d”,&x);
                                    add_front(x);
                                    break;
                                    case 2:
                                    delete_front();
                                    break;
                                    case 3:
                                    printf (“Enter the element to be added :”);
                                    scanf(“%d”,&x);
                                    add_rear(x);
                                    break;
                                    case 4:
                                    delete_rear();
                                    break;
                                    }
                                   }
                                   /**************** Add at the front ***************/
                                   add_front(int y)
                                   {
                                   if (front == 0)
                                   {
                                    printf(“Element can not be added at the front”);
                                    return;
                                   else
                                    {
                                    front = front - 1;




          172                               LOVELY PROFESSIONAL UNIVERSITY
   174   175   176   177   178   179   180   181   182   183   184