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 Comment

Your email address will not be published. Required fields are marked *

Scroll to Top