Linked List Management 2022 (Required)

Time limit: 500ms
Memory limit: 256mb

Description:
In this exercise, you are required to maintain a linked list of sorted distinct integers in ascending order and support the following operations.

1.	Insert an integer to the linked list if it does not yet occur in the list. If already exist, do nothing. (Tips: before insertion, check whether the value to be inserted already exist)
2.	Delete an integer from the head of the linked list
3.	Delete an integer from the end of the linked list
4.	Delete an integer from the middle elemenmt of the linked list
5.  Delete all matching integers in a range (inclusive) from the linked list


The program performs Delete and Insert operations on the integers inputted.

The code template has been provided. Your task is to complete the following functions.

List Insert(List p, int value);
Firstly, check whether the value already exist in the list p, if not exist yet, do the insertion, do nothing otherwise.
Example:
insert 1 to 1 -> 2 -> 4 -> 5 -> 7
List will be something like: 1 -> 2 -> 4 -> 5 -> 7 (as 1 already exist)

insert 6 to 1 -> 2 -> 4 -> 5 -> 7
List will be something like: 1 -> 2 -> 4 -> 5 -> 6 -> 7

List Delete_a(List p);
Delete the node from the head of the linked list p. You could assume that the list is not empty.
Example:
Delete from the head of 1 -> 2 -> 4 -> 5 -> 6 -> 7
List will be something like: 2 -> 4 -> 5 -> 6 -> 7

List Delete_b(List p);
Delete the node from the end of the linked list p. You could assume that the list is not empty.
Example:
Delete from the end of 1 -> 2 -> 4 -> 5 -> 6 -> 7
List will be something like: 1 -> 2 -> 4 -> 5 -> 6

List Delete_c(List p);
Delete the node from the middle of the linked list p. You could assume that the list is not empty. If there are even number of integers, delete the FIRST middle element. (Tips: You can make use of the functions Num(List p) and MiddleIndex(List p) which returns the number of distinct values and the first middle index of the list)
Example:
Delete the FIRST middle integer (here, there are even number of integers, the FIRST middle integer is 4 and the SECOND middle integer is 5) from 1 -> 2 -> 4 -> 5 -> 6 -> 7
List will be something like: 1 -> 2 -> 5 -> 6 -> 7

Delete the middle integer from 1 -> 2 -> 5 -> 6 -> 7
List will be something like: 1 -> 2 -> 6 -> 7

List Delete_d(List p, int value_min, int value_max);
Delete all matching integers with values in a range (inclusive) from value_min to value_max from the linked list p. 
Example:
Let value_min=2, value_max=6, all matching integers with values not less than 2 (>= 2) and not greater than 6 (<= 6) will be deleted from 1 -> 2 -> 4 -> 5 -> 7 -> 8
List will be something like: 1 -> 7 -> 8

Let value_min=6, value_max=8, the integers with values not less than 6 (>= 6) and not greater than 8 (<= 8) will be deleted from 1 -> 2 -> 4 -> 5 -> 9 -> 10
List will be something like: 1 -> 2 -> 4 -> 5 -> 9 -> 10

Sample input
10
2 4 6 5 3 8 6 7 11 9
3 4

Sample output:
5 7 8 9

-------------------------Copy the following code, complete it and submit-------------------------

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef struct linked_list_node{
    int value;
    struct linked_list_node* next;
} Node;

typedef Node* List;

int Exist(List p, int value)
{
    // judge whether linked list p contains the value
    // you should visit each node of the linked list one by one, and check whether it is equal to the value
    // if you find it then return 1, otherwise return 0
    while(p!=NULL)
    {
        if(p->value==value) return 1;
        p = p->next;
    }
    return 0;
}

void Print(List p)
{
    // print all integers from the head of linked list in one line(separated by a space), in other words, you should firstly print the integer p points to
    // to be more specific, print p->value and then move p to the next node p->next recursively, until p points to NULL
    while(p!=NULL)
    {
        printf("%d ", p->value);
        p = p->next;
    }
    printf("\n");
}

int Num(List p){
    int num = 0;

    while(p!=NULL)
    {
        num = num + 1;
        p = p->next;
    }

    return num;
}

int MiddleIndex(List p){
    
}

List Delete_a(List p){
    
}

List Delete_b(List p){
    
}

List Delete_c(List p){
    
}

List Delete_d(List p, int value_min, int value_max){
    
}

List Insert(List p, int value)
{
    
}

int main()
{
    List p = NULL;
    int n, m;
    int value, value_min, value_max;

    // printf("List initialization: \n");
    // printf("How many integers in list initially: ");
    scanf("%d", &n);
    // printf("What are the integers: ");
    for(int i=0; i<n; i++)
    {
        int value;
        scanf("%d", &value);
        p = Insert(p, value);
    }

    // printf("Delete a value from head\n");
	p = Delete_a(p);

    // printf("Delete a value from end\n");
	p = Delete_b(p);

    // printf("Delete a value from first middle\n");
	p = Delete_c(p);

    scanf("%d%d", &value_min, &value_max);
    p = Delete_d(p, value_min, value_max);

    // printf("Current array: \n");
    Print(p);

    return 0;
}

-------------------------------------------End of Code-------------------------------------------

Submit