diff --git a/include/linkedlist.h b/include/linkedlist.h index 24dbf58..c497993 100644 --- a/include/linkedlist.h +++ b/include/linkedlist.h @@ -8,11 +8,25 @@ #include #include +/** + * @brief Concept that ensures a type supports equality comparison via operator==. + * + * @tparam T Type to be checked. + */ template concept HasEqual = requires (T a, T b) { - {a == b} -> std::convertible_to; + { a == b } -> std::convertible_to; }; +/** + * @brief Concept defining the requirements for types supported by LinkedList. + * + * A valid type must: + * - Be formattable (usable with std::print / std::format) + * - Support equality comparison + * + * @tparam T Type to be checked. + */ template concept LinkedListSupported = std::formattable && @@ -21,141 +35,141 @@ concept LinkedListSupported = /** - * @brief Codigos de error para operaciones de LinkedList + * @brief Error codes for LinkedList operations. */ enum class LinkedListErr { - LINKEDLIST_OK, /**< Operacin exitosa */ - LINKEDLIST_BAD_ALLOC, /**< Error al asignar memoria */ - LINKEDLIST_OUT_OF_BOUNDS, /**< Índice fuera de rango */ - LINKESLIST_INVALID_SIZE, /**< Tamaño inválido */ - LINKEDLIST_NOT_FOUND, /**< Elemento no encontrado */ - LINKEDLIST_EMPTY, /**< La lista está vacia */ + LINKEDLIST_OK, /**< Operation completed successfully */ + LINKEDLIST_BAD_ALLOC, /**< Memory allocation failed */ + LINKEDLIST_OUT_OF_BOUNDS, /**< Index is out of valid range */ + LINKEDLIST_INVALID_SIZE, /**< Invalid size provided */ + LINKEDLIST_NOT_FOUND, /**< Element not found */ + LINKEDLIST_EMPTY, /**< The list is empty */ }; /** - * @brief Nodo de una lista enlazada - * - * @tparam T Tipo de dato almacenado en el nodo + * @brief Node of a singly linked list. + * + * @tparam T Type of data stored in the node. */ template class Node { public: - T data; /**< Dato almacenado en el nodo */ - Node *next; /**< Puntero al siguiente nodo */ + T data; /**< Data stored in the node */ + Node* next; /**< Pointer to the next node */ }; /** - * @brief Implementación de una lista enlazada simple - * - * Estructura de datos dinamica que almacena elementos de tipo T - * utilizando nodos enlazados mediante punteros. - * - * @tparam T Tipo de dato almacenado en la lista + * @brief Implementation of a singly linked list. + * + * A dynamic data structure that stores elements of type T + * using nodes connected via pointers. + * + * @tparam T Type of elements stored in the list. */ template class LinkedList { private: - size_t size; /**< Numero de elementos en la lista */ - Node *head; /**< Primer nodo de la lista */ - Node *tail; /**< Último nodo de la lista */ + size_t size; /**< Number of elements in the list */ + Node* head; /**< Pointer to the first node */ + Node* tail; /**< Pointer to the last node */ public: /** - * @brief Constructor de la lista enlazada + * @brief Constructs an empty linked list. */ LinkedList(); /** - * @brief Destructor de la lista - * - * Libera toda la memoria de los nodos. + * @brief Destroys the linked list. + * + * Releases all dynamically allocated nodes. */ ~LinkedList(); /** - * @brief Obtiene el elemento en una posicion específica - * - * @param index indice del elemento - * @return std::expected Valor encontrado o error + * @brief Retrieves the element at a given index. + * + * @param index Position of the element. + * @return std::expected The element or an error code. */ std::expected get(size_t index); /** - * @brief Inserta un elemento al final de la lista - * - * @param value Valor a insertar - * @return LinkedListErr Cdigo de estado de la operacion + * @brief Appends an element to the end of the list. + * + * @param value Value to insert. + * @return LinkedListErr Status code of the operation. */ LinkedListErr append(const T& value); /** - * @brief Inserta un elemento al inicio de la lista - * - * @param value Valor a insertar - * @return LinkedListErr Codigo de estado + * @brief Inserts an element at the beginning of the list. + * + * @param value Value to insert. + * @return LinkedListErr Status code of the operation. */ LinkedListErr prepend(const T& value); /** - * @brief Elimina y devuelve el ultimo elemento de la lista - * - * @return std::expected Elemento eliminado o error + * @brief Removes and returns the last element of the list. + * + * @return std::expected Removed element or an error. */ std::expected pop(); /** - * @brief Elimina el elemento en una posicion especifica - * - * @param index Indice del elemento a eliminar - * @return LinkedListErr Codigo de estado + * @brief Removes the element at a specific index. + * + * @param index Index of the element to remove. + * @return LinkedListErr Status code. */ LinkedListErr remove(size_t index); /** - * @brief Modifica el valor de un elemento en un indice - * - * @param index Índice del elemento - * @param value Nuevo valor - * @return LinkedListErr Código de estado + * @brief Updates the value of an element at a given index. + * + * @param index Index of the element. + * @param value New value. + * @return LinkedListErr Status code. */ LinkedListErr set(size_t index, const T& value); /** - * @brief Inserta un valor en el index dado. + * @brief Inserts a value at a specified index. * - * @param index Indice del elemento - * @param value Nuevo valor - * @return LinkedListErr Codigo de estado + * @param index Target position. + * @param value Value to insert. + * @return LinkedListErr Status code. */ - LinkedListErr insert (size_t index, const T& value); + LinkedListErr insert(size_t index, const T& value); /** - * @brief Busca un valor dentro de la lista - * - * @param value Valor a buscar - * @return std::expected Índice del elemento o error + * @brief Searches for a value in the list. + * + * @param value Value to search for. + * @return std::expected Index of the element or error. */ std::expected find(const T& value); /** - * @brief Imprime los elementos de la lista - * - * @return LinkedListErr Código de estado + * @brief Prints all elements in the list. + * + * @return LinkedListErr Status code. */ LinkedListErr print(); /** - * @brief Verifica si la lista esta vacia - * - * @return true si la lista no contiene elementos + * @brief Checks whether the list is empty. + * + * @return true if the list contains no elements, false otherwise. */ bool is_empty(); /** - * @brief Obtiene el numero de elementos de la lista - * - * @return size_t Tamaño de la lista + * @brief Returns the number of elements in the list. + * + * @return size_t Number of stored elements. */ size_t len(); };