Implementation of Queue using Array and its brief explanation

By | July 15, 2015

Implementation of Queue using Array

Learn the way of “Implementation of Queue using Array“. Queue is the liner NP Ds. here NP stands for non_primitive Ds.Queue is an abstract data type as Stack. It means that it is the imaginary data type.

Queue is follow the rule of FIFO. FIFO stands for first in first out .

Its just like as row of any thing , it means that which thing that is entered first is element first.

Its just like a straight pipe that have hole on both side. For Example.

Implementation of Queue using Array in stack.




 

Implementation of Queue using Array

Implementation of Queue using Array

The Front SIDE are is to delete the data form the Queue and Rare SIDE is us to enter the data in the Queue.when Queue is empty then Front and Rare is equal to ‘-1’.

Queue_2[howpk.com]

Queue_2[howpk.com]

Implementation:-

The implementation of the Queue is using Array are as follows…:

Note:-

The simple Queue is not use in the daily life because its waste many space in memory that’s why we use circular Queue and also implemented the circle Queue not the simple Queue.

Program for Implementation of Queue using Array.

#include<iostream>
using namespace std;
class Queue
{
private:
int arr[5],f,r;
public:
Queue()
{
f=-1;
r=-1;
}
int insert()
{
if((r==4&&f==0)||f==r+1)
{
cout<<“the Queue is full”<<endl;
}
else
{
cout<<“Enter the number”;
if(f==-1)
{
f=0;
r=0;
cin>>arr[f];
}
else if(r==4)
{
r=0;
cin>>arr[r];
}
else
{
r++;
cin>>arr[r];
}
}
}
int delet()
{
if(f==-1)
{
cout<<“Queue is Empty”<<endl;
}
else
{
if(f==r)
{
f=-1;
r=-1;
}
else if(f==4)
{
f=0;
}
else
{
f++;
}
}
}
int show()
{
int t=f;
if(t>=0)
{
while(t!=r)
{
cout<<t<<“\t”<<arr[t]<<endl;
if(t==4)
{
t=0;
}
else
{
t++;
}
}
cout<<r<<“\t”<<arr[r]<<endl;
}
else
{
cout<<“Queue is NULL”<<endl;
}
}
};
int main()
{
Queue a;
char n;
do
{
cout<<“press ‘i’ for insert,’d’ for delet and ‘e’ for end of program”<<endl;
cout<<“\tEnter ‘s’ if want to show the Queue “;
cin>>n;
if(n==’i’)
{
a.insert();
}
else if(n==’d’)
{
a.delet();
}
else if(n==’s’)
{
a.show();
}
}while(n!=’e’);
}

also use Implementation of Queue using Array in queue.

Implementation of Queue using Array in Trees.

Implementation of Queue using Array in Heaps.

Author: Awais Shafique

Hello My name is Awias.I am Student of BSCS in GCUF. I am the Senior Contributor of this website.