diff --git a/c/linked_list.c b/c/linked_list.c new file mode 100644 index 0000000..10b0494 --- /dev/null +++ b/c/linked_list.c @@ -0,0 +1,75 @@ +#include +#include + +typedef struct Node { + int value; + struct Node* next; + struct Node* prev; +} Node; + +typedef struct LinkedList { + int length; + Node* head; + Node* tail; +} LinkedList; + +LinkedList* new_linked_list() { + LinkedList* ll = malloc(sizeof(LinkedList)); + ll->length = 0; + + return (ll); +} + +Node* new_node(int value) { + Node* n = malloc(sizeof(Node)); + n->value = value; + n->next = NULL; + n->prev = NULL; + return (n); +} + +// append - insert a node at the end of the linked list + +// prepend - insert a node at the front of the linked list +void preppend(LinkedList* list, Node* node) { + if (list->length == 0) { + list->head = node; + list->tail = node; + list->length++; + } else { + list->head->prev = node; + node->next = list->head; + list->head = node; + } +} + +void print_list(LinkedList* list) { + Node* curr = list->head; + printf("[ "); + while (curr != NULL) { + printf("%d ", curr->value); + curr = curr->next; + } + printf("]\n"); +} + +int get_size_list(LinkedList* list) { + return 0; +} + +// insert at - insert a node at a given index + +int main() { + LinkedList* list = new_linked_list(); + Node* a = new_node(10); + Node* b = new_node(11); + append(list, a); + append(list, b); + append(list, new_node(12)); + append(list, new_node(13)); + append(list, new_node(14)); + append(list, new_node(15)); + + print_list(list); + return (0); +} \ No newline at end of file diff --git a/c/linked_list.exe b/c/linked_list.exe new file mode 100644 index 0000000..04cbc98 Binary files /dev/null and b/c/linked_list.exe differ diff --git a/c/linked_list.ilk b/c/linked_list.ilk new file mode 100644 index 0000000..ba857f3 Binary files /dev/null and b/c/linked_list.ilk differ diff --git a/c/linked_list.obj b/c/linked_list.obj new file mode 100644 index 0000000..6752649 Binary files /dev/null and b/c/linked_list.obj differ diff --git a/c/linked_list.pdb b/c/linked_list.pdb new file mode 100644 index 0000000..f0d5937 Binary files /dev/null and b/c/linked_list.pdb differ diff --git a/c/vc140.pdb b/c/vc140.pdb index 22493b9..2e853b6 100644 Binary files a/c/vc140.pdb and b/c/vc140.pdb differ