Click here to Skip to main content
15,886,518 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionResorce file ....Custom Cursor Pin
ForNow15-Apr-10 21:09
ForNow15-Apr-10 21:09 
QuestionHow to uninstall all modified files from previous setup installation Pin
Chesnokov Yuriy15-Apr-10 20:08
professionalChesnokov Yuriy15-Apr-10 20:08 
QuestionAbout pointer assignment [modified] Pin
milestanley15-Apr-10 15:31
milestanley15-Apr-10 15:31 
AnswerRe: About pointer assignment [modified] Pin
Richard Andrew x6415-Apr-10 16:31
professionalRichard Andrew x6415-Apr-10 16:31 
AnswerRe: About pointer assignment PinPopular
Gwenio15-Apr-10 16:31
Gwenio15-Apr-10 16:31 
AnswerRe: About pointer assignment Pin
Emilio Garavaglia15-Apr-10 20:46
Emilio Garavaglia15-Apr-10 20:46 
AnswerRe: About pointer assignment Pin
KarstenK15-Apr-10 21:49
mveKarstenK15-Apr-10 21:49 
QuestionBinary Tree Help-how to display a tree hierarchy Pin
Member 382253215-Apr-10 14:35
Member 382253215-Apr-10 14:35 
I have to display the contents of a binary tree in its "tree" form rather than a string of numbers.
I have a solution(i think) on how I'm suppose to display it.

My problem is that I keep getting a link error that looks like this:
"b11.obj : error LNK2001: unresolved external symbol "public: void __thiscall AVLTreeType<int>::rnl_inorderTraversal(void (__cdecl*)(int ..."


I know its the display hierarchy component of the program specifically, but I don't know what.
I'm using Visual Studio 08.
Thanks in advance.

and sorry for the long post.
I just thought people would at least want the functional parts of the binary tree class code.

here's most of the binary tree class code:
at the very bottom is the rnl_inorderTraversal function I'm having trouble with.

//file name avlTree.h
#include <iostream>
using namespace std;

template<class T>  //class element type T
struct AVLNode
{
	T info;
	int bfactor;               // balance factor
	AVLNode<T> *llink;
	AVLNode<T> *rlink;
};
template <class T>
class AVLTreeType
{
  public:

	void insert(const T &newItem);

    void postorderTraversal(void (*visit)(T&) );
   
	void rnl_inorderTraversal(void (*visit)(T&,int));
	
	int treeHeight();
    int treeNodeCount();
    int treeLeavesCount();
    void destroyTree();
    AVLTreeType();  //default constructor
	
  private:
    AVLNode<T>* root;
	
	
	
	//associated with insert
    void rotateToLeft(AVLNode<T>* &root);
    void rotateToRight(AVLNode<T>* &root);
    void balanceFromLeft(AVLNode<T>* &root);
    void balanceFromRight(AVLNode<T>* &root);
    void insertIntoAVL(AVLNode<T>* &root,AVLNode<T>  *newNode, bool& isTaller);

	void rnl_inorder(AVLNode<T> *p,void(*visit)(T&,int),int);

   
    void postorder(AVLNode<T> *p, void (*visit)(T&) );
    
    void destroy(AVLNode<T>* &p);
};



template<class T>
void AVLTreeType<T>::rotateToLeft(AVLNode<T>* &root)
{
     AVLNode<T> *p; //pointer to the root of the
                           //right subtree of root
     if(root == NULL)
        cerr<<"Error in the tree."<<endl;
     else
        if(root->rlink == NULL)
           cerr<<"Error in the tree:"
               <<" No right subtree to rotate."<<endl;
        else
        {
            p = root->rlink;
            root->rlink = p->llink; //the left subtree of p 
                             //becomes the right subtree of root
            p->llink = root; 
            root = p;	//make p the new root node
        }
}//end rotateTOLeft

template<class T>
void AVLTreeType<T>::rotateToRight(AVLNode<T>* &root)
{
     AVLNode<T> *p;  //pointer to the root of	
                            //the left subtree of root

     if(root == NULL)
        cerr<<"Error in the tree."<<endl;
     else
        if(root->llink == NULL)
           cerr<<"Error in the tree:"
               <<" No left subtree to rotate."<<endl;
        else
        {
           p = root->llink;
           root->llink = p->rlink; //the right subtree of p 
                           //becomes the left subtree of root
           p->rlink = root; 
           root = p;	//make p the new root node
        }
}//end rotateToRight

template<class T>
void AVLTreeType<T>::balanceFromLeft(AVLNode<T>* &root)
{
     AVLNode<T> *p;
     AVLNode<T> *w;

     p = root->llink;   //p points to the left subtree of root

     switch(p->bfactor)
     {
     case -1: root->bfactor = 0;
              p->bfactor = 0;
              rotateToRight(root);
              break;
     case 0:  cerr<<"Error: Cannot balance from the left."<<endl;
              break;
     case 1:  w = p->rlink;
              switch(w->bfactor)  //adjust the balance factors
              {
              case -1: root->bfactor = 1;
                       p->bfactor = 0;
                       break;
              case 0:  root->bfactor = 0;
                       p->bfactor = 0;
                       break; 
              case 1:  root->bfactor = 0;
                       p->bfactor = -1;
              }//end switch

              w->bfactor = 0;	
              rotateToLeft(p);
              root->llink = p;
              rotateToRight(root);
     }//end switch;
}//end balanceFromLeft

template<class T>
void AVLTreeType<T>::balanceFromRight(AVLNode<T>* &root)
{
     AVLNode<T> *p;
     AVLNode<T> *w;

     p = root->rlink;   //p points to the right subtree of root

     switch(p->bfactor)
     {
     case -1: w = p->llink;
              switch(w->bfactor)  //adjust the balance factors
              {
              case -1: root->bfactor = 0;
                       p->bfactor = 1;
                       break;
              case 0:  root->bfactor = 0;
                       p->bfactor = 0;
                       break;		
              case 1:  root->bfactor = -1;
                       p->bfactor = 0;
              }//end switch

              w->bfactor = 0;	
              rotateToRight(p);
              root->rlink = p;
              rotateToLeft(root);
              break;
     case 0:  cerr<<"Error: Cannot balance from the right."<<endl;
              break;
     case 1:  root->bfactor = 0;
              p->bfactor = 0;
              rotateToLeft(root);
     }//end switch;
}//end balanceFromRight


template<class T>
void AVLTreeType<T>::insert(const T &newItem)
{
     bool isTaller = false;
     AVLNode<T>  *newNode;

     newNode = new AVLNode<T>;
     newNode->info = newItem;
     newNode->bfactor = 0;
     newNode->llink = NULL;
     newNode->rlink = NULL;

     insertIntoAVL(root, newNode, isTaller);
}//end insert



template<class T>
void AVLTreeType<T>::insertIntoAVL(AVLNode<T>* &root, 
			   AVLNode<T>  *newNode, 
			   bool& isTaller)
{
    if(root == NULL)
    {
       root = newNode;
       isTaller = true;
    }
	else 
		if(root->info == newNode->info)
          cerr<<"No duplicates are allowed."<<endl;
	else 
		if(root->info > newNode->info) //newItem goes in 
                                         //the left subtree
          {
             insertIntoAVL(root->llink, newNode, isTaller);

             if(isTaller)             //after insertion, the 
                                      //subtree grew in height
                switch(root->bfactor)
                {
                case -1: balanceFromLeft(root);
                         isTaller = false;
                         break;
                case 0:  root->bfactor = -1;
                         isTaller = true;
                         break;
                case 1:  root->bfactor = 0;
                         isTaller = false;
                }//end switch
          }//end if
          else
          {
             insertIntoAVL(root->rlink, newNode, isTaller);

             if(isTaller)              //after insertion, the 
                                       //subtree grew in height
                switch(root->bfactor)
                {
                case -1: root->bfactor = 0;
                         isTaller = false;
                         break;
                case 0:  root->bfactor = 1;
                         isTaller = true;
                         break;
                case 1:  balanceFromRight(root);
                         isTaller = false;
                }//end switch
          }//end else
}//end insertIntoAVL

template <class T> 
void AVLTreeType<T>::postorderTraversal(void (*visit)(T& item) )
{
	postorder(root, *visit);
}

template <class T> 
void AVLTreeType<T>::postorder(AVLNode<T> *p, 
                             void (*visit)(T& item) )
{
        if(p != NULL)
        {
                postorder(p->llink, *visit);
         
                postorder(p->rlink, *visit);
      (*visit)(p->info);      //function in client file
	 } 
}


template <class T> 
void AVLTreeType<T>::destroy(AVLNode<T>* &p) 
{    
        if(p != NULL)
        {
                destroy(p->llink);
                destroy(p->rlink);
                delete p;
                p = NULL;
        }
}

template <class T>
void  AVLTreeType<T>::destroyTree()
{
        destroy(root);
}

template<class T>
AVLTreeType<T>::AVLTreeType()
{
	root=NULL;
}


template<class T>
void rnl_inorderTraversal(void(*visit)(T&,int))
{
int iLevel=0;
rnl_inorder(root,*visit,iLevel);
}


template<class T>
void rnl_inorder(AVLNode<T> *p,void(*visit)(T&,int),int)
{
	if(p != NULL)
        {
               
				iLevel+1;	
				rnl_inorder(p->rlink,*visit,iLevel);
                (*visit)(p->info);      //function in client file
                rnl_inorder(p->llink,*visit,iLevel)
		} 
}


here's the code for main.
specifically, the areas which rnl_inorderTraversal is used.


#include <iostream>  
#include <iomanip>   
#include"avlTree.h"
#include <fstream>
                     
using namespace std;
//function prototype 
template<class T> 
void displayHierarchial(T& anItem, int level);


int main()
{

AVLTreeType<int> cTree1;
cTree1.insert(1);
cTree1.insert(2);
cTree1.insert(4);
cTree1.rnl_inorderTraversal(displayHierarchial);



return 0;
//function definition 
template<class T>    
void displayHierarchial (T& anItem, int level)
{
  cout <<level<<".) "<< anItem<<' '; //display number from binary tree
}

AnswerRe: Binary Tree Help-how to display a tree hierarchy Pin
Gwenio15-Apr-10 15:23
Gwenio15-Apr-10 15:23 
GeneralRe: Binary Tree Help-how to display a tree hierarchy Pin
Member 382253215-Apr-10 15:52
Member 382253215-Apr-10 15:52 
QuestionWinHelp for Mobile Windows CE 6.0 Pin
Software200715-Apr-10 8:55
Software200715-Apr-10 8:55 
AnswerRe: WinHelp for Mobile Windows CE 6.0 Pin
Eugen Podsypalnikov15-Apr-10 20:17
Eugen Podsypalnikov15-Apr-10 20:17 
QuestionHow to combine Menu and toolbar to one line? Pin
Software200715-Apr-10 6:05
Software200715-Apr-10 6:05 
AnswerRe: How to combine Menu and toolbar to one line? Pin
Iain Clarke, Warrior Programmer15-Apr-10 6:16
Iain Clarke, Warrior Programmer15-Apr-10 6:16 
AnswerRe: How to combine Menu and toolbar to one line? Pin
«_Superman_»15-Apr-10 7:08
professional«_Superman_»15-Apr-10 7:08 
QuestionAccess violation for CWinThread Pin
sksksksksksksks15-Apr-10 0:12
sksksksksksksks15-Apr-10 0:12 
AnswerRe: Access violation for CWinThread Pin
CPallini15-Apr-10 0:24
mveCPallini15-Apr-10 0:24 
AnswerRe: Access violation for CWinThread Pin
Cedric Moonen15-Apr-10 1:06
Cedric Moonen15-Apr-10 1:06 
AnswerRe: Access violation for CWinThread Pin
Rajesh R Subramanian15-Apr-10 4:24
professionalRajesh R Subramanian15-Apr-10 4:24 
GeneralRe: Access violation for CWinThread Pin
CPallini15-Apr-10 7:35
mveCPallini15-Apr-10 7:35 
GeneralRe: Access violation for CWinThread Pin
Moak15-Apr-10 8:21
Moak15-Apr-10 8:21 
GeneralRe: Access violation for CWinThread Pin
CPallini15-Apr-10 8:53
mveCPallini15-Apr-10 8:53 
GeneralRe: Access violation for CWinThread Pin
Iain Clarke, Warrior Programmer15-Apr-10 10:39
Iain Clarke, Warrior Programmer15-Apr-10 10:39 
QuestionHow to Pass a Argument as CArray to a Function. Pin
janaswamy uday14-Apr-10 23:39
janaswamy uday14-Apr-10 23:39 
QuestionRe: How to Pass a Argument as CArray to a Function. Pin
CPallini15-Apr-10 0:04
mveCPallini15-Apr-10 0:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.