Saturday, June 19, 2021
Home coding Write a program to implement queue using array.

Write a program to implement queue using array.

Given a array ,we have to implement queue using array.

Queue has two operation:

1-enqueue operation.(push the element)

2-dequeue operation.(pop the element)

Logic:

STEP 1:implement push operation.
STEP 2:implement pop operation.

Code

void enqueue(int data)
{
    
if (rear==SIZE && front==0)
cout<<"full"<<endl;
else
{
q[rear]=data;
}
rear++;
}
void dequeue()
{
if (front==rear)
cout<<"empty";
else
{
int popped=q[front];
front++;
cout<<popped<<"deleted"<<endl;
}
}

Ouput:

pushed
popped

Time Complexity:O(N)

Space Complexity:O(1)

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

Recent Comments