Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions C++/queue.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include<stdio.h>

int queue[100];
int front = -1;
int rear = -1;

void insert()
{
int item;
if(rear == 100-1)
{
printf("Overflow!\n");
}
else
{
if(front == -1)
{
front = 0;
}
printf("Insert the element in the queue : ");
scanf("%d", &item);
rear = rear+1;
queue[rear] = item;
}
}

void delete()
{
if(front == -1 || front > rear)
{
printf("Queue is empty\n");
}
else
{
printf("DELETED!\n");
front = front + 1;
}
}

void display()
{
if(front == -1)
{
printf("Queue is empty\n");
}
else
{
for(int i = front; i <=rear; i++)
{
printf("%d\t", queue[i]);
}
}
printf("\n");
}


int main()
{
int choice;
do
{
printf("1.Insert \n");
printf("2.Delete \n");
printf("3.Display \n");
printf("4.Quit \n");
scanf("%d", &choice);

switch (choice)
{
case 1:
insert();
break;
case 2:
delete();
break;
case 3:
display();
break;
case 4:

default:
printf("Wrong choice \n");

}
}while(choice != 4);
}