Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/yeremyacuna/LYNX/llms.txt

Use this file to discover all available pages before exploring further.

LinkedList<T> is LYNX’s general-purpose sequential container, defined in include/LinkedList.h. It is built from Node<T> nodes linked in a single forward direction, with dedicated head and tail pointers that keep both front and back insertions at O(1). Throughout the LYNX system, LinkedList<T> serves as the backbone of AuthManager, where it holds the registered passenger and driver rosters. Beyond the standard structural operations, the class exposes three lambda-powered methods — forEach, filter, and findFirst — that let callers express iteration and search logic inline without writing explicit traversal loops. Two additional methods, toArray and fromArray, bridge the linked list to raw C-style arrays for use with AdvancedSorts.

Private Members

MemberTypeRole
headNode<T>*Points to the first node; nullptr when the list is empty
tailNode<T>*Points to the last node; enables O(1) pushBack without traversal
sizeintTracks the current element count; used by bounds-checking and getSize()

Method Reference

MethodSignatureDescriptionComplexity
pushFrontvoid pushFront(T value)Inserts a new node before the current headO(1)
pushBackvoid pushBack(T value)Appends a new node after the current tailO(1)
insertvoid insert(int index, T value)Inserts at an arbitrary index; delegates to pushFront/pushBack at the boundariesO(n)
popFrontvoid popFront()Removes and deletes the head nodeO(1)
popBackvoid popBack()Removes and deletes the tail node; requires traversal to find the new tailO(n)
removevoid remove(int index)Removes the node at the given index; delegates at boundariesO(n)
getT get(int index) constReturns the value at the given index; returns T{} on out-of-rangeO(n)
frontT front() constReturns the head value without removing itO(1)
backT back()Returns the tail value without removing itO(1)
searchint search(T value)Returns the index of the first matching element, or -1O(n)
containsbool contains(T value)Returns true if search finds the valueO(n)
countint count(T value)Counts all nodes whose data == valueO(n)
reversevoid reverse()Reverses the list in-place by re-wiring next pointersO(n)
clearvoid clear()Deletes all nodes and resets head, tail, and sizeO(n)
printvoid print()Prints the chain as [ a -> b -> nullptr ] to stdoutO(n)
printInfovoid printInfo()Prints size, head->data, and tail->data as a one-linerO(1)
isEmptybool isEmpty() constReturns true when size == 0O(1)
getSizeint getSize()Returns the current element countO(1)
forEachvoid forEach(function&lt;void(T)&gt; accion)Calls accion on every element’s dataO(n)
filterLinkedList&lt;T&gt;* filter(function&lt;bool(T)&gt; criterio)Returns a new heap-allocated list of elements satisfying criterioO(n)
findFirstT findFirst(function&lt;bool(T)&gt; criterio)Returns the first element satisfying criterio, or T{}O(n)
toArrayT* toArray() constExports all elements to a heap-allocated C-array; caller must delete[]O(n)
fromArrayvoid fromArray(T* arr, int n)Clears the list and rebuilds it from arr[0..n-1]O(n)

Complexity Summary

OperationTime Complexity
pushFrontO(1)
pushBackO(1)
front / backO(1)
insertO(n)
getO(n)
searchO(n)
popBackO(n)
reverseO(n)

Lambda Methods

LYNX uses lambdas with LinkedList<T> to keep traversal logic co-located with the call site rather than scattered across helper functions. All three methods accept std::function objects, so standard lambdas, function pointers, and capturing closures all work.

forEach — Iterate Every Element

void forEach(function<void(T)> accion)
Walks every node from head to nullptr and calls accion on each element’s data. No elements are modified or removed. Ideal for printing, logging, or accumulating external state.
// Print every driver's name to the console
drivers.forEach([](Driver d) {
    cout << d.getName() << "\n";
});

filter — Build a Filtered Sub-List

LinkedList<T>* filter(function<bool(T)> criterio)
Creates a new LinkedList<T> on the heap containing only the elements for which criterio returns true. The original list is untouched. The caller is responsible for deleting the returned pointer when done.
// Get only drivers who are currently available
LinkedList<Driver>* available = drivers.filter([](Driver d) {
    return d.getIsAvailable();
});
// ... use available ...
delete available; // caller owns the result

findFirst — Locate One Element

T findFirst(function<bool(T)> criterio)
Returns the data of the first node for which criterio returns true. If no match exists, returns a value-initialized T{}. Used in AuthManager to look up a passenger by DNI without exposing internal iteration.
// Find the passenger whose DNI matches the input
Passenger p = passengers.findFirst([&](Passenger p) {
    return p.getDni() == dni;
});

Array Interop

toArray() and fromArray() exist to bridge LinkedList<T> with the AdvancedSorts utilities, which operate on raw C-style arrays rather than linked nodes.
// Export to array, sort, then reload
T* arr = myList.toArray();
AdvancedSorts::mergeSort(arr, myList.getSize());
myList.fromArray(arr, myList.getSize());
delete[] arr; // caller must free the array
toArray() allocates memory with new T[] and returns nullptr if the list is empty. Always check the return value and call delete[] once you are done with the array — the list does not track or free it.

Usage Example

LinkedList<Driver> drivers;
drivers.pushBack(Driver("Juan", "12345678", "pass", v));
drivers.pushBack(Driver("Ana",  "87654321", "pass", v));

// Find first available driver
Driver best = drivers.findFirst([](Driver d) {
    return d.getIsAvailable();
});

// Filter available drivers into a new list
LinkedList<Driver>* available = drivers.filter([](Driver d) {
    return d.getIsAvailable();
});
delete available; // caller owns the result

Build docs developers (and LLMs) love