Hello again guys,
I got here a Stack and Queue Array program. My problem is deleting an item in Queue. Here's a quick video of my problem:
http://www.youtube.com/watch?v=X_G82aU_LV4
Here's my code:
#include <stdio.h>
#include <conio.h>
int main()
{
int a[100],n=0,i;
int cho,choi,choice;
clrscr();
do
{
printf("\n\n\n [1] Stack\n");
printf(" [2] Queue\n");
printf(" [3] Exit\n");
printf("\n Enter your choice: ");
scanf("%d", &cho);
switch (cho)
{
case 1:
{
do
{
printf("\n\n\n [1] Push items\n");
printf(" [2] Pop items\n");
printf(" [3] Display items\n");
printf(" [4] Exit\n");
printf("\n Enter your choice: ");
scanf("%d", &choi);
switch (choi)
{
case 1:
{
clrscr();
printf("\n\n Enter integer for total numbers to be sorted: ");
scanf("%d", &n);
printf("\n\n");
for (i = 0; i < n; i++)
{
printf(" Enter integer for no. %d : ", i + 1);
scanf("%d", &a[i]);
}
break;
}
case 2:
{
clrscr();
if (n == 0)
{
printf("\n The stack is empty.");
}
else
{
n = n - 1;
printf("\n The poped element is %d.", a[n]);
}
break;
}
case 3:
{
clrscr();
if (n == 0)
{
printf("\n The stack is empty.");
}
else
{
printf("\n The stack contains: ");
for (i = 0; i < n; printf("%3d", a[i]), i++);
}
break;
}
case 4:
{
break;
}
default:
{
printf("\n\n Please enter the right choice.");
break;
}
}
}while (choi != 4);
return 0;
}
case 2:
{
int rear=-1,n=-1;
do
{
printf("\n\n\n [1] Queue items\n");
printf(" [2] Deque items\n");
printf(" [3] Display items\n");
printf(" [4] Exit\n");
printf("\n Enter your choice: ");
scanf("%d", &choice);
switch (choice)
{
case 1:
{
clrscr();
printf("\n\n Enter integer for total numbers to be sorted: ");
scanf("%d", &n);
printf("\n\n");
for (i = 0; i < n; i++)
{
printf(" Enter integer for no. %d : ", i + 1);
scanf("%d", &a[i]);
}
break;
}
case 2:
{
clrscr();
if (n == -1)
{
printf("\n The stack is empty.");
}
else
{
printf("\n The poped element is %d.", a[n]);
if(n == rear)
{
n = rear=-1;
}
else
{
n++;
}
}
break;
}
case 3:
{
clrscr();
if (n == -1)
{
printf("\n The stack is empty.");
}
else
{
printf("\n The stack contains: ");
for (i = 0; i < n; printf("%3d", a[i]), i++);
}
break;
}
case 4:
{
break;
}
default:
{
printf("\n\n Please enter the right choice.");
break;
}
}
}while (choice != 4);
return 0;
}
}
}while (cho != 3);
}