-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperations.h
64 lines (54 loc) Β· 1.23 KB
/
operations.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
#include <stdlib.h>
// Node structure for Binary Tree
struct Node {
struct Node *lChild;
int data;
struct Node *rChild;
};
// Creation of a Node
struct Node* createNode(int data){
struct Node *temp = (struct Node*)malloc(sizeof(struct Node));
temp->data = data;
temp->lChild = NULL;
temp->rChild = NULL;
return temp;
}
struct Queue{
int size;
int front;
int rear;
struct Node **Q; // bcoz it stores address of the tree node
};
void createQ(struct Queue *q , int size){
q->size = size;
q->front = q->rear = 0;
q->Q = (struct Node **)malloc(q->size * sizeof(struct Node *));
}
void enqueue(struct Queue *q , struct Node* data){
if(q->rear == q->size-1){
printf("Queue is full.");
}else{
q->rear++;
q->Q[q->rear] = data;
}
}
struct Node * dequeue(struct Queue *q){
struct Node * x = NULL;
if(q->front == q->rear){
printf("Queue is empty.");
}else{
q->front++;
x = q->Q[q->front];
}
return x;
}
int isEmpty(struct Queue *q){
return (q->front == q->rear) ? 1 : 0;
}
int count(struct Node *p){
if(p){
return count(p->lChild) + count(p->rChild) + 1;
}
return 0;
}