Thread: How do I call this function in my client file?

  1. #1
    Unregistered
    Guest

    How do I call this function in my client file?

    How do I call this function: void InorderTrnaverse(node *leaf); in my client file?
    I am not getting the syntax correct.

    #include<iostream>
    #include<iomanip>
    #include<fstream>
    #include <cctype> // defines isalpha() function

    #include"TreeImplementation.cpp"

    using namespace std;


    int main()
    {

    node structnode;

    btree bt;
    int num=0;
    char chr;
    int count=0;
    int *leaf;

    ifstream fin("input.txt");
    ofstream fout("output1.txt");

    fin>>num;
    fin>>chr;
    while(fin)
    {
    bt.insert(num);
    bt.search(num);
    bt.InorderTrnaverse(num);
    fout<<num;
    count++;
    fout<<"Step: "<<count<<" "<<"Data Value = "<<num<<" "<<"Activity Signal = "<<chr<<endl;


    fout<<"Preorder Transversal = "<<endl<<endl;
    fout<<"Inorder Transversal = "<<endl<<endl;
    fout<<"Post order Transversal = "<<endl<<endl;
    fout<<"Level by Level Transversal = "<<endl<<endl;
    fout<<"Total Number of nodes = "<<count<<endl<<endl;

    fin>>num;
    fin>>chr;
    }


    return 0;
    }

    Function

    void btree::InorderTrnaverse(node *leaf)
    {

    if(leaf != NULL)
    InorderTrnaverse(LChild(leaf));
    cout<<leaf;
    InorderTrnaverse(RChild(leaf));
    }

    header

    struct node
    {
    int key_value;
    node *left;
    node *right;
    };


    class btree
    {
    public:
    // node *root;
    btree();
    // ~btree();
    void destroy_tree(node *leaf);
    void insert(int key, node *leaf);
    node *search(int key, node *leaf);
    //public:
    void insert(int key);
    node *search(int key);
    //void destroy_tree();
    void InorderTrnaverse(node *leaf);
    private:
    node *root;
    };
    node *RChild(node *leaf);
    node *LChild(node *leaf);

  2. #2
    Registered User kitten's Avatar
    Join Date
    Aug 2001
    Posts
    109
    You need a btree object (or a pointer or a reference) and a node object for an attribute.


    btree BinTree;
    BinTree.InorderTrnaverse(new node()) ;

    ...for example
    Making error is human, but for messing things thoroughly it takes a computer

  3. #3
    Unregistered
    Guest
    Sould I uste the inserrt function? void insert(int key, node *leaf);

    bt.InorderTranverse(void insert(int key, node *leaf));

  4. #4
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    No, but you could do something similar to your insert routine by creatiing a InorderTranverse function that takes no arguments that passes the root to your other InorderTranverse function (that takes a node as an argument). This way it could be called recursively. You could also make this second InorderTranverse function private as it's not going to be called directly.
    zen

  5. #5
    Light-Force
    Guest

    hmm

    You may also want to make a header file...its just a lil cleaner code pratice.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM