1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | /****** C Program For Impelmetation Of Circular Queue *******/
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define MAX 5
struct queue
{
int arr[MAX];
int rear,front;
};
int isempty(struct queue *p)
{
if(p->front ==p->rear)
return 1;
else
return 0;
}
void insertq(struct queue *p,int v)
{
int t;
t = (p->rear+1)%MAX;
if(t == p->front)
printf("\nQueue Overflow\n");
else
{
p->rear=t;
p->arr[p->rear]=v;
}
}
int removeq(struct queue *p)
{
if(isempty(p))
{
printf("\nQueue Underflow");
exit(0);
}
else
{
p->front=(p->front + 1)%MAX;
return(p->arr[p->front]);
}
}
void main()
{
struct queue q;
char ch;
int no;
q.rear=q.front =0;
insertq(&q,7);
insertq(&q,10);
insertq(&q,12);
insertq(&q,15);
insertq(&q,8);
printf("\n%d\n",removeq(&q));
printf("%d\n",removeq(&q));
printf("%d\n",removeq(&q));
printf("%d\n",removeq(&q));
removeq(&q);
system("cls");
getch();
}
|
This blog is about my daily programming technologies I explore and work on. It contains data from my University learning materials to my Profession as Software Engineer. Programming in Asp.net, Windows Forms, JavaScript, HTML, OpenGL, Assembly Language, Dynamics CRM 2011.
Feedjit
Articles for you
Tuesday, December 31, 2013
C++ Plus Plus Program of Circular Queue in C++ Object Oriented Programm OOP C++
C++ Plus Plus Program of Circular Queue in C++ Object Oriented Programm OOP C++
2013-12-31T01:48:00-08:00
Saqib Khan
C++|Computer Science|F09B|Islamic University|Programming|
Subscribe to:
Post Comments (Atom)