LinkedList: Doubly Linked List

LinkedList is a standard template-based implementation of a doubly-linked list. It provides efficient insertion and deletion at both ends and supports bi-directional iteration.

Characteristics

LinkedList is suitable for collections where frequent insertions and removals are expected, especially at the beginning or end of the sequence.

Usage Example

#include "ds/LinkedList.h"
#include <iostream>

void listExample() {
    LinkedList<int> list;

    // Adding elements
    list.add(10);
    list.add(20);
    list.insertAtBeginning(5);

    // Iterating with standard loops
    for (int value : list) {
        std::cout << value << " ";
    }
    std::cout << std::endl;

    // Removing elements
    list.remove(1); // Removes element at index 1
}

API Reference

Constructors and Destructor

Insertion and Removal

Access and Cursor Management

Iterators

The class provides standard begin(), end(), cbegin(), cend(), rbegin(), and rend() methods returning appropriate iterator types.


Usage Notes

LinkedList manages a sequence of nodes, where each node is an instance of linkedlist_value_container_t.

Index-Based Access

While LinkedList supports index-based access via get(int i) and remove(int i), these operations are O(N) as they require traversing the list from either the head or the tail (depending on which is closer) to reach the target index. For heavy index-based workloads, ArrayList would be a more appropriate choice.