forked from DHEERAJHARODE/Hacktoberfest2024-Open-source-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathList.c
44 lines (33 loc) · 825 Bytes
/
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
#include <stdio.h>
#include <stdlib.h>
struct Node{
int data;
struct Node* next;
};
void displayList(struct Node* n){
while(n != NULL){
printf("%d ", n->data);
n = n->next;
}
printf("\n");
}
int main(){
struct Node* head = NULL;
struct Node* second = NULL;
struct Node* third = NULL;
struct Node* fourth = NULL;
head = (struct Node*)malloc(sizeof(struct Node));
second = (struct Node*)malloc(sizeof(struct Node));
third = (struct Node*)malloc(sizeof(struct Node));
fourth = (struct Node*)malloc(sizeof(struct Node));
head->data = 10;
head->next = second;
second->data = 20;
second->next = third;
third->data = 30;
third->next = fourth;
fourth->data = 40;
fourth->next = NULL;
displayList(head);
return 0;
}