A Doubly Linked List Library made with templates, smart pointers, std::containers and other C++14, C++11 coding conventions.
Features a main.cpp for testing the effect of the methods described below.
If you like to give it a try you can just simply include LinkedList.h
to your project.
-
fill()
: fills the list by appending its read element by the initializer_list provided. -
empty()
: returnstrue
if the list is empty,false
otherwise. -
length()
: returns anint
which holds the length of the list. -
append()
: appends the provided element at the end of the list. -
remove()
: Searchs and removes the provided element in any part of the list. -
search()
: Searchs the list for the provided element, if it's found 1 is returned, if not 0, if the list is empty -1 (error). -
print()
: prints the list in this format[ <element1> ... <elementN> ]
, where N is the order of insertion. -
reverse_ print()
: prints the list in this format[ <elementN> ... <element1> ]
, where N is the order of insertion.
Make a main.cpp, include the LinkedList.h and you can declare a DoublyLinkedList like this:
#include "LinkedList.h" //namespace is DLL for the list object in order to avoid conflict with other common implementations.
int main() {
DLL::LinkedList <int> list; //Create an empty list.
list.fill({1, 2, 3, 4, 5, 6, 7, 8, 9, 10}); //you could fill the list by appending iteratively.
DLL::LinkedList <bool> list2({true, false, false, true}); //same as filling list but with a constructor.
DLL::LinkedList <char> list3({'a', 'b', 'c'});
DLL::LinkedList <std::string> list4; //Empty list.
list4.append("Hello"); //You could fill it manually.
list4.append("World");
//...
return 0;
}
Compile using a -std=c++14
flag because of the make_unique()
call and other features that are used.
The testing is done with the catch library and the test's build with cmake, to run the the tests, use the following commands:
mkdir build # Make build folder for tests.
cd build
cmake .. # Run this command and the ones above just once.
make # Build tests / re-run make if the header files change.
./test/tests # Run all tests.
This library is not intended for commercial use, it's an experimental project for practical application of C++14 features.