ホーム » 2017 » 10月 » 10

日別アーカイブ: 2017年10月10日

2017年10月
1234567
891011121314
15161718192021
22232425262728
293031  

検索・リンク

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

(さらに…)

システム

最新の投稿(電子情報)

アーカイブ

カテゴリー