-
Notifications
You must be signed in to change notification settings - Fork 0
/
retrial-linked.c
54 lines (38 loc) · 915 Bytes
/
retrial-linked.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
52
53
/* */
#include <stdlib.h>
#include <stdio.h>
struct Node
{
int age;
struct Node * next;
};
int main()
{
struct Node *first = NULL;
struct Node *second = NULL;
struct Node *third = NULL;
/* Adding new node to start of Linked List */
struct Node *new_node = NULL;
first = (struct Node *)malloc(sizeof(struct Node*));
second = (struct Node *)malloc(sizeof(struct Node*));
third = (struct Node *)malloc(sizeof(struct Node*));
new_node = (struct Node *)malloc(sizeof(struct Node *));
/* Assigning data to the node */
first->age = 30;
first->next = second;
second->age = 40;
second->next = third;
third->age = 15;
third->next = NULL;
new_node->age = 25;
new_node->next = first;
/* Updating the head to equal to new node */
first = new_node;
/* Print the nodes of a linked list */
while (first != NULL)
{
printf("%d\n", first->age);
first = first->next;
}
return (0);
}