Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If the first two entries in the list are duplicates, then it seems that the first time you check for:</p> <pre><code>if(temp2 == temp-&gt;next){ temp = DeleteSong(temp,temp2-&gt;title); } </code></pre> <p>it will evaluate as true at the head of the list. You may want to check what happens from there if your list is suddenly reduced to just the head of your list.</p> <p>I suspect the error may actually be found in the DeleteSong function, because it looks a bit more complicated to me than I recall from other singly-linked lists that I've seen.</p> <p>In pseudo-C, I'd probably attempt something like this:</p> <pre><code>to_delete = find_node_by_key( key ) return if to_delete == null current = head last = null if to_delete == current { head = current-&gt;next to_mem_free = current } else do { if to_delete == current { to_mem_free = current if ( last != null ) last-&gt;next = current-&gt;next break } last = current } while (current = current-&gt;next) != null </code></pre> <p>You can combine the search for the node to delete with the actual deletion so you won't have to traverse the list twice. You may also want to try to avoid using "temp" as a variable name unless absolutely necessary because it often causes confusion.</p> <p>Many tool chains include a library that provides singly-linked lists. You can save yourself hours of coding and debugging by using such a library, which probably also provide sorted trees or hash lists that significantly speed up searching for, e.g., song titles.</p>
 

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