#include<stdio.h>
#include<stdlib.h>
typedef int element;
typedef struct node{
element data;
struct node *left, *right;
}Treenode;
/* Treenode n1= {1, NULL, NULL};
Treenode n2= {4, &n1, NULL};
Treenode n3= {16, NULL, NULL};
Treenode n4= {25, NULL, NULL};
Treenode n5= {20, &n3, &n4};
Treenode n6= {15, &n2, &n5};
Treenode *root =&n6;
*/
void init_node(Treenode *root){
root->data = 0;
root->left = NULL;
root->right =NULL;
}
void create_node(Treenode *root, Treenode *left, Treenode *right,element data){
root = (Treenode *)malloc(sizeof(Treenode));
root->data = data;
root->left =
}
void inorder( Treenode *root){
if( root){
inorder( root->left);
printf("%d/", root->data);
inorder( root->right);
}
}
void preorder( Treenode *root){
if( root){
printf("%d/", root->data);
preorder(root->left);
preorder(root->right);
}
}
void postorder( Treenode *root){
if(root){
postorder(root->left);
postorder(root->right);
printf("%d/", root->data);
}
}
int main(void){
Treenode *n1, *n2, *n3, *n4, *n5, *n6;
n1->data =15;
n1-> left = n2;
n1->right = n3;
n2->data = 4;
n2->left = n4;
n2->right =NULL;
n3->data =20;
n3->left = n5;
n3->right = n6;
n4 ->data = 1;
n4 ->left =NULL;
n4 ->right = NULL;
n5 -> data = 16;
n5 -> left = NULL;
n5 -> right = NULL;
n6 -> data = 25;
n6 ->left =NULL;
n6 -> right = NULL;
inorder(root);
preorder(root);
postorder(root);
return 0;
}
'이전것 > Algorithm' 카테고리의 다른 글
이진 트리의 연산 // 노드,단말노드의 개수 (0) | 2014.06.02 |
---|---|
레벨 순회 프로그램 (0) | 2014.06.02 |
배열 트리 (0) | 2014.05.26 |
배열 큐 전체출력 (0) | 2014.05.21 |
연결 큐 미완성 (0) | 2014.05.19 |