From 25c5909011873bc34bdd9394f3fec04ad28bbb72 Mon Sep 17 00:00:00 2001 From: Hacker <56584374+vidhidrana01@users.noreply.github.com> Date: Sat, 15 Oct 2022 23:50:23 +0530 Subject: [PATCH] Create linked list --- linked list | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 linked list diff --git a/linked list b/linked list new file mode 100644 index 0000000..59b5444 --- /dev/null +++ b/linked list @@ -0,0 +1,45 @@ +// Linked list implementation in C + +#include +#include + +// Creating a node +struct node { + int value; + struct node *next; +}; + +// print the linked list value +void printLinkedlist(struct node *p) { + while (p != NULL) { + printf("%d ", p->value); + p = p->next; + } +} + +int main() { + // Initialize nodes + struct node *head; + struct node *one = NULL; + struct node *two = NULL; + struct node *three = NULL; + + // Allocate memory + one = malloc(sizeof(struct node)); + two = malloc(sizeof(struct node)); + three = malloc(sizeof(struct node)); + + // Assign value values + one->value = 1; + two->value = 2; + three->value = 3; + + // Connect nodes + one->next = two; + two->next = three; + three->next = NULL; + + // printing node-value + head = one; + printLinkedlist(head); +}