|
DSA Hacking Club Library
|
A simple singly linked list implementation in C. More...
#include <stdio.h>
Go to the source code of this file.
Classes | |
| struct | node |
| A node in the singly linked list. More... | |
Typedefs | |
| typedef struct node | node_t |
| A node in the singly linked list. | |
Functions | |
| void | printlist (node_t *head) |
| Prints all the values in the linked list. | |
| node_t * | create_new_node (int value) |
| Creates a new node with a given integer value. | |
| node_t * | insert_at_head (node_t **head, node_t *node_to_insert) |
| Inserts a node at the head of the list. | |
| node_t * | find_node (node_t *head, int value) |
| Finds the first node with a given value. | |
| void | insert_after_node (node_t *node_to_insert_after, node_t *newnode) |
| Inserts a new node after a given node. | |
| void | free_list (node_t *head) |
| Frees all nodes in the linked list. | |
A simple singly linked list implementation in C.
This file provides the public interface for a linked list of integers. The list supports insertion, search, printing, memory management, and basic node operations.
A node in the singly linked list.
Each node stores an integer value and a pointer to the next node.
| node_t * create_new_node | ( | int | value | ) |
Creates a new node with a given integer value.
Allocates memory for a new node, sets its value, and initializes its next pointer to NULL.
| [in] | value | The integer value to store in the new node. |
Finds the first node with a given value.
Traverses the list to search for a node containing the specified value.
| [in] | head | Pointer to the head node of the list. |
| [in] | value | The integer value to search for. |
| void free_list | ( | node_t * | head | ) |
Frees all nodes in the linked list.
Iterates through the list, freeing each node’s allocated memory. After calling this function, the list is no longer valid.
| [in] | head | Pointer to the head node of the list. |
Inserts a new node after a given node.
Updates pointers so that the new node follows the specified node.
| [in] | node_to_insert_after | Pointer to the node after which to insert. |
| [in] | newnode | Pointer to the new node to insert. |
Inserts a node at the head of the list.
Updates the head pointer to point to the new node.
| [in,out] | head | Pointer to the head pointer of the list. |
| [in] | node_to_insert | Pointer to the node to insert. |
| void printlist | ( | node_t * | head | ) |
Prints all the values in the linked list.
Iterates from the head of the list to the end, printing each value.
| [in] | head | Pointer to the head node of the list. |