Intel Interview Question
Software Engineer / DevelopersTeam: Firmware
Country: United States
Interview Type: In-Person
void enqueue(void)
{
int x;
if((front==0&&rear==max-1)||(front==rear+1)) //condition for full Queue
{
printf("Queue is overflow\n"); return;
}
if(front==-1)
{
front=rear=0;
}
else
{
if(rear==max-1)
{
rear=0;
}
else
{
rear++;
}
}
printf("enter the data:\n");
scanf("%d",&x);
q[rear]=x;
printf("%d succ. inserted\n",x);
return;
}
void dequeue(void)
{
int y;
if(front==-1)
{
printf("Queue is underflow\n"); return;
}
y=q[front];
if(front==rear)
{
front=rear=-1;
}
else
{
if(front==max-1)
{
front=0;
}
else
{
front++;
}
}
printf("%d succ. deleted\n",y);
return;
}
you forgot to bumped the top while insertion
- Anonymous October 11, 2012