I've been developing my own stack implementation. data is my main storage mechanism:
I've supplied all the functionality I need for the stack except for a class iterator to loop through the stack's values. I'm looking to do something like this:Code:template<class T> class Stack { private: T *data; public: typedef T* iter;
What should I have the begin() and end() functions return? An iterator is basically a pointer to the stack data right? I'm stuck.Code:Stack<int> s; s.push(1); s.push(2); s.push(4); for(Stack<int>::iter it=s.begin();it!=s.end();it++) cout << *it << endl;
Am I on the right track?Code:inline iter begin() { iter front= ... //???? return front; }


Reply With Quote
Bookmarks