-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path3_perimeter.c
52 lines (47 loc) · 828 Bytes
/
3_perimeter.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
#include <stdio.h>
typedef struct s_node {
int value;
struct s_node *right;
struct s_node *left;
} Node;
void a(Node *root)
{
if (root->left)
{
printf(" %d", root->value);
a(root->left);
}
}
void b(Node *root)
{
if (root->left)
b(root->left);
if (root->right)
b(root->right);
if (!root->left && !root->right)
printf(" %d", root->value);
}
void c(Node *root)
{
if (root->right)
{
c(root->right);
printf(" %d", root->value);
}
}
void perimeter(struct s_node *root)
{
if (root)
printf("%d", root->value);
if (root->left)
{
a(root->left);
b(root->left);
}
if (root->right)
{
b(root->right);
c(root->right);
}
printf("\n");
}