Program On "Queue"
"Nice One Program"
"Nice One Program"
//DIVIDE always divide your work and proceed for that
if You divide Your code and then go for it that would be Easy Task it Just looks 50 60 Lines of Code But not A difficult Task For beginers.
if You divide Your code and then go for it that would be Easy Task it Just looks 50 60 Lines of Code But not A difficult Task For beginers.
Queue: Is the Abstract Data Structure.Like a Stack where insertion( Enqueue ) And Deletion( Dequeue ) . Works on FIFO that is First In First Out. Hence Insertion will at end And Deletion will be at the beginning.
Check Out Its Code. Do Write Queries in Comment.
//Header Files
//Code Executed In TurboC++
#include<iostream.h>
#include<conio.h>
#include<process.h>
#define size 50
int front=-1;
int rear=-1;
void enq(int *s)
{
int data;
if(rear==size-1)
cout<<"Error:Overflow";
else
{
cout<<"\nEnter data:";
cin>>data;
if(front==-1)
{
front=rear=0;
s[front]=data;
}
else
{
rear++;
s[rear]=data;
}
}
} //Insertion In Queue End
//Code For Deletion
void deq()
{
if(front==-1||front>rear)
cout<<"\n\nError:UnderFlow can't Perform Deletion:\n";
else
{
front=front+1;
}
} //Code For deletion End
//Main Method
void main()
{
clrscr();
int choice;
int queue[size];
//int queue=new queue[];
cout<<"Size of Queue Is Predefined:\n\n";
cout<<"\nEnter Choice:\n";
cout<<"Enqueue(1):";
cout<<"\nDequeue(2):";
cout<<"\nExit(3):";
cin>>choice;
while(choice!=3)
{
if(choice==1)
enq(queue);
else if(choice==2)
{
if(front==-1)
{
cout<<"UnderFlow:Erorr";
break;
}
cout<<"\nDeleting Element:"<<queue[front]<<endl;
deq();
}
else
break;
cout<<"\nEnter Choice:\n";
cout<<"Enqueue(1):";
cout<<"\nDequeue(2):";
cout<<"\nExit(3):";
cin>>choice;
}//While loop end
if(front!=-1)
for(int i=front;i<=rear;i++)
cout<<queue[i]<<" ";
getch();

No comments:
Post a Comment