0

How to print the data part of a Linked List

I am trying to print the data part of a linked list but when whenever i run my program there is no output. #include<stdio.h> #include <stdlib.h> main() { struct node { int data; struct node *link; }; node* head=NULL; node* temp=(struct node*)malloc(sizeof(struct node)); temp->data=2; temp->link=NULL; head=temp; temp=(struct node*)malloc(sizeof(struct node)); temp->data=4; temp->link=NULL; node* temp1=head; while(temp1->link!=NULL) { temp1=temp1->link; printf("%d",temp1->data); } temp1->link=temp; }

2nd Oct 2020, 4:57 PM
Ravi anshuman
Ravi anshuman - avatar
1 Answer
0
codemonkey what if i want to add that 2nd node at the end position.
2nd Oct 2020, 7:20 PM
Ravi anshuman
Ravi anshuman - avatar