Created
September 2, 2016 13:23
-
-
Save eruffaldi/268aec63d5cf44f2497caf1afaa888b6 to your computer and use it in GitHub Desktop.
C++ List Snippet Tools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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