-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree_assignment.c
76 lines (73 loc) · 1.84 KB
/
tree_assignment.c
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
66
67
68
69
70
71
72
73
74
75
76
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct node{
int data;
struct node*left;
struct node*right;
}node;
node* create() {
node *p;
char c;
printf("if you want to add node type 'y' otherwise 'n' \n ");
scanf(" %c", &c);
if (c == 'n')
return NULL;
p = (node *) malloc(sizeof(node));
scanf(" %d", &p->data);
p->left = create();
p->right = create();
return p;
}
int instructions() {
int n;
printf("1->pre order traversal\n 2->In order traversal\n 3->post order traversal\n");
scanf("%d", &n);
return n;
}
void pre_order(node*root) {
if (root == NULL) {
return;
}
printf("%c ", root->data);
pre_order(root->left);
pre_order(root->right);
return;
}
int isFull(node* root) {
if (root == NULL) return 1;
if (root->left == NULL && root->right == NULL)return 1;
if ((root->left) && (root->right))return ((isFull(root->left) && isFull(root->right)));
return 0;
}
int valCheck(node *root) {
int ldat = 0, rdat = 0;
if (root == NULL || (root->left == NULL && root->right == NULL))return 1;
else {
if (root->left != NULL) {
ldat = root->left->data;
}
if (root->right != NULL) {
rdat = root->right->data;
}
if (root->data == ldat + rdat && valCheck(root->left) && valCheck(root->right))return 1;
else return 0;
}
}
int isSkew(node *root){
if(root==NULL||(root->left==NULL&&root->right==NULL))return 1;
if(root->left&&root->right)return 0;
if(root->left)return isSkew(root->left);
return isSkew(root->right);
}
typedef struct queue{
struct node *front;
struct node *rear;
}queue;
int main() {
node *root = NULL;
queue *front=NULL,*rear=NULL;
root=create();
if(valCheck(root))printf("true");
else printf("false");
}