示例#1
0
文件: LCRSTree.c 项目: ESOS-Lab/MOST
void LCRS_DestroyTree( LCRSNode* Root )
{
    if ( Root->RightSibling != NULL )
        LCRS_DestroyTree( Root->RightSibling );

    if ( Root->LeftChild != NULL )
        LCRS_DestroyTree( Root->LeftChild );

    Root->LeftChild = NULL;
    Root->RightSibling = NULL;

    LCRS_DestroyNode( Root );
}
示例#2
0
int main(void)
{
    LCRSNode* Root = LCRS_CreateNode('A');
    
    LCRSNode* B = LCRS_CreateNode('B');
    LCRSNode* C = LCRS_CreateNode('C');
    LCRSNode* D = LCRS_CreateNode('D');
    LCRSNode* E = LCRS_CreateNode('E');
    LCRSNode* F = LCRS_CreateNode('F');
    LCRSNode* G = LCRS_CreateNode('G');
    LCRSNode* H = LCRS_CreateNode('H');
    LCRSNode* I = LCRS_CreateNode('I');
    LCRSNode* J = LCRS_CreateNode('J');
    LCRSNode* K = LCRS_CreateNode('K');
    
    LCRS_AddChildNode(Root, B);
        LCRS_AddChildNode(B, C);
        LCRS_AddChildNode(B, D);
            LCRS_AddChildNode(D, E);
            LCRS_AddChildNode(D, F);
    LCRS_AddChildNode(Root, G);
        LCRS_AddChildNode(G, H);
    LCRS_AddChildNode(Root, I);
        LCRS_AddChildNode(I, J);
            LCRS_AddChildNode(J, K);
    
    LCRS_PrintTree(Root, 0);
    
    printf("Level 0 :\n");
    LCRS_PrintNodesAtLevel(Root, 0);
    printf("Level 1 :\n");
    LCRS_PrintNodesAtLevel(Root, 1);
    printf("Level 2 :\n");
    LCRS_PrintNodesAtLevel(Root, 2);
    printf("Level 3 :\n");
    LCRS_PrintNodesAtLevel(Root, 3);
    
    LCRS_DestroyTree(Root);
    
    return 0;
}