Skip to content

Instantly share code, notes, and snippets.

@omalinov
Created May 4, 2022 15:20
Show Gist options
  • Save omalinov/4c60aa91e89c614e4c80d17f50695372 to your computer and use it in GitHub Desktop.
Save omalinov/4c60aa91e89c614e4c80d17f50695372 to your computer and use it in GitHub Desktop.
Procedural forward list
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