Hi there, could anybody please do me a big favour and write a complete program in C++ with at least one example of using all interface functions of the specified below ADT ( Abstract Data Type)
You should implement the stack ADT using the STL vector class.
Thanks![]()
Here is what I did so far:
Code:#ifndef SIMPLE_STACK_LIFO #define SIMPLE_STACK_LIFO #include <vector> template <class T> class stack{ public: typedef std::vector<T> Container; typedef typename Container::size_type size_type; typedef typename Container::value_type value_type; typedef typename Container::reference reference; typedef typename Container::const_reference const_reference; explicit stack(const size_type nSize = 100){ m_vContainer.reserve(nSize); } void push(const_reference obj){ m_vContainer.push_back(obj); } reference top(){ return m_vContainer.back(); } const_reference top() const{ return m_vContainer.back(); } void pop(){ m_vContainer.pop_back(); } bool empty() const{ return m_vContainer.empty(); } size_type size() const{ return m_vContainer.size(); } protected: Container m_vContainer; }; #endif // SIMPLE_STACK_LIFO
A few comments/questions:
1) Since the specification of a stack may vary from book to book, what methods need to be included?
2) Are you getting any compiler errors with your implementation?
3) Have you built a test application for your implementation?
4) If so, does it appear to be working correctly?
We aren't going to write your program for you, but we can offer guidance.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks