Queues are frequently used in computer programming, and a typical example is the creation
of a job queue by an operating system. If the operating system does not use priorities, then
the jobs are processed in the order they enter the system. Write C++ program for simulating
job queue. Write functions to add job and delete job from queue.
#include<iostream>
#include<string>
using namespace std;
char que[10];
int size=10;
int front = -1, rear = -1;
int que_empty()
{
if(front == rear || front == rear == -1)
return 1;
else
return 0;
}
int que_full()
{
if(rear == size-1)
return 1;
else
return 0;
}
char del_que()
{
front ++;
return que[front];
}
void insert(char ch)
{
rear ++;
que[rear] = ch;
}
void display()
{
for(int i = front+1 ; i<=rear ; i++)
cout<<"|"<<que[i]<<"|";
}
int main()
{
char ch;
int cnt;
cout<<"Enter the No. of jobs ";
cin>>cnt;
for(int i=0; i<cnt; i++)
{
cout<<"\nEnter data for Job : ";
cin>>ch;
if(!que_full())
insert(ch);
else
{
cout<<" Queue Is Full !!! ";
break;
}
}
cout<<" Jobs In Queue are : ";
display();
while(!que_empty())
{
cout<<"\n\nProcessed job is : "<<del_que();
cout<<" \n In Process :";
display();
}
cout<<"\n\n";
return 0;
}
of a job queue by an operating system. If the operating system does not use priorities, then
the jobs are processed in the order they enter the system. Write C++ program for simulating
job queue. Write functions to add job and delete job from queue.
#include<iostream>
#include<string>
OUTPUT FOR THE PROGRAM |
char que[10];
int size=10;
int front = -1, rear = -1;
int que_empty()
{
if(front == rear || front == rear == -1)
return 1;
else
return 0;
}
int que_full()
{
if(rear == size-1)
return 1;
else
return 0;
}
char del_que()
{
front ++;
return que[front];
}
void insert(char ch)
{
rear ++;
que[rear] = ch;
}
void display()
{
for(int i = front+1 ; i<=rear ; i++)
cout<<"|"<<que[i]<<"|";
}
int main()
{
char ch;
int cnt;
cout<<"Enter the No. of jobs ";
cin>>cnt;
for(int i=0; i<cnt; i++)
{
cout<<"\nEnter data for Job : ";
cin>>ch;
if(!que_full())
insert(ch);
else
{
cout<<" Queue Is Full !!! ";
break;
}
}
cout<<" Jobs In Queue are : ";
display();
while(!que_empty())
{
cout<<"\n\nProcessed job is : "<<del_que();
cout<<" \n In Process :";
display();
}
cout<<"\n\n";
return 0;
}
For more such posts click the link:-http://svencrai.com/G8W
Tags
CODING