Skip to content
/ List Public

My re-created version of C++'s std::list container

Notifications You must be signed in to change notification settings

veasman/List

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

List

FAQ

What is it?

It is my "version" of C++'s std::list container, which is a doubly-linked list.

Why did I make it?

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.

Usage

Installing

git clone https://github.com/veasman/List.git
mv List/header/*.hpp <YOUR_DISIRED_LOCATION>

Example

// 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
	}
}

Docs

Everything in the List class functions as it does in the built-in std::list class, but I'll explain anyways.

begin()

Returns an iterator of the first element (head) of the list.

end()

Returns an iterator of the last element (tail) in the list.

Front()

Returns the first element (head) of the list as type Node<ValueType>*.

Back()

Returns the last element (tail) of the list as type Node<ValueType>*.

PushFront(ValueType data)

Uses Insert(Iterator pos, ValueType data) to place a new node at the front of the list.

PopFront()

Removes the first element of the list, and returns the data from that element.

PushBack(ValueType data)

Uses Insert(Iterator pos, ValueType data) to place a new node at the end of the list.

PopBack()

Removes the last element from the list, and returns the data from that element.

Insert(Iterator pos, ValueType data)

Inserts data at the position of pos

Erase(Iterator pos)

Erases the node at pos

Resize(int size)

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.

Clear()

Resets the list to contain no data.

About

My re-created version of C++'s std::list container

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages