Información

Autor(es) Maxime Mawait & Nicolas Rybowski
Fecha de entrega Sin fecha de envío
Tiempo límite de envío Sin límite de envío
Etiquetas de categoría S4, Level 4, Pointer, Linked list, Malloc, Struct

Etiquetas

Inicia sesión

[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.


Pregunta 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) {
Pregunta 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)) {