single linked list improvement
This commit is contained in:
parent
d5ae74f860
commit
259517ac9b
@ -1,8 +1,9 @@
|
|||||||
#ifndef SINGLYLINKEDLIST_H_
|
#ifndef FRAMEWORK_CONTAINER_SINGLYLINKEDLIST_H_
|
||||||
#define SINGLYLINKEDLIST_H_
|
#define FRAMEWORK_CONTAINER_SINGLYLINKEDLIST_H_
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
/**
|
/**
|
||||||
* @brief Linked list data structure,
|
* @brief Linked list data structure,
|
||||||
* each entry has a pointer to the next entry (singly)
|
* each entry has a pointer to the next entry (singly)
|
||||||
@ -47,12 +48,11 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
LinkedElement(T* setElement, LinkedElement<T>* setNext = NULL) : value(setElement),
|
LinkedElement(T* setElement, LinkedElement<T>* setNext = nullptr):
|
||||||
next(setNext) {
|
value(setElement), next(setNext) {}
|
||||||
}
|
|
||||||
virtual ~LinkedElement(){
|
virtual ~LinkedElement(){}
|
||||||
|
|
||||||
}
|
|
||||||
virtual LinkedElement* getNext() const {
|
virtual LinkedElement* getNext() const {
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ public:
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
LinkedElement* end() {
|
LinkedElement* end() {
|
||||||
return NULL;
|
return nullptr;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
LinkedElement *next;
|
LinkedElement *next;
|
||||||
@ -78,21 +78,21 @@ private:
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
class SinglyLinkedList {
|
class SinglyLinkedList {
|
||||||
public:
|
public:
|
||||||
SinglyLinkedList() :
|
using ElementIterator = typename LinkedElement<T>::Iterator;
|
||||||
start(NULL) {
|
|
||||||
}
|
SinglyLinkedList() {}
|
||||||
|
|
||||||
|
SinglyLinkedList(ElementIterator start) :
|
||||||
|
start(start.value) {}
|
||||||
|
|
||||||
SinglyLinkedList(typename LinkedElement<T>::Iterator start) :
|
|
||||||
start(start.value) {
|
|
||||||
}
|
|
||||||
SinglyLinkedList(LinkedElement<T>* startElement) :
|
SinglyLinkedList(LinkedElement<T>* startElement) :
|
||||||
start(startElement) {
|
start(startElement) {}
|
||||||
}
|
|
||||||
typename LinkedElement<T>::Iterator begin() const {
|
ElementIterator begin() const {
|
||||||
return LinkedElement<T>::Iterator::Iterator(start);
|
return ElementIterator::Iterator(start);
|
||||||
}
|
}
|
||||||
typename LinkedElement<T>::Iterator::Iterator end() const {
|
typename ElementIterator::Iterator end() const {
|
||||||
return LinkedElement<T>::Iterator::Iterator();
|
return ElementIterator::Iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t getSize() const {
|
uint32_t getSize() const {
|
||||||
@ -108,7 +108,7 @@ public:
|
|||||||
start = setStart;
|
start = setStart;
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
LinkedElement<T> *start;
|
LinkedElement<T> *start = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SINGLYLINKEDLIST_H_ */
|
#endif /* SINGLYLINKEDLIST_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user