help with trees

can anyone tell me if my nodeCount, leavesCount,swapSubtrees are correct because im getting an error when calling them here the header file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
template <class elemType>
int binaryTreeType<elemType>::leavesCount(nodeType<elemType> *p)
{
   if(p==NULL)
      return 0;
   else if(p->lLink==NULL && p->rLink == NULL)
    return 1;
   else
    return(leavesCount(p->lLink)+ leavesCount(p->rLink));

}
template <class elemType>
int binaryTreeType<elemType>::nodesCount(nodeType<elemType> *p)
{
   if(p != NULL)
   {
       return(1+nodesCount(p->lLink)+ nodesCount(p->rLink));
   }
   else
    return 0;

}
template <class elemType>
void binaryTreeType<elemType>::swapSubTreeNodes(nodeType<elemType> *p)
{
   nodeType<elemType> *root;
   nodeType<elemType> *temp;

   if(p==NULL)
   {
       return ;
   }
   else
   {
       swapSubTreeNodes(p->lLink);
       swapSubTreeNodes(p->rLink);
       temp =p->lLink;
       p->lLink =p->rLink;
       p->rLink =temp;
   }

   root =temp;

}
here the main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include "binarySearchTree.h"
using namespace std;

int main()
{
    bSearchTreeType<int> tree;
    int num;


         //enter numbers and to end it enter a -999
     cout << "please enter number with a space and end it with -999\n: ";
     cin >> num;

    //end when the last number is -999
    while(num != -999)
    {
        tree.insert(num);
        cin >> num;
    }
    //print the list
    cout << "print tree : \n";
    tree.leavesCount();
    return 0;
}

note the call in the main is just a test
Topic archived. No new replies allowed.