Skip to content

Instantly share code, notes, and snippets.

@eruffaldi
Created September 2, 2016 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eruffaldi/268aec63d5cf44f2497caf1afaa888b6 to your computer and use it in GitHub Desktop.
Save eruffaldi/268aec63d5cf44f2497caf1afaa888b6 to your computer and use it in GitHub Desktop.
C++ List Snippet Tools
struct List
{
ListNode * first = 0, * last = 0;
void append(ListNode*p)
{
if(first)
{
last->next = p;
last = p;
}
else
{
first = last = p;
}
}
void prepend(ListNode * p)
{
if(first)
{
p->next = first;
first = p;
}
else
{
first = last = p;
}
}
void close()
{
last->next = 0;
}
};
struct ListLoop
{
ListLoop(ListNode * & q): q_(q)
{
n_ = q->next;
}
~ListLoop() { q_ = n_; }
ListNode * & q_;
ListNode * n_;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment