What is the error?
Some suggestion, when deleting the head and tail, set the new head/tail pointer first before deleting the old one. So the code
temp = head;
delete head;
head = temp->next;
should be changed to
temp = head;
head = temp->next;
delete temp;
Do the same for the tail. This is because when you call delete head
, the temp
which is pointing the same location with head
now have garbage values, so you can't just use temp->next
in the subsequent commands.
Also when calling name = temp->info
, make sure it is before the variable is deleted.