-
Notifications
You must be signed in to change notification settings - Fork 0
/
load.c
78 lines (68 loc) · 976 Bytes
/
load.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
77
78
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int data;
struct node * child1;
struct node * child2;
struct node * child3;
} Treenode,* Tree;
void init(Tree t)
{
t=NULL;
}
void sort(int w[],int n,int c[])
{
int i,j,s;
for(i=0;i<n;i++)
c[i]=i;
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++){
if(w[i]>w[j])
{
s=w[i];
w[i]=w[j];
w[j]=s;
}
}
}
void createTree(Tree t,int w[],int n,int c[],int i)
{
int j;
if(i==n)
return ;
else{
t=(Tree)malloc(sizeof(Treenode));
t->data=w[i];
t->child1=NULL;
t->child2=NULL;
t->child3=NULL;
j=i;
i++;
createTree(t->child1,w,n,c,j);
createTree(t->child2,w,n,c,j);
createTree(t->child3,w,n,c,j);
}
}
void print(Tree t)
{
Treenode *p;
p=t;
while(p->child1!=NULL){
printf("%d ",t->data);
p=p->child1;
}
printf("\n");
}
int main()
{
int w[]={1,2,3,4,5};
int n=5;
int t[5];
int i=0;
Tree tree;
init(tree);
createTree(tree,w,n,t,i);
print(tree);
return 0;
}