1typedef struct node{
2 int value; //this is the value the node stores
3 struct node *next; //this is the node the current node points to. this is how the nodes link
4}node;
5
6node *rmvNode(node *head, int index){
7 node *tmp = head;
8 node *rmv;
9 int count = 0;
10
11 //base case for if the user enters a value greater then or equal to the length of the head
12 //base case for if the user enters a value with a list of length 1. because in this library a list MUST contain one value minimum
13 if(index >= len(head) || len(head) == 1){
14 return NULL;
15 }
16
17 //if you want to remove the first value
18 if(index == 0){
19 rmv = head; //stores the head at this given moment in time
20 head = tmp->next; //this jumps the position of the head making sure that the beginning is no longer part of the head
21 free(rmv); //this frees the memory given to the initial head
22 return head;
23 }
24
25 //if you want to remove index position 1
26 if(index == 1){
27 rmv = head->next;
28 head->next = tmp->next->next;
29 free(rmv);
30 return head;
31 }
32
33 //if you want to remove the last value
34 if(index == -1){
35
36 while(count < len(head)-2){ //we do -2 because we want to access the node before the last one
37 tmp = tmp->next;
38 count += 1;
39 }
40 rmv = tmp->next;
41 tmp->next = NULL;
42 free(rmv);
43 return head;
44 }
45
46 //remove anything else
47 while(count < index-1){
48 tmp = tmp->next;
49 count += 1;
50 }
51 rmv = tmp->next;
52 tmp->next = tmp->next->next;
53 free(rmv);
54 return head;
55
56}