0% found this document useful (0 votes)
4 views

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)
4 views

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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy