https://github.com/dxrzc/list-data-structure-cpp
Low level circular doubly linked list data structure in C++
https://github.com/dxrzc/list-data-structure-cpp
cmake cpp20 data-structures googletest
Last synced: about 1 year ago
JSON representation
Low level circular doubly linked list data structure in C++
- Host: GitHub
- URL: https://github.com/dxrzc/list-data-structure-cpp
- Owner: dxrzc
- Created: 2024-11-01T17:35:05.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-02T02:32:44.000Z (about 1 year ago)
- Last Synced: 2025-03-02T03:23:43.995Z (about 1 year ago)
- Topics: cmake, cpp20, data-structures, googletest
- Language: C++
- Homepage:
- Size: 173 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
README
# List Data Structure
Low-level circular doubly linked list data structure with a header node in C++.

## Features
- Flexible Header Construction - This data structure can be instantiated even if the template argument does not have a default constructor
- Iterator class – Standard iterator for list traversal.
- Reverse iterator class – Traverse the list in reverse order.
- Const reverse iterator class – Immutable reverse iteration.
- std::advance and foreach support when working with iterators
- Movement semantic – Efficient resource transfer between lists.
- Emplace elements – Construct elements directly in the list using arguments.
- Reverse the list - Invert the order of the elements.
- Sort the list - Sort elements using the QuickSort algorithm.
- Splice the list into another list - Transfer elements from one list to another.
- Remove elements conditionally – Remove elements based on a condition (remove_if).
- Find element and return iterator to the cell – Locate elements and return an iterator to them.
- And more...
## Build and run tests
```
git clone https://github.com/dxrzc/list-data-structure-cpp.git
cd list-data-structure-cpp
mkdir build
cd build
cmake ..
cmake --build .
```
Run tests with CTest
```
ctest
```
Or run the executable manually
```
cd Debug
./testing
```
## Usage
Copy the list.h file into your project and include it. For example:
```
#include "list.h"
class Resource
{
private:
std::string test_string;
int test_int;
public:
// default constructor deleted
Resource() = delete;
Resource(const std::string& test_string, int test_int)
: test_string(test_string), test_int(test_int) {}
friend std::ostream& operator<<(std::ostream& os, const Resource& res)
{
os << res.test_string << ' ' << res.test_int << '\n';
return os;
}
};
int main()
{
list resources_list;
// create and insert a resource
Resource test_resource ("test string 0", 0);
resources_list.push_back(test_resource);
// create a resource directly in the list
resources_list.emplace_back("test string 1", 1);
for (const Resource& res : resources_list)
std::cout << res;
}
```
Output:
```
test string 0 0
test string 1 1
```