From 6d88b98a005f1465395f97b37320c108a9533b0d Mon Sep 17 00:00:00 2001 From: ArshitaKalra Date: Fri, 1 Oct 2021 02:27:06 +0530 Subject: [PATCH] linkedlist insert a number --- C/insertInLinkedl.c | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 C/insertInLinkedl.c diff --git a/C/insertInLinkedl.c b/C/insertInLinkedl.c new file mode 100644 index 0000000..676b800 --- /dev/null +++ b/C/insertInLinkedl.c @@ -0,0 +1,48 @@ +struct node +{ + int data; + struct node *next; +}; +struct node* head; +void Insert(int x) +{ + struct node * temp=(struct node*)malloc(sizeof(struct node)); + temp->data=x; + temp->next=0; + if(head!=0) + temp->next=head; + head=temp; + + +} +void Print() +{ + struct node* temp=head; + while (temp !=0) + { + printf("%d",temp->data); + temp=temp->next; + } +} +int main() +{ + struct node* one ; + + struct node *two; + struct node *three; + one=(struct node*)malloc(sizeof(struct node)); + two=(struct node*)malloc(sizeof(struct node)); + three=(struct node*)malloc(sizeof(struct node)); + head=one; + one->data=1; + two->data=2; + three->data=3; + one->next=two; + two->next=three; + three->next=0; + int x; + scanf("%d",&x); + //printf("%d %d %d %d",one->data,one->next->data,one->next->next->data,one); + Insert(x); + Print(); +}