2分探索木
2分木(2分探索木)
struct Tree { int data ; struct Tree* left ; struct Tree* right ; } ; struct Tree* tcons( int x, struct Tree*L, struct Tree*R ) { struct Tree* ans ; ans = (struct Tree*)malloc( sizeof( struct Tree ) ) ; if ( ans != NULL ) { ans->data = x ; ans->left = L ; ans->right = R ; } return ans ; } void main() { struct Tree* top = tcons( 52 , tcons( 24 , tcons( 10 , NULL , NULL ) , tcons( 35 , NULL , NULL ) ) , tcons( 73 , tcons( 60 , NULL , NULL ) , tcons( 95 , NULL , NULL ) ) ) ; }
出来上がった木構造のイメージ
top \ 52 / \ / \ 24 73 / \ / \ 10 35 60 95