mirror of
https://github.com/hazemKrimi/jack-vm-translator.git
synced 2026-05-01 18:00:27 +00:00
feat: generic linked list
This commit is contained in:
@@ -0,0 +1,16 @@
|
|||||||
|
#include "linked-list.hpp"
|
||||||
|
|
||||||
|
template <typename T> int insertNode(LinkedList<T> *list, T data) {
|
||||||
|
LinkedList<T> *node = new LinkedList<T>;
|
||||||
|
|
||||||
|
node->data = data;
|
||||||
|
|
||||||
|
if (list == nullptr) {
|
||||||
|
node->next = list;
|
||||||
|
list = node;
|
||||||
|
} else {
|
||||||
|
list->next = node;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
template <typename T>
|
||||||
|
struct LinkedList {
|
||||||
|
T data;
|
||||||
|
struct LinkedList* next;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
int insertNode(LinkedList<T> *, T);
|
||||||
Reference in New Issue
Block a user