Doubly Linked List Maintenance

Time limit: 5000ms
Memory limit: 256mb

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

1.	Insert an integer.
2.	Find the position of an integer.
3.	Delete an integer.
4.	Print all integers in descending order.

The main function has been provided. It first asks the user to input the integers and invokes the Insert function to add the integers to the list.  Then it asks for a value that the user wants to find, and invokes the Find function to find the node that contains the value, and prints out the two values before and after the search value.  Finally it asks for a value for deletion, invokes the Delete function, and then prints the list in descending order via the Print_DESC function.

You need to complete four functions.

List Insert(List l, int value);
Insert the value into doubly linked list "l" and return the updated head and tail pointers.
You could assume that the "value" doesn't exist in "l" before insertion.
After insertion, the integers in "l" should still be in ascending order.

Node* Find(List l, int value);
Find the node which contains the "value" on the doubly linked list "l" and return its address.
You could assume that the "value" exists in "l".

List Delete(List l, int value);
Delete "value" from "l" and return the updated head and tail pointers.
You could assume that the "value" exists in "l" before deletion.
After deletion, the integers in "l" should still be in ascending order. 
To delete the "value", you may use the function Find to locate it fisrt.

void Print_DESC(List l);
Print all integers in descending order in one line. Every two integers are separated by a space.

Sample Input 1:
4
1 7 4 10
7
4

Sample Output 1:
Input the number of integers inserted into the linked list:
Input these integers:
Input the value to find:
4 7 10
Input the value for deletion:
10 7 1

Sample Input 2:
6
11 5 6 3 7 1
1
1

Sample Output 2:
Input the number of integers inserted into the linked list:
Input these integers:
Input the value to find:
NULL 1 3
Input the value for deletion:
11 7 6 5 3

Code Template:

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

typedef struct doubly_linked_list_node{
    int value;
    struct doubly_linked_list_node *prev, *next;
} Node;

typedef struct{
    Node *head; // point to the first node of doubly linked list
    Node *tail; // point to the last node of doubly linked list
} List;

void InitList(List *p)
{
    p->head = NULL;
    p->tail = NULL;
}

List Insert(List l, int value)
{
    //Insert the value into doubly linked list l and return the updated head and tail pointers.


    return l;
}

Node* Find(List l, int value)
{
    //Find the node which contains the value on the doubly linked list l and return its address.
    Node* ptr = l.head;


    return ptr;
}

List Delete(List l, int value)
{
    //Delete value from l and return the updated head and tail pointers.
    Node* ptr = Find(l, value);


    return l;
}

void Print_DESC(List l)
{
    // print all integers in descending order


}

int main()
{
    List l;
    int n;
    int value;
    Node* ptr;

    InitList(&l);
    printf("Input the number of integers inserted into the linked list:\n");
    scanf("%d", &n);
    printf("Input these integers:\n");
    for(int i=0; i<n; i++)
    {
        scanf("%d", &value);
        l = Insert(l, value);
    }

    printf("Input the value to find:\n"); // print the integers before and after the given value
    scanf("%d", &value);
    ptr = Find(l, value);
    if(ptr->prev!=NULL) printf("%d", ptr->prev->value);
    else printf("NULL");
    printf(" %d ", ptr->value);
    if(ptr->next!=NULL) printf("%d", ptr->next->value);
    else printf("NULL");
    printf("\n");

    printf("Input the value for deletion:\n");
    scanf("%d", &value);
    l = Delete(l, value);

    Print_DESC(l);
    return 0;
}

Submit