Created
October 25, 2017 14:22
-
-
Save H2CO3/e96a2c996c1509a85afa81eb6a57c6dd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <vector> | |
#include <cstdio> | |
struct Node { | |
int value; | |
Node *next; | |
Node(int _value, Node *_next): value(_value), next(_next) {} | |
~Node() { | |
std::printf("Destroying %d\n", value); | |
} | |
}; | |
int main() { | |
auto head = new Node( | |
0, new Node ( | |
1, new Node( | |
2, new Node( | |
3, nullptr | |
) | |
) | |
) | |
); | |
auto tmp = head; | |
auto next = head->next; | |
while (next != nullptr) { | |
delete tmp; | |
tmp = next; | |
next = next->next; | |
} | |
} | |
// output: | |
// Destroying 0 | |
// Destroying 1 | |
// Destroying 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment