Skip to content

Latest commit

 

History

History

0x12-singly_linked_lists

0x12. C - Singly linked lists

Resources

Read or watch:

Learning Objectives

General

  • When and why using linked lists vs arrays
  • How to build and use linked lists

Tasks

0. Print list

  • Write a function that prints all the elements of a list_t list.

Requirements:

Prototype: size_t print_list(const list_t *h); Return: the number of nodes Format: see example If str is NULL, print [0] (nil) You are allowed to use printf

Mode: mandatory

File: 0-print_list.c


1. List length

  • Write a function that returns the number of elements in a linked list_t list.

Requirements:

Prototype: size_t list_len(const list_t *h);

Mode: mandatory

File: 1-list_len.c


2. Add node

  • Write a function that adds a new node at the beginning of a list_t list.

Requirements:

Prototype: list_t *add_node(list_t **head, const char *str); Return: the address of the new element, or NULL if it failed str needs to be duplicated You are allowed to use strdup

Mode: mandatory

File: 2-add_node.c


3. Add node at the end

  • Write a function that adds a new node at the end of a list_t list.

Requirements:

Prototype: list_t *add_node_end(list_t **head, const char *str); Return: the address of the new element, or NULL if it failed str needs to be duplicated You are allowed to use strdup

Mode: mandatory

File: 3-add_node_end.c


4. Free list

  • Write a function that frees a list_t list.

Requirements:

Prototype: void free_list(list_t *head);

Mode: mandatory

File: 4-free_list.c


5. The Hare and the Tortoise

Requirements:

You are allowed to use the printf function

Mode: #advanced

File: 100-first.c


6. Real programmers can write assembly code in any language

  • Write a 64-bit program in assembly that prints Hello, Holberton, followed by a new line.

Requirements:

You are only allowed to use the printf function You are not allowed to use interrupts Your program will be compiled using nasm and gcc:

Mode: #advanced

File: 101-hello_holberton.asm