Repeated Elements in Doubly Linked List 2022 (Optional)


Time limit: 5000ms
Memory limit: 256mb

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

1. Insert an integer.
2. Find the numbers that appears for at least k times, where k >= 1, and print them in descending order.

The inputs are, sequentially:
1. the number of elements n in the list,
2. the n elements of the list (unsorted),
3. k 

You need to complete two functions.

List Insert(List p, int value);
Insert the value into doubly linked list p and return the updated head and tail pointers.
After insertion, the integers in p should still be in descending order.

List Find(List p, int k);
Find the numbers that appears for at least k times, and return them in descending order.

Sample Input 1:
7
1 7 4 10 4 5 5
2

Sample Output 1:
Input the number of integers inserted into the linked list:
Input these integers:
Input k:
5 4

Sample Input 2:
7
1 2 3 4 4 5 5
1

Sample Output 2:
Input the number of integers inserted into the linked list:
Input these integers:
Input k:
5 4 3 2 1


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

/*
I, <Your Full Name>, am submitting the assignment for
an individual project.
I declare that the assignment here submitted is original except for
source material explicitly acknowledged, the piece of work, or a part
of the piece of work has not been submitted for more than one purpose
(i.e. to satisfy the requirements in two different courses) without
declaration. I also acknowledge that I am aware of University policy
and regulations on honesty in academic work, and of the disciplinary
guidelines and procedures applicable to breaches of such policy and
regulations, as contained in the University website
http://www.cuhk.edu.hk/policy/academichonesty/.
It is also understood that assignments without a properly signed
declaration by the student concerned will not be graded by the
teacher(s).
*/

#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 *l)
{
    l->head = NULL;
    l->tail = NULL;
}

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

List Find(List l, int k)
{
    List out;
    // code here
    
    
    return out;
}

void Print_DESC(List l)
{
    // print all integers of list p in descending order
    Node* ptr = l.head;
    while(ptr!=NULL)
    {
        printf("%d ", ptr->value);
        ptr = ptr->next;
    }
    printf("\n");
}

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

    InitList(&p);
    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);
        p = Insert(p, value);
    }

    printf("Input k:\n");
    scanf("%d", &k);

    List out = Find(p, k);
    Print_DESC(out);
    return 0;
}




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

;
Submit