You know, Prelude, 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. This data structs class is distance learning, so real-time help doesn't exist for me :-( I read up on std:air, modified my function and included the <utility> header, and included pair class def., but the compiler does not like my use of enqueue() for pair (do I have to overload it?), and doesn't accept my declaration of pair in the getIPL function. As usual, thanks for any help, and what you've done so far!
-Patrick
pair class declaration:
Code:
template <class T>
class pair {
T values [2];
public:
pair (T first, T second)
{
values[0]=first; values[1]=second;
}
};
New getIPL() function
Code:
template<class T>
void BinSearchTree<T>::getIPL()
{
int level = 0;
static int count = 0;
Queue<BinSearchNode<T>*> anotherQueue;
BinSearchNode<T> * n = root;
if(n != 0)
{
anotherQueue.enqueue(make_pair(n, level)); //no-go. Must I overload?
while(!anotherQueue.empty())
{
pair<BinSearchNode<int>*, int> save = n.dequeue(); //error
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 if(n == 0)
{
level = 0;
count = 0;
}
cout << "This tree has an IPL of " << level << endl;
}