Page 630 - Computer science 868 Class 12
P. 630

Program 22     Circular Queue
                               Define a class circularQ  having
                               Class Name                   :   circularQ
                               Data Members
                               int q[]                      :   to store element in circular queue array
                               int n, front, rear           :   denote the maximum size front, rear respectively
                               Member Function
                               circularQ(int nn)            :   to initialise the size front and rear to zero and definrarra
                               void add(int v)              :   to add number in the circular queue from the rear end
                               int del()                    :   to delete number from the circular queue from end
                               void display()               :   to display the number in circular queue
                               Also write the main method to implement circular queue.


                 1       import java.util.*;
                 2       class circularQ

                 3       {
                 4       int q[];

                 5       int n,front,rear;
                 6       circularQ(int nn)

                 7       {
                 8       n = nn;

                 9       q = new int[n];
                10       front = 0;

                11       rear = 0;
                12       }

                13       void add(int v)
                14       {

                15       if((rear+1)%n!= front)
                16       {

                17       rear =(rear+1)%n;
                18       q[rear]=v;

                19       }
                20       else
                21       System.out.println("Circular queue fall");

                22       }

                23       int del()
                24       {





                628628  Touchpad Computer Science-XII
   625   626   627   628   629   630   631   632   633   634   635