Wednesday, February 1, 2012

Data Structure and Algorithm - Binary Tree - Source code - Main program

//
//  main.cpp
// 
//
//  Created by keovessna vong on 2/2/2012.
//  Copyright (c) 2012 Burapha. All rights reserved.
//

#include <iostream>
#include "bSearchTreeType.h"

using namespace std;

int main(){
    bSearchTreeType treeRoot;
   
    int num;
    cout<<"Enter numbers and exit with -999"<<endl;
    cin>>num;
    while(num != -999){
        treeRoot.insert(num);
        cin>>num;
    }
    cout<<endl<<"Tree node in inorder: ";
    treeRoot.inorderTraversal();
    cout<<endl;
   
    cout<<"Number of Nodes: "<<treeRoot.treeNodeCount()<<endl;
    return 0;
}

Look at this running of the main program :

when the user input -999 then the program will show the result as In-order sequence and show out the number of nodes of the tree then exit program

Look at this running of the main program :
In case user input the value that existed then will show an error message !!!

1 comment:

  1. Hi, nice description about Data Structure and Algorithm in Binary Tree.Thanks for your help..

    -Aparna
    Theosoft

    ReplyDelete