forked from Unknown-hunk/TEJAS_C
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinked_list.c
51 lines (43 loc) · 959 Bytes
/
Linked_list.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<stdio.h>
//Structure for Linked List Node
struct node
{
int nData;
struct node* pLink;
};
//Function to display Linked List
void displayLL(struct node* p)
{
printf("Display The Link List:\n");
if(p)
{
do
{
printf(" %d", p->nData);
p=p->pLink;
}
while(p);
}
else
printf("Linked List is empty.");
}
int main()
{
struct node* pNode1= NULL;
struct node* pNode2= NULL;
struct node* pNode3= NULL;
//create node and assign data value
pNode1 = (struct node *)malloc(sizeof(struct node *));
pNode1->nData =10;
pNode2 = (struct node *)malloc(sizeof(struct node *));
pNode2->nData =20;
pNode3 = (struct node *)malloc(sizeof(struct node *));
pNode3->nData =30;
//connecting nodes
pNode1->pLink = pNode2;
pNode2->pLink = pNode3;
pNode3->pLink = NULL;
//Display Linked List if first node is not null
if(pNode1)
displayLL(pNode1);
}