Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Circular queues : Circular Queue Data Structure C Tutorial

http://www.java2s.com/Tutorial/C/0260__Data-Structure/Circularqueu...

14.4.1.Circular queues
#include <stdio.h> #include <stdlib.h> #define MAX 10 void insert(int queue[], int *rear, int front, int value) { *rear= (*rear +1) % MAX; if(*rear == front) { printf("The queue is full can not insert a value\n"); exit(0); } queue[*rear] = value; } 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) % MAX; *value = queue[*front]; } void main() { int queue[MAX]; int front,rear; int n,value; front=0; rear=0; insert(queue,&rear,front,1); insert(queue,&rear,front,2); insert(queue,&rear,front,3); insert(queue,&rear,front,4); delete(queue,&front,rear,&value); printf("The value deleted is %d\n",value); delete(queue,&front,rear,&value); printf("The value deleted is %d\n",value);

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

1 of 1

7/1/2011 7:40 PM

You might also like