EDIT tu drobnost, že jsem chybí !! chyba je stále ještě
Takže já jsem se snaží naučit, jak kódovat svůj první BST, a to je těžké .... Už jsem potíže s jen pár řádků kódu. Problém je ve vložce, ale jsem zařadil všechno tak, že bych mohl dostat nějakou zpětnou vazbu na můj styl / jiné chyby. Byl jsem navrhl použít ukazatel na realizaci ukazatele, ale my havent ještě nenaučili to, takže já dont pocit pohodlí / vědět, jak ji ještě kód.
chyba je
[trinhc@cs1 Assignment_3]$ g++ movieList.cpp -o a.out
/tmp/ccLw6nsv.o: In function `main':
movieList.cpp:(.text+0x7a): undefined reference to `Tree::Tree()'
movieList.cpp:(.text+0xa7): undefined reference to `Tree::insert(int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: ld returned 1 exit status
Soubor tree.h
#ifndef TREE_H
#define TREE_H
#include <string>
#include <iostream>
using namespace std;
class Tree
{
public:
Tree();
bool insert(int k, string s);
private:
struct Node
{
int key;
string data;
Node *left;
Node *right;
};
Node* root;
bool insert(Node*& root, int k, string s);
};
#endif
tree.cpp
#include <iostream>
#include tree.h
#include <stack>
#include <queue>
#include <string>
using namespace std;
Tree::Tree()
{
root = NULL;
}
bool Tree::insert(int k, string s)
{
return insert(root, k, s);
}
bool Tree::insert(Node*& current_root, int k, string s)
{
if(root == NULL){
current_root = new Node;
current_root->key = k;
current_root->data = s;
current_root->left = NULL;
current_root->right = NULL;
return true;
}
else if (current_root->key == k)
return false;
else if (current_root->key > k)
insert(current_root->left, k, s);
else
insert (current_root->right,k, s);
}
movieList.cpp
#include <iostream>
#include <stack>
#include <queue>
#include <string>
#include tree.h
using namespace std;
int main()
{
Tree test;
test.insert(100, blah);
return 0;
}













