This project implements a Singly Linked List in C++ as part of my Learning Journey.
It’s written with detailed comments and educational explanations — for learners to follow easily, and for recruiters to see my ability to write clean, well-documented, and modular C++ code.
A linked list is a linear data structure where each element, called a node, contains:
- data — the stored value
- next — a pointer to the next node
[HEAD] → [10 | *] → [20 | *] → [30 | NULL]
Each arrow (→
) represents a pointer connecting one node to the next.
A list with two elements can be visualized like this:
Node* Node Node
+------+ +-----+ +-----+
| head |-->|value| +-->|value|
+------+ +-----+ | +-----+
|next |--+ |next |-->nullptr
+-----+ +-----+
The Pointer "head" here points to the fisrts element of linked list. because we don't want to loose the head our chain in the memory!
Concept | Description |
---|---|
Dynamic Memory | Linked lists grow and shrink at runtime — no fixed size like arrays. |
Efficient Insertion/Deletion | Inserting or deleting nodes doesn’t require shifting elements. |
Foundation for Other Structures | Stacks, Queues, Graphs, and Hash Tables often use linked lists internally. |
Stacks, Queues, Graphs, etc... like vectors are containers to save data in in a progamming languages like C++.
This SinglyLinkedList
class supports the following operations:
Operation | Description | Time Complexity |
---|---|---|
push_front(value) |
Insert a node at the beginning | O(1) |
push_back(value) |
Insert a node at the end | O(n) |
at(index) |
Return the value of the element located in a a specific position | |
insert_at(index, value) |
Insert a node at a specific position | O(n) |
pop_front() |
Delete the first node | O(1) |
pop_back() |
Delete the last node | O(n) |
remove_at(index) |
Delete a node by index | O(n) |
size() |
Return the number of nodes | O(n) |
File | Description |
---|---|
singly_linked_list.hpp |
Header file with class definition |
singly_linked_list.cpp |
Implementation with detailed comments |
main.cpp |
Demonstration program |
You can build the demo with any C++ compiler:
g++ main.cpp singly_linked_list.cpp -o linked_list
./linked_list
-
This implementation focuses on:
-
Understanding pointer logic
-
Practicing memory management (new / delete)
-
Writing clear, documented code
-
Following object-oriented design principles
-
Add these methods:
- search(value)
- print()
- clear()
- reverse()
-
Implement a DoublyLinkedList class
-
Visualize the list structure with ASCII diagrams
-
Create unit tests for each method
-
Convert Node class to Template class
-
Error handling and using informational errors
👨💻 Author
Habib Mote Student at 42 Berlin