Page 557 - Computer science 868 Class 12
P. 557

17.  Convert the following infix expression to postfix form:                                  [ISC 2017]
                        P * Q/R + (S + T)
                   Ans.  P * Q/R + (S + T)
                        = PQ* / R  + (S + T)
                        = PQ*R / + (S + T)
                        = PQ*R/ (S+T) +
                        = PQ*R / ST ++
                   18.  A queue is an entity which can hold a maximum of 100 integers. The queue enables the user to add integers from the rear and
                       remove integers from the front.                                                            [ISC 2017]
                        Define a class Queue with the following details:
                        Class name                      :   Queue
                        Data Members/Instance variables
                        Que[]                           :   array to hold the integer elements
                        size                            :   stores the size of the array
                        front                           :   to point the index of the front
                        rear                            :   to point the index of the rear
                        Member Functions
                        Queue(int mm)                   :   constructor to initialize the data
                                                           size = mm, front = 0, rear = 0
                        void addele(int v)              :   to add integer from the rear if possible else display the message “Overflow”
                        int delele()                    :   returns  elements  from  front  if  present,  otherwise  displays  the  message
                                                           “Underflow” and return-9999
                        void display()                  :   displays the array elements
                        Specify the class Queue giving details of ONLY the functions void addele(int) and int delete()
                        Assume that the other functions have been defined.
                        The main function and algorithm need NOT be written.
                   Ans.  public class Queue {
                         int Quen = new int[100];
                         int max, f, r;
                         public class Queue {
                         int Quen = new int[100];
                         int max, f, r;
                         void addele(int v) if (r < max - 1)
                           Que[+ - Fr]
                           = v;
                         else System.out.println("Overflow");
                       }
                       int delete()
                       if (f != r)
                           return Que[++f];
                       else
                           return -9999;
                       }













                                                                                                                       555
                                                                                                       Data Structures  555
   552   553   554   555   556   557   558   559   560   561   562