Skip to content

Commit 0fa2382

Browse files
Linked list traversal
Here I have coded How to traverse a singly linked list, and also how to display using pointer concepts.
1 parent c5c05c2 commit 0fa2382

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

Linked List traversal

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include<stdio.h>
2+
#include<conio.h>
3+
4+
5+
void main()
6+
struct node
7+
{
8+
int data;
9+
struct node *next;
10+
};
11+
12+
struct node *head,*newnode,*temp;
13+
14+
head=0,temp=0;
15+
16+
int choice;
17+
18+
while (choice){
19+
newnode = (struct node*)malloc(sizeof(struct node))
20+
21+
printf("Enter data")
22+
23+
scanf("%d",&newnode->data);
24+
newnode->next=0;
25+
26+
if(head==0)
27+
{
28+
head=temp=newnode;
29+
}
30+
else
31+
{
32+
temp->next=newnode;
33+
temp=newnode;
34+
}
35+
36+
printf("Do you want to continue (0,1)?");
37+
scanf("%d",&choice);
38+
39+
/////////////////displaying///////////////
40+
41+
42+
temp=head;
43+
while(temp!=0)
44+
{
45+
printf("%d",temp->data);
46+
temp=temp->next;
47+
}
48+
getch();
49+
50+
}
51+
52+
53+
54+

0 commit comments

Comments
 (0)