12345678910111213141516171819
/* #include <cstdlib> //added http://forums.devx.com/showthread.php?t=152439 #include <string> #include <iostream> #include <fstream> #include "iterator.h" #include "genlib.h" #include "stdafx.h" using namespace std; template <typename ElemType> Iterator<ElemType>::Iterator() { start = NULL; tail = NULL; } ... */
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
#include "stdafx.h" #include <cstdlib> //added http://forums.devx.com/showthread.php?t=152439 #include <string> #include <iostream> #include <fstream> #include "iterator.h" #include "genlib.h" using namespace std; template <typename ElemType> Iterator<ElemType>::Iterator() { start = NULL; tail = NULL; } template <typename ElemType> Iterator<ElemType>::~Iterator() { // This should be left empty for very subtle reasons } template <typename ElemType> bool Iterator<ElemType>::hasNext() { return (start != NULL); } template <typename ElemType> ElemType Iterator<ElemType>::next() { cellT *cp = start; if (cp == NULL) Error("Next called on empty iterator"); ElemType elem = cp->elem; start = cp->link; delete cp; return elem; } template <typename ElemType> void Iterator<ElemType>::add(ElemType elem) { cellT *cp = new cellT; cp->elem = elem; cp->link = NULL; if (tail == NULL) { start = cp; } else { tail->link = cp; } tail = cp; }