Created
January 31, 2022 10:22
-
-
Save krissemicolon/23e04b19c83fc8f06180735918a8c880 to your computer and use it in GitHub Desktop.
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
#include <stdio.h> | |
#include <stdlib.h> | |
typedef struct _node { | |
int data; | |
struct _node *next; | |
} node; | |
typedef struct { | |
node *head; | |
node *tail; | |
int size; | |
} list; | |
void append(list *l, node *n) { | |
l->tail = l->tail->next = n; | |
} | |
void printlist(list *l) { | |
puts("Printing The List:"); | |
for(node *current = l->head; current != NULL; current = current->next) { | |
printf("%i\n", current->data); | |
} | |
} | |
int main() { | |
node *n3 = malloc(sizeof(node)); n3->data = 7; n3->next = NULL; | |
node *n2 = malloc(sizeof(node)); n2->data = 6; n2->next = n3; | |
node *n1 = malloc(sizeof(node)); n1->data = 5; n1->next = n2; | |
list *l = malloc(sizeof(list)); | |
l->head = n1; | |
l->tail = n3; | |
printlist(l); | |
node *n4 = malloc(sizeof(node)); n4->data = 8; n4->next = NULL; | |
append(l, n4); | |
printlist(l); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment