[S3] Simple linked list

We ask you to write two simple functions that are needed to implement a simple linked list.

/**
* Structure node
*
* @next: pointer to the next node in the list, NULL if last node_t
* @value: value stored in the node
*/
typedef struct node {
  struct node *next;
  int value;
} node_t;

/**
* Structure list
*
* @first: first node of the list, NULL if list is empty
* @size: number of nodes in the list
*/
typedef struct list {
  struct node *first;
  int size;
} list_t;

In your functions, you cannot use the function calloc(3)


Question 1: Node initialisation
/*
* Create a new node containing the value @value.
*
* @value: value stored in the node
* @return: returns the pointer to the newly created node, or NULL if an error occured.
*/
node_t *init_node(int value) {
Question 2: Adding a node
/*
* Add a node at the head of the list @list and increment the number of nodes in the list (member `size`)
*
* @l: linked list
* @value: value to add to the list
*
* @return: 0 if success, 1 otherwise
*/
int add_node(list_t *list, int value);

Information

Author(s) Maxime Mawait & Nicolas Rybowski
Deadline No deadline
Submission limit No limitation
Category Tags S3, Data structures, Malloc

Tags

Sign in