Queue
Most interesting code for Queue and implementation of Queue in Operating System
Queue are used in C++ Language. It is designed for FIFO(First input, First Output) process. It specify how process in execute firstly. Queue can be two type En Queue and De Queue. En Queue is adding of information and De Queue is removing of information. Queue are mostly used in Operating system where process are executed on the bases of some certain algorithms. Queue is mostly concern with adding of element into memory. Queue are accessed from memory through FIFO. It work in stack of memory. Stack is temporary memory in operating system. In which it contain several attributes of process that is running.
#include
<iostream.h>
#include <conio.h>
#include <stdlib.h>
class Queue
{
private:
int q[10];
int rear;
int front;
public:
Queue()
{
rear=front=-1;
}
void Enqueue(int x)
{
if(rear==10)
{
cout<<"Stack is
full "<<endl;
front=rear=-1;
}
else
q[++rear]=x;
cout<<"Element
is inserted "<<x<<endl;
}
void Dequeue(int x)
{
if(front==rear)
{
cout<<"Stack is
empty "<<endl;
}
else
q[front++]=x;
cout<<"Element
is removed "<<x<<endl;
}
void display()
{
for(int i=0; i<=10;
i++)
{
cout<<"Element
are "<<q[i];
}
}
};
void main()
{
int ch;
Queue obj;
while(1)
{
cout<<"1. Enter
1 for insert element \n2. Enter 2 for Delete element \n3. Enter 2 for Display
element \n4. Exit"<<endl;
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter
data"<<endl;
cin>>ch;
obj.Enqueue(ch);
break;
case 2:
obj.Dequeue(ch);
break;
case 3:
obj.display();
break;
case 4:
exit(0);
break;
}
}
getch();
}Output Result
Queue in C++ |
Post a Comment