+ Reply to Thread
Results 1 to 3 of 3

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

  1. #1
    Newbie mibit is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    7

    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. #2
    Newbie mibit is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    7

    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

  3. #3
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    37
    Posts
    12,912
    Blog Entries
    57

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

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. ROBOT ASSEMBLY-- C language
    By hummer350 in forum C and C++
    Replies: 3
    Last Post: 07-31-2008, 07:03 PM
  2. VS2008 C# Sequential Lists: The Queue And Stack Class
    By Jordan in forum CSharp Tutorials
    Replies: 5
    Last Post: 05-26-2008, 08:43 AM
  3. program on signed and unsigned numbers
    By Nethra in forum C and C++
    Replies: 33
    Last Post: 03-22-2008, 02:05 AM
  4. Reverse String using Stack.
    By nt_virus in forum C# Programming
    Replies: 1
    Last Post: 02-24-2008, 09:22 PM
  5. Understanding the stack
    By RobSoftware in forum General Programming
    Replies: 3
    Last Post: 08-27-2006, 10:44 AM