#include<bits/stdc++.h>

using namespace std;

struct QNode {
int data;
QNode* next;
QNode(int d)
{
data = d;
next = NULL;
}
};

struct Queue {
QNode *front, *rear;
Queue()
{
front = rear = NULL;
}

void enQueue(int x)
{

    QNode* temp = new QNode(x);

    if (rear == NULL) {
        front = rear = temp;
        return;
    }

    rear->next = temp;
    rear = temp;
}

void deQueue()
{

    if (front == NULL)
        return;

    QNode* temp = front;
    front = front->next;

    if (front == NULL)
        rear = NULL;

    delete (temp);
}

};

int main()
{

Queue q;
q.enQueue(15);
q.enQueue(20);
q.enQueue(25);
q.enQueue(30);
q.enQueue(35);
q.deQueue();
cout << "Queue Front : " << (q.front)->data << endl;

}

By RRR

One thought on “Write a C++ program to create a queue using linked list implementation with values 15 20 25 30 35.Also write a function to print the first element in the queue.”

Leave a Reply

Your email address will not be published.