Queue representation using array program not working

#include
#define N 5
using namespace std;
int queue[N];
int i;
int front=-1;
int rear=-1;
void enqueue(int x)
{
if(rear=N-1)
{
cout<<“overflow”;
}
if(front==-1&&rear==-1)
{
front=rear=0;
queue[rear]=x;
}
else
{
rear++;
queue[rear]=x;
}
}
void display()
{
if(front==-1&&rear==-1)
{
cout<<“empty queue”;
}
else
{
for(i=front;i=rear+1;i++)
{
cout<<queue[i];
}
}
}
int main()
{
enqueue(2);
enqueue(5);
enqueue(7);
display();
}

Hi @supratik260699
2 changes you have to make in your code :

  1. in display function else case you have to run i from front to rear.
  2. inenqueue function if case there should be double == in its condition.

Here is your corrected code :

1 Like