Skip to content

Instantly share code, notes, and snippets.

@Embedded-linux
Last active December 22, 2015 21:39
Show Gist options
  • Select an option

  • Save Embedded-linux/6535216 to your computer and use it in GitHub Desktop.

Select an option

Save Embedded-linux/6535216 to your computer and use it in GitHub Desktop.
Queue Program Using Array in C
This Program is for queue implementation using arrays in C.
#include <stdio.h>
#define N 6
int queue[N] = {0};
int rear = 0,front = 0;
void insert(void);
void delete(void);
void display(void);
void create(void);
void main()
{
int user =0;
while(user!=4)
{
printf("Size of queue is:%d",N);
printf("\n 1.Insert");
printf("\n 2.delete");
printf("n 3.Display");
printf("\n 4.Exit");
printf("\n 5.Create");
scanf("%d",&user);
switch(user)
{
case 1:
insert();
break;
case 2:
delete();
break;
case 3:
display();
break;
case 4:
printf("Thank you\n");
break;
case 5:
create();
break;
}
}
}
void insert(void)
{
int t;
if (rear<N)
{
printf("Enter a value in queue\n");
scanf("%d",&t);
queue[rear] = t;
rear++;
}
else
{
printf("queue overflow\n");
}
}
void delete()
{
int i;
printf("deleted element: %d\n",queue[front]);
queue[front]=0;
front++;
}
void display(void)
{
int i;
for (i=front;i<rear;i++)
{
printf("display elements:%d",queue[i]);
}
}
void create()
{
int t;
printf("Enter a value to enter into queue\n");
scanf("%d\n",&t);
front = 0;
queue[front] = t;
rear = front+1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment