/**
Program Name: SIMPLE QUEUE
Description: This program is for Implementing Simple QUEUE
Author: Tauqirul Haque
*/
#define SIZE 3
int front = -1;
int rear = -1;
int queue[SIZE];
void deleteElement();
void insertElement();
void displayElement();
void main()
{
int ch;
while(ch !=4)
{
printf("\n\t\t1. Insert into queue..\n");
printf("\t\t2. Delete From Queue...\n");
printf("\t\t3. Diplay Queue...\n");
printf("\t\t4. Exit Program ...\n");
printf("Enter Your Choice # ");
scanf("%d",&ch);
switch(ch)
{
case 1:
insertElement();
break;
case 2:
deleteElement();
break;
case 3:
displayElement();
break;
case 4:
exit(0);
}
}
}
void insertElement()
{
int item;
printf("Enter The Item You want to Insert : ");
scanf("%d",&item);
if(rear == SIZE -1)
{
printf("\n Queue OVERFLOW ... \n\n");
return ;
}
rear++;
queue[rear] = item;
if(front == -1)
{
front++;
}
}
void deleteElement()
{
if(front == -1)
{
printf("\n\nQueue Empty... UNDERFLOW\n\n");
return;
}
printf("\n The Element to be Deleted is : %d ",queue[front]);
if(front == rear)
{
front = rear = -1;
}
else
{
front++;
}
}
void displayElement()
{
int i;
if(front == -1)
{
printf("\n QUEUE is EMPTY .. no item to display...\n");
return;
}
else
{
printf("\nTHE ELEMENTS ARE ... \n ");
for(i=front; i<=rear; i++)
{
printf("%5d",queue[i]);
}
}
printf("\n\n");
}
Program Name: SIMPLE QUEUE
Description: This program is for Implementing Simple QUEUE
Author: Tauqirul Haque
*/
#define SIZE 3
int rear = -1;
int queue[SIZE];
void deleteElement();
void insertElement();
void displayElement();
void main()
{
int ch;
while(ch !=4)
{
printf("\n\t\t1. Insert into queue..\n");
printf("\t\t2. Delete From Queue...\n");
printf("\t\t3. Diplay Queue...\n");
printf("\t\t4. Exit Program ...\n");
printf("Enter Your Choice # ");
scanf("%d",&ch);
switch(ch)
{
case 1:
insertElement();
break;
case 2:
deleteElement();
break;
case 3:
displayElement();
break;
case 4:
exit(0);
}
}
}
void insertElement()
{
int item;
printf("Enter The Item You want to Insert : ");
scanf("%d",&item);
if(rear == SIZE -1)
{
printf("\n Queue OVERFLOW ... \n\n");
return ;
}
rear++;
queue[rear] = item;
if(front == -1)
{
front++;
}
}
void deleteElement()
{
if(front == -1)
{
printf("\n\nQueue Empty... UNDERFLOW\n\n");
return;
}
printf("\n The Element to be Deleted is : %d ",queue[front]);
if(front == rear)
{
front = rear = -1;
}
else
{
front++;
}
}
void displayElement()
{
int i;
if(front == -1)
{
printf("\n QUEUE is EMPTY .. no item to display...\n");
return;
}
else
{
printf("\nTHE ELEMENTS ARE ... \n ");
for(i=front; i<=rear; i++)
{
printf("%5d",queue[i]);
}
}
printf("\n\n");
}
Comments