Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does this keep on returning only one node of my singly linked list?
    primarykey
    data
    text
    <p>I have a structure, </p> <pre><code> typedef struct song{ string title; string artist; string album; string genre; float rating; struct song *next; }song_t; </code></pre> <p>and a delete function,</p> <pre><code> song_t *DeleteSong(song_t *head, string key){ song_t *temp, *temp2, *holder; holder = (song_t *)malloc(sizeof(song_t)); temp = head; while(temp != NULL &amp;&amp; strcasecmp(temp-&gt;title, key) != 0){ temp = temp-&gt;next; } if(temp == NULL){ newline; printf("Song not found."); newline; newline; } else if(temp == head){ if(temp-&gt;next == NULL){ temp-&gt;next = NULL; free(temp); return NULL; } else{ head = temp-&gt;next; } } else if(temp-&gt;next == NULL){ temp2 = head; while(temp2-&gt;next-&gt;next != NULL){ temp2 = temp2-&gt;next; } holder = temp2-&gt;next-&gt;next; temp2-&gt;next = NULL; } else{ temp2 = head; while(temp2-&gt;next != temp){ temp2 = temp2-&gt;next; } holder = temp; temp2-&gt;next = temp-&gt;next; free(holder); } return head; } </code></pre> <p>and finally, a remove duplicate function,</p> <pre><code>song_t *RemoveDuplicate(song_t *head){ song_t *temp; song_t *temp2; temp = head; temp2 = temp-&gt;next; while(temp != NULL){ while(temp2 != NULL){ if(strcasecmp(temp-&gt;title,temp2-&gt;title) == 0 &amp;&amp; strcasecmp(temp-&gt;artist,temp2-&gt;artist) == 0 &amp;&amp; strcasecmp(temp-&gt;album,temp2-&gt;album) == 0 &amp;&amp; strcasecmp(temp-&gt;genre,temp2-&gt;genre) == 0){ if(temp2 == temp-&gt;next){ temp = DeleteSong(temp,temp2-&gt;title); } else{ temp2 = DeleteSong(temp2-&gt;next,temp2-&gt;title); } } temp2 = temp2-&gt;next; } temp = temp-&gt;next; } } </code></pre> <p>However, whenever I include the remove duplicate function in main, head = RemoveDuplicate(head);</p> <p>the result always returns only one structure and removes the whole list. I think that there is something wrong with the RemoveDuplicate function because I tested the DeleteSong function and it works well.</p>
    singulars
    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.
 

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