Tuesday, 13 May 2014

Array Implementation of a int Queue

Created By: Hanan Mannan
Contact Number: Pak (+92)-321-59-95-634
==================================
Array Implementation of a int Queue
===============================
#include 
#include
// j a v a2 s . c om
#define MAX 10

void insert(int queue[], int *rear, int value)
{
if(*rear < MAX-1)
{
*rear= *rear +1;
queue[*rear] = value;
}
else
{
printf("The queue is full can not insert a value\n");
exit(0);
}
}

void delete(int queue[], int *front, int rear, int * value)
{
if(*front == rear)
{
printf("The queue is empty can not delete a value\n");
exit(0);
}
*front = *front + 1;
*value = queue[*front];
}

void main()
{
int queue[MAX];
int front,rear;
int n,value;
front = rear = -1;

insert(queue,&rear,1);
insert(queue,&rear,2);

delete(queue,&front,rear,&value);
printf("The value deleted is %d\n",value);
}

0 comments:

Post a Comment