Esempio n. 1
0
int main(){
    
    int i,count;
    int number[MAXSIZE]={75,30,21,50,45,9,16,12,31,40};
    TRnode *root = NULL;
    
    printf("Sequence before Binary tree sort :\n");
                for(i=0;i<MAXSIZE;i++){
                    if(i==(MAXSIZE-1)){printf("%d\n",number[i]);}
                    else{
                    printf("%d ->",number[i]);
                    }
                }
    
        for(i=0;i<MAXSIZE;i++){
                          
           root = Add_tree_node(root,number[i]);              
        
        }
    printf("Sequence after Binary tree sort¡iInorder tracersal¡j :\n");
            Inorder_traversal(root);    
    printf("[Delete all of tree node..]\n");
    count = Delete_node(root,root);
    printf("The number of deleted node is : %d\n",count);
    
    
    
    system("pause");
    return(0);
    }
Esempio n. 2
0
int main(int argc, const char *argv[])
{
    DT *head ;
    head = creak_link(10);
    print_link(head);
    head = Delete_node(head);
    printf("\n");
    print_link(head);
    return 0;
}
Esempio n. 3
0
//------Delete idea, use Postorder_traversal method,from bottom to top ,from left to right-------//     
int Delete_node(TRnode *root,TRnode *parent_node){
                     
          int count = 0;           
          if(root == NULL){return 0;}
            else{
                 //printf("count : %d\n",count);
                 count = count + Delete_node(root->left,root);                 
                 count = count + Delete_node(root->right,root);     
                 printf("\tThis tree node %d wil be deleted \n",root->data);
                 if((parent_node->data) < (root->data)){
                        parent_node->right = NULL;
                                                              
                 }
                 else{
                       parent_node->left = NULL;
                 }
                        free(root);
                        root = NULL;
                        count++;
                        
            }
            return(count);              
                  
    }