FREE : [ Study Material ] NDA/SSB Preparation : Check Now!!! | Latest: HR Interview Questions:CHECK | Like Us :

Wednesday 24 April 2013

C program to implement a Queue Implementation using array | QUEUE USING ARRAY


//Program Coded by ASHISH

#include<stdio.h>
#include<conio.h>
#define MAX 50
int queue[MAX];
int FRONT=-1;
int REAR=-1;
void traverse();
void insert(int num);
void remov();
void main()
{
int ch,num,p;
clrscr();
do
{
printf("Press 1 to Print All elements of QUEUE\n");
printf("Press 2 to Insert Element in the Queue\n");
printf("Press 3 to Delete Element from the QUEUE\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
traverse();
break;
}
case 2:
{
printf("Enter the Element to be inserted in queue\n");
scanf("%d",&num);
insert(num);
break;
}
case 3:
{
printf("Deleting Element from Queue--FIFO---\n");
remov();
break;
}
}
printf("\nDo you wanna Perform again 1 for yes\n");
scanf("%d",&p);
}while(p==1);
getch();
}
void traverse()
{
int i;
if(FRONT==-1&&REAR==-1)
{printf("\nQueue is Empty");}
else
{
printf("Queue is:-\n");
for(i=FRONT;i<=REAR;i++)
{
printf("\n%d",queue[i]);
}
}

}
void insert(int num)
{
if(FRONT==-1&&REAR==-1)
{
FRONT=0;
REAR=0;
queue[FRONT]=num;
}
else
{
REAR=REAR+1;
queue[REAR]=num;
}
printf("Element Inserted\n");
}
void remov()
{
if(FRONT==-1&&REAR==-1)
{printf("Queue is Empty\n");}
else if(FRONT==REAR)
{
FRONT=-1;
REAR=-1;
printf("Queue is Empty NOW!!!\n");
}
else
{
FRONT=FRONT+1;
}
}

Please Submit your Responses

0 comments:

Post a Comment

Please add only useful comments.......

 

Results

get our extension

Like Us on FB

    Freshers Jobs

    Donate

    DMCA Protected

    You are Visitor Number

    Interview Questions

    SSB Questions

      Authors
    Tinku Singh
    Hitesh Dhanda

    MrNaukri.com - Get Sarkari Jobs, Results, Off Campus Placement Updates © 2012. All Rights Reserved | Back To Top |

    © 2013 A Product of IBC Network