https://github.com/stageguard/datastructurecurriculumdesign
Data structure curriculum design for term 1 grade 2.
https://github.com/stageguard/datastructurecurriculumdesign
Last synced: 10 months ago
JSON representation
Data structure curriculum design for term 1 grade 2.
- Host: GitHub
- URL: https://github.com/stageguard/datastructurecurriculumdesign
- Owner: StageGuard
- License: gpl-3.0
- Created: 2021-12-25T06:54:28.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-12-25T07:11:09.000Z (over 4 years ago)
- Last Synced: 2025-03-18T11:11:51.798Z (about 1 year ago)
- Language: C++
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## DataStructureCurriculumDesign
### A Double-linked list.
Class definition
```c++
class DLinkedList {
bool isEmpty(); // return if empty
bool add(T); // add element at the tail
bool add(uint32_t, T); // add element at the specific index
T set(uint32_t, T); // set element at the specific index
T remove(uint32_t); // remove element at the specific index
bool remove(T); // remove element that equals it
T get(uint32_t); // get element at specific index
clear(); // clear all elements
traverse(Function); // traverse list with lambda
traverse_reversed(Function); // traverse list reversed
contains(T); // return if list contains it
indexOf(T); // return first index of it or -1 if not exists
lastIndexOf(T); // return last index of it or -1 if not exists
size(); // return size
class Iterator {
Iterator begin(); // list head
Iterator end(); // list tail
};
iter(); // return the iterator
riter(); // return the reversed iterator
};
```
Because the `DLinkedList` implements `iterator`, so it supports some STL container operations.
```c++
auto iter = list -> iter();
// for each
for_each(iter.begin(), iter.end(), [&](int e) {
cout << e << " ";
});
// sum
auto sum = accumulate(iter.begin(), iter.end(), 0);
```