error: `root' was not declared in this scope

I have started working on binary trees. On the first example I get this error:
[Error] C:\Dev-Cpp\MalikChapter11\Example11.6\Example11-6\bSearchTreeType.cpp:16: error: `root' was not declared in this scope
[Error] C:\Dev-Cpp\MalikChapter11\Example11.6\Example11-6\bSearchTreeType.cpp:59: error: `trailcurrent' was not declared in this scope

I have included all the needed headers
1
2
3
4
5
6
#include "bSearchTreeType.h"
#include<algorithm>
//#include "bsearchTreeType.cpp"
#include "binaryTreeType.h"
#include<iostream>
#include<stdio.h> 

I can post all the files if needed to.
I only get those two errors
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
 template<class elemType>
bool bSearchTreeType<elemType>::search(const elemType& searchItem)
{
	nodeType<elemType> *current;
	bool found = false;
	
	if(root == NULL)
		cerr<<"Cannot search an empty tree." <<endl;
	else
	{
		current = root;
		
		while(current != NULL & !found)
		{
			if(current->info == searchItem)
				found = true;
			else
				if(current->info > searchItem)
					current = current->llink;
				else
					current = current->rlink;
		}  //end while
	}  //end else

	return found;
}  //end search


template<class elemType>
void bSearchTreeType<elemType>::insert(const elemType& insertItem)
{
	nodeType<elemType> *current;      //pointer to traverse the tree
	nodeType<elemType> *trailCurrent;  //pointer behind current
	nodeType<elemType> *newNode;       //pointer to create the node
	
	newNode = new nodeType<elemType>;
	assert(newNode != NULL);
	newNode->info = insertItem;
	newNode->llink = NULL;
	newNode->rlink = NULL;
	
	if(root == NULL)
		root = newNode;
	else
	{
		current = root;
		
		while(current != NULL)
		{
			trailcurrent = current;
			
			if(current->info == insertItem)
			{
				cerr<<"The insert item is already in the list - ";
				cerr<<"duplicates are not allowed." << endl;
				return ;
			}
			else
				if(current->info > insertItem)
					current = current->llink;
				else
					current = current->rlink;
		}// end while
		
		if(trailcurrent->info > insertItem)
			trailCurrent->llink = newNode;
		else
			trailCurrent->rlink = newNode;
	}
}  //end insert

Regards,
while(current != NULL & !found)
Shall be written as
while(current != NULL && !found).
Last edited on
I have corrected that typing error. The same error still comes up
 
while(current != NULL && !found)
Registered users can post here. Sign in or register to post.