Updated SimpleList

This commit is contained in:
Stefan Kremser
2018-04-13 10:36:08 +02:00
parent 6b585fddb4
commit d48a0f9fc4

View File

@@ -282,6 +282,17 @@ void SimpleList<T>::swap(int x, int y){
y = h;
}
// When data is small, copy it
if(sizeof(T) < 24){
Node<T>* nodeA = getNode(x);
Node<T>* nodeB = getNode(y);
T h = nodeA->data;
nodeA->data = nodeB->data;
nodeB->data = h;
}
// otherwise change the pointers
else {
// Example: a -> b -> c -> ... -> g -> h -> i
// we want to swap b with h
Node<T>* nodeA = getNode(x - 1); // x.prev
@@ -313,6 +324,7 @@ void SimpleList<T>::swap(int x, int y){
nodeG->next = nodeB;
}
}
}
template<typename T>
void SimpleList<T>::sort(bool (*cmp)(T &a, T &b)) {