Thread: Assymetric delete() vs. symmetric delete() functions - binary tree

  1. #16
    Registered User
    Join Date
    Jun 2006
    Posts
    121
    Sorry, at the bottom it should read,

    cout << "This tree has an IPL of " << count << endl;

  2. #17
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I'm thinking that software engineering is not a field I should be looking into; I can't do a lot of
    >the projects in the book without asking for help.
    Programming is very hard. I think you're doing well, all things considered. Only a handful of the pros I know could solve this problem easily without asking for help or nicking a solution from somewhere.

    >but the compiler does not like my use of enqueue() for pair
    pair and make_pair already exist in the <utility> header. It looks like you're trying to declare your own pair type and use it with the standard make_pair function, which is unlikely to work since they're designed as a pair (haha! I made a funny). Ditch the pair that you defined and make sure that your queue stores a pair rather than just a node:
    Code:
    template<class T>
    void BinSearchTree<T>::getIPL()
    {
            static int count = 0;
            Queue<pair<BinSearchNode<T>*, int> > anotherQueue;
            BinSearchNode<T> * n = root;
            if(n != 0)
            {
                    anotherQueue.enqueue(make_pair(n, 0));
                    while(!anotherQueue.empty())
                    {   
                        pair<BinSearchNode<T>*, int> save = n.dequeue();
                        n = save.first; //doesn't recognize save
                        count += save.second;
                        if(n->left != 0)
                        {
                            anotherQueue.enqueue(make_pair(n->left, save.second+1));
            
                        }
                        if(n->right != 0)
                        {
                            anotherQueue.enqueue(make_pair(n->right, save.second+1));
                        }
                        
                    }
             }
             else
             {
                  count = 0;
             }
             cout << "This tree has an IPL of " <<  count << endl;
    }
    My best code is written with the delete key.

  3. #18
    Registered User
    Join Date
    Jun 2006
    Posts
    121
    Thanks for the words of encouragement. Funny, I thought I was a C++ guru after the two intro courses, and then got my butt handed to me this term with this data structs course, didn't know there was a third (and advanced course), LOL. I did look at std:air pretty hard, but the problem I have with references is that they tend to be very concise and to the point; totally aimed at advanced programmers, and their definitions leave me clueless, and they provide to real-world examples to us mere mortals.

    -Patrick

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  2. binary tree start
    By curlious in forum C++ Programming
    Replies: 6
    Last Post: 01-01-2004, 03:47 PM
  3. read records fron file into a binary tree
    By Kirsten in forum C Programming
    Replies: 1
    Last Post: 04-23-2002, 02:48 PM
  4. Array, Linked List, or Binary Tree?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 01-05-2002, 10:07 PM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM