I'm having a hard time picking up the logic of how to remove all nodes from a circular list, if anyone could give a brief explanation of concept and / or point out the errors in the code I've already done, I'd be grateful:
int freelist ( Node ** list ) {
if ( empty ( list ) ) {
return 0;
}
if ( ( * list ) == ( * list ) -> next ) {
free ( * list );
( * list ) = NULL;
return 1;
}
Node * tmp = NULL, * aux = ( * list ) -> next;
while ( aux != ( * list ) ) {
tmp = aux;
aux = aux -> next;
free ( tmp );
}
// ( * list ) = NULL;
return 1;
}
If the list contains only one item the function works perfectly, if more than one it does not delete them ... (Full code here )