Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/paramsiddharth/linked-list-cpp
A fully-functional implementation of a linked list in C++.
https://github.com/paramsiddharth/linked-list-cpp
Last synced: about 1 month ago
JSON representation
A fully-functional implementation of a linked list in C++.
- Host: GitHub
- URL: https://github.com/paramsiddharth/linked-list-cpp
- Owner: paramsiddharth
- Created: 2020-11-02T09:44:57.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2020-11-09T08:06:25.000Z (about 4 years ago)
- Last Synced: 2024-05-22T20:22:04.580Z (7 months ago)
- Language: C++
- Size: 798 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Linked List
A fully-functional implementation of a linked list in C++.## Usage
The header file `linked_list` may simply be included to access `Param::List`.
``` cpp
#include "linked_list"
```
### `Param::Node`
This class represents the individual nodes in a list.#### Constructor
``` cpp
Param::Node::Node(T info = 0, Node NEXT = nullptr)
```
Accepts a value for the data (of typename/class `T`) stored in the node, and a pointer for the next node if any.#### Attributes
- `T Param::Node::INFO` : The data stored in the node.
- `Param::Node* Param::Node::NEXT` : The pointer to the next node, or `nullptr` if absent.### `Param::List`
This class represents linked lists.#### Constructor
``` cpp
Param::List::List(Node* HEAD = nullptr)
```
Accepts an existing `HEAD` node (of typename/class `T`) to be used in the linked list.#### Destructor
``` cpp
Param::List::~List()
```
Properly cleans up the dynamically allocated memory previously occupied by the list.#### Attribute(s)
- `Node* Param::List::HEAD` : Stores a pointer to the first node, or `nullptr` if the list is empty. It is a private attribute i. e. Not directly accessible.#### Methods
- `bool Param::List::isEmpty()` : Check if the list is empty.
- `void Param::List::insertEnd(T info)` : Insert a new node at the end of the list with data `info`.
- `void Param::List::deleteEnd()` : Delete the last node in the list.
- `void Param::List::insertBeginning(T info)` : Insert a new node at the beginning of the list with data `info`.
- `void Param::List::deleteBeginning()` : Delete the first node in the list.
- `void Param::List::insertIndex(int index), T info` : Insert `info` at index `index`.
- `void Param::List::deleteIndex(int index)` : Delete the node at index `index`.
- `T& Param::List::getIndex(int index)` : Get a reference to the `INFO` of the node at index `index`. If absent, a new node is automatically created, so accessing invalid indices. A reference is returned to allow assignment.
- `T& Param::List::operator [](int index)` : Same as `T& getIndex(int index)`.
- `int Param::List::size()` : Returns the number of nodes currently in the list.
- `void Param::List::show()` : Displays the list into the console as follows
```
< 1 2 3 ... n >
```
Where 1, 2, 3, ..., n are the values stored in each of the nodes in the list.## Testing
Run `make test` using GNU Make.
``` bash
make test
```
![Test output](docs/test.png)## Made with ❤ by Param.