Note that there are some explanatory texts on larger screens.

plurals
  1. POhelp with insert on first BST
    primarykey
    data
    text
    <p>EDIT there a small thing that I am missing!! the error is still there</p> <p>So I am attempting to learn how to code my first BST, and it is hard.... I am already having trouble with just a few lines of codes. the problem is in the insert, but I have included everything so that I could get some feedback on my style/other errors. I was suggested to use a pointer to pointer implementation, but we havent learned it yet, so I dont feel comfort/know how to code it yet. the </p> <p>error is </p> <pre><code>[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&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;)' collect2: ld returned 1 exit status </code></pre> <p>the tree.h file</p> <pre><code>#ifndef TREE_H #define TREE_H #include &lt;string&gt; #include &lt;iostream&gt; 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*&amp; root, int k, string s); }; #endif </code></pre> <p>tree.cpp</p> <pre><code>#include &lt;iostream&gt; #include "tree.h" #include &lt;stack&gt; #include &lt;queue&gt; #include &lt;string&gt; using namespace std; Tree::Tree() { root = NULL; } bool Tree::insert(int k, string s) { return insert(root, k, s); } bool Tree::insert(Node*&amp; current_root, int k, string s) { if(root == NULL){ current_root = new Node; current_root-&gt;key = k; current_root-&gt;data = s; current_root-&gt;left = NULL; current_root-&gt;right = NULL; return true; } else if (current_root-&gt;key == k) return false; else if (current_root-&gt;key &gt; k) insert(current_root-&gt;left, k, s); else insert (current_root-&gt;right,k, s); } </code></pre> <p>movieList.cpp</p> <pre><code>#include &lt;iostream&gt; #include &lt;stack&gt; #include &lt;queue&gt; #include &lt;string&gt; #include "tree.h" using namespace std; int main() { Tree test; test.insert(100, "blah"); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload