Closed Thread
Results 1 to 3 of 3

Thread: Help with implementing the stack ADT using the STL vector class, C++

  1. #1
    mibit is offline Newbie
    Join Date
    May 2008
    Posts
    7
    Rep Power
    0

    Help with implementing the stack ADT using the STL vector class, C++

    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

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    mibit is offline Newbie
    Join Date
    May 2008
    Posts
    7
    Rep Power
    0

    Re: Help with implementing the stack ADT using the STL vector class, C++

    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

  4. #3
    Join Date
    Jul 2006
    Posts
    16,478
    Blog Entries
    75
    Rep Power
    143

    Re: Help with implementing the stack ADT using the STL vector class, C++

    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.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Stack allocation and stack size
    By mircan in forum C and C++
    Replies: 3
    Last Post: 03-17-2010, 06:53 PM
  2. Replies: 2
    Last Post: 07-10-2009, 11:36 AM
  3. Storing a Class in a Vector
    By Buttacup in forum C and C++
    Replies: 6
    Last Post: 07-04-2009, 02:06 PM
  4. Replies: 1
    Last Post: 12-20-2008, 11:58 AM
  5. VS2008 C# Sequential Lists: The Queue And Stack Class
    By Jordan in forum CSharp Tutorials
    Replies: 5
    Last Post: 05-26-2008, 09:43 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts