-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinked_list.c
More file actions
executable file
·85 lines (73 loc) · 1.47 KB
/
linked_list.c
File metadata and controls
executable file
·85 lines (73 loc) · 1.47 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int value;
struct node *next;
} node_t;
void display(node_t *head);
void Initialize();
void add(node_t *head);
node_t * head = NULL;
void Initialize(){
head = malloc(sizeof(node_t));
if (head == NULL){
printf("invalid!!\n");;
}
int val;
printf("Enter value for head : ");
scanf("%d",&val);
head->value = val;
head->next == NULL;
}
void add(node_t *head){
node_t *current = head;
int i =1;
while(current->next != NULL){
current = current->next;
}
node_t * next_node = NULL;
next_node = malloc(sizeof(node_t));
current->next = next_node;
printf("Enter value for new entry: ");
scanf("%d", &next_node->value);
next_node->next = NULL;
printf("\nafter modifying\n");
display(head);
}
void display(node_t *head){
node_t *current = head;
int i=1;
while(current != NULL){
printf("(%d,%d)\n",i, current->value);
current=current->next;
++i;
}
}
void pushAtStart(node_t **head){
node_t *current;
current = malloc(sizeof(node_t));
printf("Enter value for new head: ");
scanf("%d",¤t->value);
current->next= *head;
*head = current;
display(*head);
}
void pullFromFirst(node_t **head){
node_t *current = NULL;
if(head == NULL){
printf("Nothing to delete!!\n");
}
current = (*head)->next;
free(*head);
*head = current;
printf("After pulling...\n");
}
void main(){
Initialize();
display(head);
add(head);
pushAtStart(&head);
pullFromFirst(&head);
display(head);
}