מידע

יוצרים Maxime Mawait & Nicolas Rybowski
מועד הגשה אין מועד הגשה
מגבלת הגשות אין הגבלה
תגיות קטגוריה s4, level4, category_pointer, category_linked_list, category_malloc, category_struct

תגיות

כניסה

[S4] Ordered linked list

Given the provided implementation of a linked list, you need to implement the insert function based on a specific order relation. The goal is to implement an ordered list similar to a LinkedList with a Comparator in Java.


שאלה 1: Order relation

For this subproblem, you need to implement the comparison function which defines the order relationship of the list.

Write the body of the function compare.

/*
* @return: 0 if equals, negative number if @b is greater,
* and positive number otherwise
*/
int compare(char a, char b) {
שאלה 2: Insert

Assuming following linked list structure :

typedef struct node{
    char val;
    struct node *next;
} node_t;

Write the body of the function insert

/*
* @value: value to be inserted. If the value is already in the list, no element is added and the list is not modified
* @fun: comparison function which defines the order relationship of the list
* @head: first node of the list, head != NULL
* @return: 0 if success, -1 otherwise
*/
int insert(node_t **head, char val, int (*cmp)(char,char)) {