Please help fix my code

the problem for 7 of my functions is along the lines of: Error 1 error LNK2019: unresolved external symbol "public: __thiscall BST<int>::BST<int>(void)" (??0?$BST@H@@QAE@XZ) referenced in function _main C:\Users\Pak\Dropbox\CSCI 262\Lab10\Lab10\Sprout.obj

essentially i keep getting:: Error 1 error LNK2019: unresolved external symbol [...etc...]

///////////////////////////////////
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <iostream>
#include <iomanip>
#include "BST.h"
using namespace std;

	
	template <class Name>
	BST<Name>::BST()
	{
		root = NULL;
	}

	template <class Name>
	BST<Name>::~BST()
	{
		prune(root);
		cout << "ping!" << endl;
	}

	template <class Name>
	BST<Name>::BST(const BST<Name>& tree)
	{
		root = NULL;
		clone(tree.root);
	}

	template <class Name>
	const BST<Name>& BST<Name>::operator=(const BST<Name>& tree)
	{
		if (this != &tree)
		{
			prune(root);
			root = NULL;
			clone(tree.root);
		}
		return *this;
	}



	template <class Name>
	bool BST<Name>::empty(void) const
	{
		return !root;
	}

	template <class Name>
	void BST<Name>::insert(Name value)
	{
		Node<Name>* parent = NULL;
		Node<Name>* focus = trace(parent, value);
		if(!focus) //nothing matches
		{
			focus = new Node<Name>(value);
			if(!parent)
				root = focus;
			else
				if (value < parent->data)
					parent->left = focus;
				else parent->right = focus;
		}

	}

	template <class Name>
	void BST<Name>::remove(Name value)
	{
		Node<Name>* parent = NULL;
		Node<Name>* focus = trace(parent, value);	//focus will be the deleted Node<Name>
		if(focus)	//if not null yet
		{
			Node<Name>* hold = focus;	//hold your current focus
			if(focus->left && focus->right)	//if branches are full
			{
				parent = focus;	//parent will poName to value being removed => NULL!

				//find max value LESS than focus
					focus = focus->left; 
					while(focus->right)
					{
						parent = focus;
						focus = focus->right;
					}

				hold->data = focus->data; //swap
			}

			hold = (focus->left ? focus->left : focus->right); //if you still have something left, or right I suppose, don't lose it
			if(!parent) //are we focussed on the top?
				root = hold;
			else
				if (parent->data < focus->data) //skip over the focus
					parent->right = hold;
				else
					parent->left = hold;
			delete focus;
		}
	}

	template <class Name>
	bool BST<Name>::find(Name value)
	{
		Node<Name>* parent = NULL;
		Node<Name>* focus = trace(parent, value);
		return focus;
	}



	template <class Name>
	Node<Name>* BST<Name>::trace(Node<Name>*& parent, Name& value) //maybe later, overload operator++?
	{
		Node<Name>* focus = root;
		parent = NULL;
		while( focus && (focus->data != value) )
		{
			parent = focus;	//take this with you
			focus = (value < focus->data) ? focus->left : focus->right;
		}
		return focus;
	}

	template <class Name>
	void BST<Name>::prune(Node<Name>* stem)
	{
		if(stem)
		{
			prune(stem->left);
			prune(stem->right);
			delete stem;
		}
	}

	template <class Name>
	void BST<Name>::clone(Node<Name>* stem)
	{
		if(stem)
		{
			insert(stem->data);
			clone(stem->left);
			clone(stem->right);
		}
	}



	template <class Name>
	void BST<Name>::print(Node<Name>* focus, std::size_t height=0) const
	{
		if(!height) 
			cout << "= = = = = =\n";
		if(focus) 
		 {
			 prName(focus->right,height+1); 
			 cout<<setw(height*SPACER)<<focus->data<<endl;
			 prName(focus->left,height+1); 
		 }
	}


///////////////////

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
#include <iostream>
#include <iomanip>
#include "Node.h"
using namespace std;

template <class Name>
class BST
{

public:

	//typedef Node<Name> Node<Name>;
	
	BST();//
	~BST();//
	BST(const BST&);//
	const BST& operator=(const BST&);//

	Node<Name>* getroot() {return root;}
	bool empty(void) const; 
	void insert(Name value);//
	void remove(Name value);//
	bool find(Name value);
		
	Node<Name>* trace(Node<Name>*& parent, Name& value);
	void prune(Node<Name>* stem);
	void clone(Node<Name>* stem);
    void print(Node<Name>* stem, size_t value) const;//
		
	static const int SPACER=5;
	

	private:
	Node<Name> *root;
		
};
Last edited on
Topic archived. No new replies allowed.