diff --git a/LinkedList.h b/LinkedList.h index 742933a..c89c3c9 100644 --- a/LinkedList.h +++ b/LinkedList.h @@ -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 */ @@ -347,6 +353,22 @@ void LinkedList::clear(){ shift(); } + +template +void LinkedList::iterator(void (*iteratorCallback)(T &, T* _out), T *out){ + ListNode* current = root; + + while(current){ + + // Post data to callback function + iteratorCallback(current->data, out); + + current = current->next; + } + + return NULL; +} + template void LinkedList::sort(int (*cmp)(T &, T &)){ if(_size < 2) return; // trivial case;