-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedlist.c
More file actions
118 lines (91 loc) · 2.42 KB
/
linkedlist.c
File metadata and controls
118 lines (91 loc) · 2.42 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*****************************************************
Linked lists using pointers in C
*****************************************************/
#include <stdio.h>
#include <stdlib.h>
/*****************************************************
Define structures of each node
*****************************************************/
struct nodes
{
int val;
struct nodes *next;
};
/*****************************************************
Function Declarations
*****************************************************/
void insopt(struct nodes *, struct nodes *);
/*****************************************************
Main Function
*****************************************************/
int main(int argc, char const *argv[])
{
struct nodes head;
struct nodes curr;
struct nodes *currptr;
currptr = &curr;
int opt = 999;
int insopt = 2;
int value ;
while (opt != '4')
{
printf("Enter the option from the menu below\n\n");
printf(" 1 : Insert a new node \n");
printf(" 2 : Delete an existing node \n");
printf(" 3 : Display the linked list \n");
printf(" 4 : Exit \n");
switch (opt)
{
case 1 :
printf("Enter value of node to be inserted \n>>>> ");
scanf("%d",&value);
curr.val = value;
insopt(&head,&curr);
break;
case 2 :
printf("Enter value of node to be deleted \n>>>> ");
break;
case 3 :
printf(" The linked list as follows \n>>>> ");
printf("%d",head.val);
currptr = head.next;
while (!currptr)
{
printf("%d",currptr->val);
currptr = head.next;
}
break;
case 4 :
printf("Exit");
break;
}
}
return 0;
}
/*****************************************************
Insert Function
*****************************************************/
void insopt(struct nodes *headptr, struct nodes *currptr)
{
int option;
printf("Enter the insert options from the menu below\n");
printf("1: Insert head node\n");
printf("2: Insert node after\n");
printf("3: Insert node before\n");
scanf("%d\n",&option );
switch (option) {
case 1:
if (!headptr)
{
headptr->val = currptr->val;
headptr->next = NULL;
}
else
{
headptr->next = headptr;
headptr->val = currptr->val;
headptr = currptr;
}
}
return;
}