diff options
author | oskar <[email protected]> | 2024-05-10 23:41:25 +0200 |
---|---|---|
committer | oskar <[email protected]> | 2024-05-10 23:41:25 +0200 |
commit | ec3079e3f4a0124c744ec7e5b7a3fe78d2bbca77 (patch) | |
tree | 3cee44f4f691751528d0e254370596f73ab87ca7 /linked.c | |
parent | 3b2246ab2a255710a3ef02fb0f9f19dc92e528a7 (diff) |
Implemented doubly linked list, fixed issued with singly linked list. Added some nicer visualization for both of them.
Diffstat (limited to 'linked.c')
-rw-r--r-- | linked.c | 56 |
1 files changed, 0 insertions, 56 deletions
diff --git a/linked.c b/linked.c deleted file mode 100644 index 8f47a41..0000000 --- a/linked.c +++ /dev/null @@ -1,56 +0,0 @@ -#include <stdio.h> -#include <stdlib.h> -#include <stddef.h> -#include <unistd.h> -#include <stdint.h> -#include <stdbool.h> -#include <string.h> - -struct waster { - int gg; - struct waster *next; -}; - -void *newnode () { - - struct waster *new = malloc(sizeof(struct waster)); - return new; -} - -struct waster *llist (uint64_t count) { - - struct waster *wr1 = malloc(sizeof(struct waster)); - struct waster *head = wr1; - for (uint64_t i = 0 ; i < count ; i++) { - - wr1->gg = i; - wr1->next = newnode(); // Make new node and assign address of the new node to the current one - wr1 = wr1->next; // Make save point to the next node - - } - - wr1->next = NULL; - return head; -} - -void freellist(struct waster *wr1) { - //printf("freelist \n"); - struct waster *save; - while (wr1 != NULL) { - save = wr1; - wr1 = wr1->next; - free(save); - } -} - -int main () { - - struct waster *wr1 = llist(10); - struct waster *p; - for (p = wr1 ; p->next != NULL ; p = p->next) { - printf("%d\n", p->gg); - } - - freellist(wr1); - return 0; -}
\ No newline at end of file |