@@ -5,10 +5,10 @@ using namespace std;
55class Queue
66{
77private:
8- int front;
9- int rear;
10- int size;
11- int * Q;
8+ int front; // front is used for deletion
9+ int rear; // rear is used for insertion
10+ int size; // size of the queue
11+ int * Q; // dynamically allocated space for queue
1212public:
1313 Queue () // Non-parameterized constructor //front and rear are assigned as -1 //indicates Queue is empty
1414 {
@@ -22,33 +22,33 @@ class Queue
2222 this ->size = size;
2323 Q = new int [this ->size ];
2424 }
25- void enqueue (int x);
26- int dequeue ();
27- void display ();
25+ void enqueue (int x); // declaration for insertion element in the queue
26+ int dequeue (); // declaration for deletion of the element queue
27+ void display (); // declaration for displaying the queue
2828};
2929
30- void Queue::enqueue (int x)
30+ void Queue::enqueue (int x) // passing the value as parameter for insertion
3131{
32- if (rear == size - 1 )
32+ if (rear == size - 1 ) // condition for checking queuefull
3333 cout << " Queue is Full" << endl;
3434 else
3535 {
36- rear++;
37- Q[rear] = x;
36+ rear++; // increament the rear and then insert the value in the queue
37+ Q[rear] = x; // insertion of the element.
3838 }
3939}
4040
4141int Queue::dequeue ()
4242{
43- int x = -1 ;
44- if (front == rear)
43+ int x = -1 ; // initially set the value of the x to -1; setting
44+ if (front == rear) // condition for cheking the queue empty
4545 cout << " Queue is Empty" << endl;
4646 else
4747 {
48- front++;
48+ front++; // increment the front and take out the element
4949 x = Q[front];
5050 }
51- return x;
51+ return x; // return the deleted value
5252}
5353
5454void Queue::display ()
@@ -61,16 +61,16 @@ void Queue::display()
6161
6262int main ()
6363{
64- Queue q (5 );
64+ Queue q (5 ); // Creating an instance for class and setting the size as 5
6565
66- q.enqueue (10 );
66+ q.enqueue (10 ); // inserting the value in queue
6767 q.enqueue (20 );
6868 q.enqueue (30 );
6969 q.enqueue (40 );
7070
71- q.display ();
72- q.dequeue ();
73- q.display ();
71+ q.display (); // displaying queue
72+ q.dequeue (); // deleting the value from the queue.
73+ q.display (); // then displaying it after deletion
7474
7575 return 0 ;
76- }
76+ }
0 commit comments