Repository navigation
Expand file tree
/
Copy pathlinked_list.h
More file actions
86 lines (73 loc) · 2.09 KB
/
Copy pathlinked_list.h
File metadata and controls
86 lines (73 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* @file linked_list.h
* @brief Singly Linked List data structure implementation.
*
* Part of the C Learning & DSA Toolkit.
*/
#ifndef LINKED_LIST_H
#define LINKED_LIST_H
#include <stdbool.h>
/**
* @brief Node in a singly linked list.
*/
typedef struct Node {
int data;
struct Node *next;
} Node;
/**
* @brief Singly linked list container tracking head pointer and node count.
*/
typedef struct {
Node *head;
int count;
} LinkedList;
/**
* @brief Initializes an empty linked list.
* @param list Pointer to LinkedList.
*/
void list_init(LinkedList *list);
/**
* @brief Inserts a new node at the beginning of the list.
* @param list Pointer to LinkedList.
* @param value Integer value to insert.
* @return true if memory allocation succeeded, false otherwise.
*/
bool list_insert_beginning(LinkedList *list, int value);
/**
* @brief Inserts a new node at the end of the list.
* @param list Pointer to LinkedList.
* @param value Integer value to insert.
* @return true if memory allocation succeeded, false otherwise.
*/
bool list_insert_end(LinkedList *list, int value);
/**
* @brief Deletes the first node containing the specified value.
* @param list Pointer to LinkedList.
* @param value Value to remove.
* @return true if node was found and removed, false if not found.
*/
bool list_delete_value(LinkedList *list, int value);
/**
* @brief Searches for a value in the list.
* @param list Pointer to LinkedList.
* @param value Value to search for.
* @return 0-based index of first occurrence, or -1 if not found.
*/
int list_search(const LinkedList *list, int value);
/**
* @brief Returns the total number of nodes in the list.
* @param list Pointer to LinkedList.
* @return Node count.
*/
int list_count(const LinkedList *list);
/**
* @brief Prints the linked list elements in order (e.g. 10 -> 20 -> 30 -> NULL).
* @param list Pointer to LinkedList.
*/
void list_display(const LinkedList *list);
/**
* @brief Frees all nodes in the linked list and resets it to empty.
* @param list Pointer to LinkedList.
*/
void list_free(LinkedList *list);
#endif /* LINKED_LIST_H */