Linked list management 2021 (Required)

Time limit: 500ms
Memory limit: 256mb

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

1.	Get the number of distinct integers in the linked list
2.	Delete a value from the head of the linked list
3.	Delete a value from the end of the linked list
4.	Delete a value from the middle elemenmt of the linked list
5.	Insert a value 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)

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.

int Num(List p);
Return the number of elements in the linked list. You could assume that the list is not empty.
Example:
The number of elements in linked list 5 -> 4 -> 3 -> 2 -> 1 is 5.

void 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 5 -> 4 -> 3 -> 2 -> 1
List will be something like: 4 -> 3 -> 2 -> 1

void 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 5 -> 4 -> 3 -> 2 -> 1
List will be something like: 5 -> 4 -> 3 -> 2

void 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 elements, delete the second middle element.
Example:
Delete from 5 -> 4 -> 3 -> 2 -> 1
List will be something like: 5 -> 4 -> 2 -> 1

Delete from 5 -> 4 -> 2 -> 1
List will be something like: 5 -> 4 -> 1

void 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 5 -> 4 -> 3 -> 2 -> 1
List will be something like: 5 -> 4 -> 3 -> 2 -> 1 (as 1 already exist)

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

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

Sample output:
9 8 7 5 4 3

-------------------------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 MiddleIndex(List p){
	// the indices of a length-n linked list are 0, 1, ..., (n-1)
    return floor((float)Num(p)/2);
}

List Delete_a(List p){
}

List Delete_b(List p){
}

List Delete_c(List p){
    int index = MiddleIndex(p);
}

List Insert(List p, int value){
}

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

    // 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 middle\n");
	p = Delete_c(p);

    // printf("Current list: \n");
    Print(p);
    return 0;
}

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