-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queue.h
49 lines (48 loc) · 834 Bytes
/
Queue.h
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
#ifndef Queue_h
#define Queue_h
#include<stdlib.h>
#include<stdio.h>
struct Node{
struct Node *lchild;
int data;
struct Node *rchild;
};
struct queue{
int front;
int rear;
int size;
struct Node **Q;
};
void create(struct queue *q,int size)
{
q->size=size;
q->front=q->rear=-1;
q->Q=(struct Node**)malloc(q->size*sizeof(struct Node*));
}
void enqueue(struct queue *q,struct Node *x)
{
if((q->rear+1)%q->size==q->front)
printf("Queue is full");
else{
q->rear=(q->rear+1)%q->size;
q->Q[q->rear]=x;
}
}
struct Node* dequeue(struct queue *q)
{
struct Node *x=NULL;
if(q->front==q->rear)
printf("Queue is Empty");
else{
q->front=(q->front+1)%q->size;
x=q->Q[q->front];
}
return x;
}
int isEmpty(struct queue q)
{
if(q.front==q.rear)
return 1;
else return 0;
}
#endif