Skip to content

Instantly share code, notes, and snippets.

@fivetanley
Created March 7, 2012 23:25
Show Gist options
  • Save fivetanley/1997174 to your computer and use it in GitHub Desktop.
Save fivetanley/1997174 to your computer and use it in GitHub Desktop.
Fuuuuuuuuuuck.cpp
Node* LinkedList::removeAtHead()
{
if (!head)
{
return 0;
}
Node* firstNode = head;
//Advance to the second position in the linked list because
//the first one will be popped off and (hopefully) deleted by the process
//requesting it..
Node* secondNode = (*firstNode).next;
//Remove the reference to the old first Node to prevent memory leaking.
//Set the new first Node of the list to the
head = secondNode;
firstNode->next = 0;
return firstNode;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment