0% found this document useful (0 votes)
44 views5 pages

8.queue: Ques) Write A Programme To Insert and Delete Data From A Queue. Ans)

This program implements a queue using a linked list data structure. It defines functions to insert nodes into the queue using push(), delete nodes from the queue using pop(), and display the contents of the queue. The main function allows the user to repeatedly insert nodes, display the queue, and optionally delete nodes from the front of the queue.

Uploaded by

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

8.queue: Ques) Write A Programme To Insert and Delete Data From A Queue. Ans)

This program implements a queue using a linked list data structure. It defines functions to insert nodes into the queue using push(), delete nodes from the queue using pop(), and display the contents of the queue. The main function allows the user to repeatedly insert nodes, display the queue, and optionally delete nodes from the front of the queue.

Uploaded by

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

8.

QUEUE
Ques ) write a programme to insert and delete data from a
queue.

Ans)
#include<iostream.h>

#include<conio.h>

#include<stdlib.h>

#include<process.h>

struct node

int info;

node*next;

}*front ,*ptr,*rear;

node*create(int n)

ptr=new node;

ptr->info=n;

ptr->next=NULL;

return ptr;
}

void push(node*m)

if (front==NULL)

front=rear=m;

else

rear->next=m;

rear=m;

void pop()

ptr=front;

front=front->next;

delete ptr;

void display(node*front)

while(front!=NULL)
{

cout<<front->info;

front=front->next;

cout<<"\n";

void main()

clrscr();

front=rear=NULL;

int info;

char ch='y';

while(ch=='y'||ch=='Y')

cout<<"\n enter new node";

cin>>info;

ptr=create(info);

push(ptr);

cout<<"\n";

display(front);
cout<<"\n";

cout<<"dou want 2 add more";

cin>>ch;

cout<<"\nod u wnat 2 delete";

cin>>ch;

if(ch=='y')

cout<<"\n";

display(rear);

cout<<"\n";

getch();

You might also like