Note that there are some explanatory texts on larger screens.

plurals
  1. POBST recursivly position a node
    primarykey
    data
    text
    <p>I'm not particularly good at using recursion, but I felt the need to use it in this case. In my insertion method, I'm using a recursive retrieval method to set the node for insertion to the position desired (in this case, it should be positioning to root->right). Currently I'm using the insert method twice, and it fills root, but does not fill root->right. I'm using pass by reference in my arguments, so I'm really not sure why "found" isn't being set to root->right.</p> <pre><code>int Tree::insert_node(char artist[], char title[], char album[], int length) { // For adding a song node to the tree if(0 == root-&gt;a_song.is_empty()) { // If root is empty, fill it first root-&gt;a_song.set(artist, title, album, length); // Set the members of the node's song } else { // fill a leaf instead node* fill_node; // new node to be inserted retrieve(root, fill_node, artist, title); // set fill_node to it's proper position on the tree fill_node = new node; fill_node-&gt;left = NULL; fill_node-&gt;right = NULL; fill_node-&gt;a_song.set(artist, title, album, length); } //FOR TESTING, REMOVE LATER if(NULL == root-&gt;right) cout &lt;&lt; endl &lt;&lt; "RIGHT IS NULL" &lt;&lt; endl; // This is being output after the first AND second insert else cout &lt;&lt; endl &lt;&lt; "RIGHT IS NOT NULL" &lt;&lt; endl; return 0; } int Tree::retrieve(node* &amp; last, node* &amp; found, char artist[], char title[]) { //simple case: node*last is NULL, meaning found is set to the correct position if(NULL == last) { found = last; return 1; } else if(1 == last-&gt;a_song.compare(artist, title)) { // If artist or title is less, go left retrieve(last-&gt;left, found, artist, title); } else if(-1 == last-&gt;a_song.compare(artist, title)) { // If artist or title is greater, go right // I've tested, and the method is going to this case on the second insertion retrieve(last-&gt;right, found, artist, title); } else return 0; //zero indiciates the song you're trying to insert already exists } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    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