Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions LinkedList.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ class LinkedList{
*/
virtual void clear();

/*
Iterates over the LinkedList;
Calls the callback function for each element;
*/
virtual void iterator(void (*iteratorCallback)(T &, T *_out), T *out);

/*
Sort the list, given a comparison function
*/
Expand Down Expand Up @@ -347,6 +353,22 @@ void LinkedList<T>::clear(){
shift();
}


template<typename T>
void LinkedList<T>::iterator(void (*iteratorCallback)(T &, T* _out), T *out){
ListNode<T>* current = root;

while(current){

// Post data to callback function
iteratorCallback(current->data, out);

current = current->next;
}

return NULL;
}

template<typename T>
void LinkedList<T>::sort(int (*cmp)(T &, T &)){
if(_size < 2) return; // trivial case;
Expand Down