It is my "version" of C++'s std::list container, which is a doubly-linked list.
We are going through linked lists in my class, and I'm not allowed to use C++'s built-in std::list, but I am allowed to use this.
git clone https://github.com/veasman/List.git
mv List/header/*.hpp <YOUR_DISIRED_LOCATION>
// main.cpp
#include <iostream>
#include "list.hpp"
int main() {
List<int> myList = { 0, 1, 3 };
myList.PushBack(4);
List<int>::Iterator itr = myList.begin();
itr++;
myList.Insert(itr, 2);
for (const auto& num : myList) {
std::cout << num << std::endl;
// Expected output:
// 0
// 1
// 2
// 3
// 4
}
}
Everything in the List class functions as it does in the built-in std::list class, but I'll explain anyways.
Returns an iterator of the first element (head) of the list.
Returns an iterator of the last element (tail) in the list.
Returns the first element (head) of the list as type Node<ValueType>*.
Returns the last element (tail) of the list as type Node<ValueType>*.
Uses Insert(Iterator pos, ValueType data)
to place a new node at the front of the list.
Removes the first element of the list, and returns the data from that element.
Uses Insert(Iterator pos, ValueType data)
to place a new node at the end of the list.
Removes the last element from the list, and returns the data from that element.
Inserts data
at the position of pos
Erases the node at pos
If size
is less than the list's current size, it will add new nodes with data
as 0
until the size is fully adjusted.
If size
is greater than or equal to the list's current size, PopBack
will be called until the size is fully adjusted.
Resets the list to contain no data.