From 37facce7f9d6ec6052158fb99898c49b48d0a8b9 Mon Sep 17 00:00:00 2001 From: Vaikuntram <95952585+Vaikuntram@users.noreply.github.com> Date: Tue, 24 Oct 2023 15:17:48 +0530 Subject: [PATCH] Update Linkedlist.c Includes user input --- C/Linkedlist.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/C/Linkedlist.c b/C/Linkedlist.c index 6668d32c..86947620 100644 --- a/C/Linkedlist.c +++ b/C/Linkedlist.c @@ -11,7 +11,7 @@ struct Node { //Complexity: O(n) where n = number of nodes void LLTraversal(struct Node* ptr){ while(ptr!=NULL){ - printf("%d\n", ptr->data); + printf("%d ", ptr->data); ptr = ptr->next; } } @@ -26,16 +26,24 @@ int main() third = (struct Node*)malloc(sizeof(struct Node)); fourth = (struct Node*)malloc(sizeof(struct Node)); - head->data = 7; + printf("Enter the first node's value: "); + scanf("%d",&head->data); + //head->data = 7; head->next = second; - second->data = 11; + printf("Enter the second node's value: "); + scanf("%d",&second->data); + //second->data = 11; second->next = third; - third->data = 66; + printf("Enter the third node's value: "); + scanf("%d",&third->data); + //third->data = 66; third->next = fourth; - fourth->data = 2; + printf("Enter the fourth node's value: "); + scanf("%d",&fourth->data); + //fourth->data = 2; fourth->next = NULL; LLTraversal(head);