From 9378aae857ab2d6388a126e1db717a5940f832b3 Mon Sep 17 00:00:00 2001 From: Shrashti Bhumarkar <113536361+shrashti2004@users.noreply.github.com> Date: Tue, 11 Oct 2022 10:48:21 +0530 Subject: [PATCH] Create DSAquestions.c --- DSAquestions.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 DSAquestions.c diff --git a/DSAquestions.c b/DSAquestions.c new file mode 100644 index 0000000..61cee1a --- /dev/null +++ b/DSAquestions.c @@ -0,0 +1,54 @@ +#include +#include + +struct Node +{ + int data; + struct Node *next; +}; + +void linkedListTraversal(struct Node *ptr) +{ + while (ptr != NULL) + { + printf("Element: %d\n", ptr->data); + ptr = ptr->next; + } +} + +int main() +{ + struct Node *head; + struct Node *second; + struct Node *third; + struct Node *fourth; + struct Node *Fifth ; + + // Allocate memory for nodes in the linked list in Heap + head = (struct Node *)malloc(sizeof(struct Node)); + second = (struct Node *)malloc(sizeof(struct Node)); + third = (struct Node *)malloc(sizeof(struct Node)); + fourth = (struct Node *)malloc(sizeof(struct Node)); +Fifth= ( struct Node *) malloc(sizeof(struct Node)); + + // Link first and second nodes + head->data = 7; + head->next = second; + + // Link second and third nodes + second->data = 11; + second->next = third; + + // Link third and fourth nodes + third->data = 41; + third->next = fourth; + + // Terminate the list at the third node + fourth->data = 66; + fourth->next =Fifth; +Fifth-> = 56; +Fifth->next=NULL; + + linkedListTraversal(head); + return 0; +}