Professional Documents
Culture Documents
Queuing Insertion
Queuing Insertion
ALGORITHM
GROUP 6
QUEUING INSERTION ALGORITHM
• Queue is an abstract data structure or
linear data structure which is open at
both ends. One end is used for the
insertion of data (This is called
Enqueue which is our major topic of
discussion) and the other end is used
to remove data (dequeue).
Queue follows a first-in-first-out
methodology also known as FIFO
where the data item stored first will
be accessed first.
-1 A
0 1 2 3 4
REA
R
FRONT
0 1 2 3 4
FRONT
REA
R
A 3 5 7 8 9
0 1 2 3 4
REA
R
IMPLEMENTATION OF THE ALGORITHM USING C++
#include<iostream>
using namespace std;
#define size 5 f(1) = 1
int main(){
Int queue[size]; f(1) = 1
Int front = -1; f(1 ) = 1
Int rear = -1; f(1) = 1
Int value;
f(1) = 1
while (rear < size – 1) f(n ) = n
{
cout<<“Insert Value in the queue\n”; f(1*n) = n
cin>>value; f(1*n) = n
if(front==-1) f(1*n) = n
front = 0; f(1*n) = n
rear++; f(1*n) = n
queue[rear]=value; f(1*n) = n
}
if (rear==size-1) f(1) = 1
cout<<“Queue is full\n”;
return 0 ; f(1*1) = 1
f(1) = 1
}
COMPLEXITY ANALYSIS
f(n) = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + n + n + n + n + n + n + n
= 8 + 7n
= 7n
Big O = O(n)
APPLICATION OF QUEUE IN COMPUTER
SCIENCE