-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrees.c
More file actions
107 lines (85 loc) · 1.8 KB
/
trees.c
File metadata and controls
107 lines (85 loc) · 1.8 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <stdio.h>
#include <stdlib.h>
struct node{
int data;
struct node *right;
struct node *left;
};
typedef struct node *BTREE;
BTREE new_node (int data){
BTREE p;
p = (BTREE)malloc(sizeof(struct node));
p->data = data;
p->left = NULL;
p->right = NULL;
return p;
}
void inorder(BTREE root){
if(root!=NULL){
inorder(root->left);
printf("%d \t", root->data);
inorder(root->right);
}
}
BTREE insert(BTREE root, int data){
if(root!= NULL){
if(data < root->data)
root->left = insert(root->left,data);
else
root->right = insert(root->right,data);
}
else
root = new_node(data);
return root;
}
int size(BTREE root){
if(root==NULL)
return 0;
else
return 1+size(root->left) + size(root->right);
}
int leaves(BTREE root){
if(root == NULL)
return 0;
else if(root->left == NULL && root->right == NULL){
return 1;
}
else
return leaves(root->left) + leaves(root->right);
}
int min_ite(BTREE root){
if(root!= NULL){
while(root->left != NULL)
root = root->left;
return root->data;
}
}
// iki çocuðu varsa yer deðiþtirecek.
BTREE mirror(BTREE root){
if (root== NULL)
return;
else
{
BTREE temp;
mirror(root->left);
mirror(root->right);
temp= root->left;
root->left = root->right;
root->right = temp;
}
}
main(){
BTREE myroot = NULL;
int i;
scanf("%d", &i);
while(i!= -1){
myroot = insert(myroot,i);
scanf("%d", &i); }
inorder(myroot);
printf("\n");
printf("Your min_ite %d\n",min_ite(myroot));
printf("Your leaves %d\n",leaves(myroot));
printf("Your size %d\n",size(myroot));
mirror(myroot);
inorder(myroot);
}