-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlinkedlists.c
More file actions
56 lines (47 loc) · 922 Bytes
/
linkedlists.c
File metadata and controls
56 lines (47 loc) · 922 Bytes
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
54
55
56
#include <stdio.h>
#include <stdlib.h>
struct nod
{
int value;
struct node *next;
};
typedef struct nod node;
void printlist(node *head)
{
node *temp = head;
while (temp != NULL)
{
printf("%d -", temp->value);
temp = temp->next;
}
printf("\n");
}
node *insert_to_head(node **head, node *node_to_insert)
{
node_to_insert->next = *head;
*head = node_to_insert;
return node_to_insert;
}
void main()
{
//declaration of structure variables .
node n1, n2, n3;
node *head;
// values of nodes
n1.value = 21;
n2.value = 31;
n3.value = 41;
//link them up.
head = &n1;
n1.next = &n3;
n3.next = &n2;
n2.next = NULL;
printlist(head);
//adding new node
node n4;
n4.value = 100;
n4.next = &n3;
n1.next = &n4;
printlist(head);
return 0;
}