0% found this document useful (0 votes)
6 views4 pages

9.queue implementation using linked list

Uploaded by

asodariadhruv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

9.queue implementation using linked list

Uploaded by

asodariadhruv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

25 August 2024 20:41

if(front==NULL)
{
front=newnode;
rear=front; //rear=newnode
}

New Section 1 Page 1


#include <cstdlib>
#include <iostream>
# include<stdlib.h>
using namespace std;
struct queue
{
int data;
struct queue* next;
}*front,*rear,*newnode,*temp;

void enqueue(int input)


{
newnode=(struct queue*)malloc(sizeof(struct
queue));
newnode->data=input;
newnode->next=NULL;
if(front==NULL)
{
front=newnode;
rear=front; //rear=newnode
}
else
{
rear->next=newnode;
rear=rear->next;
}
}

void display()
{
if(front==NULL)
cout<<"Queue underflow"<<endl;
else
{
New Section 1 Page 2
{
cout<<"Queue elements are"<<endl;
for(temp=front;temp!=rear->next;temp=temp->
next)
{
cout<<temp->data<<endl;
}
}
}
void dequeue()
{
if(front==NULL)
cout<<"Queue underflow"<<endl;
else if(front->next==NULL)
{
cout<<"Dequeued element is"<<front->
data<<endl;
delete front;
front=NULL;
}
else
{
temp=front;
cout<<"Dequeued element is"<<front->
data<<endl;
front=front->next;
delete temp;
}
}
int main()
{
enqueue(5);
display();
enqueue(10);
display();
dequeue();
display();
dequeue();
display();
}

New Section 1 Page 3


New Section 1 Page 4

You might also like