-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathADT_Linklist_node.c
49 lines (41 loc) · 1007 Bytes
/
ADT_Linklist_node.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
// author: jaydattpatel
#include <stdio.h>
#include <stdlib.h>
// Creating a node
struct node
{
int value;
struct node *next;
};
// print the linked list value
void printLinkedlist(struct node *p)
{
while (p != NULL)
{
printf("%d ", p->value); //print value of current structure data with pointer
p = p->next; //pointer will move to next address which stored in current p->next
}
}
int main() {
// Initialize nodes
struct node *head;
struct node *one = NULL;
struct node *two = NULL;
struct node *three = NULL;
// Allocate memory
one = malloc(sizeof(struct node));
two = malloc(sizeof(struct node));
three = malloc(sizeof(struct node));
// Assign value values
one->value = 15;
two->value = 26;
three->value = 37;
// Connect nodes
//store the address of next structure into variable pointer of current structure
one->next = two;
two->next = three;
three->next = NULL;
// printing node-value
head = one;
printLinkedlist(head);
}