Last active
January 2, 2016 03:29
-
-
Save SergNikitin/8244480 to your computer and use it in GitHub Desktop.
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
class ListNode { | |
friend class List; | |
public: | |
ListNode* nextNodePointer; | |
ListNode* previousNodePointer; | |
int value; | |
private: | |
/** | |
* Constructs an empty element of the list, points to NULL by default | |
*/ | |
ListNode(); | |
/** | |
* Constructs an element of the list, points to NULL by default | |
*/ | |
ListNode(const int _value); | |
}; | |
void List::clear() { | |
if (firstNodePointer != NULL) { | |
ListNode* nodeToDelete = firstNodePointer; | |
ListNode* nextNodeToDelete = firstNodePointer->nextNodePointer; | |
while (nextNodeToDelete != NULL) { | |
delete nodeToDelete; | |
nodeToDelete = nextNodeToDelete; | |
nextNodeToDelete = nextNodeToDelete->nextNodePointer; | |
} | |
delete lastNodePointer; | |
rewriteFirstNodePointer(NULL); | |
rewriteLastNodePointer(NULL); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment