Created
May 4, 2022 15:20
-
-
Save omalinov/4c60aa91e89c614e4c80d17f50695372 to your computer and use it in GitHub Desktop.
Procedural forward list
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 Node | |
{ | |
Node* Next = nullptr; | |
int Data; | |
}; | |
void PushFront(Node*& list, int data) | |
{ | |
Node* newList = new Node(); | |
newList->Data = data; | |
if (list) | |
{ | |
newList->Next = list; | |
} | |
list = newList; | |
} | |
void Destroy(Node*& list) | |
{ | |
while (list) | |
{ | |
Node* pin = list; | |
list = list->Next; | |
delete pin; | |
} | |
list = nullptr; | |
} | |
int main() | |
{ | |
Node* list = nullptr; | |
PushFront(list, 1); | |
PushFront(list, 2); | |
PushFront(list, 3); | |
Destroy(list); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment