Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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