Results 1 to 2 of 2

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date: Dec:2006
    Location: SOFIA
    Posts: 18

    Ïîìîù ñúñ implement the stack ADT using the STL vector class, C++

    Àêî ìîæå íÿêîé äà ìè ïîìîãíå äà íàïèùà ñëåäíàòà ïðîãðàìà íà C++ ùå ñúì ìó ìíîãî áëàãîäàðåí:

    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.



    Ìåðñè

  2. #2
    Registered User
    Join Date: Dec:2006
    Location: SOFIA
    Posts: 18
    çà ñåãà èìàì òîâà
    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

Posting Permissions

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

Copyright © 1999-2011 Õàðäóåð ÁÃ. Âúçìîæíî å ñúäúðæàíèåòî íà òàçè ñòðàíèöà äà å îáåêò íà àâòîðñêè ïðàâà.
iskamPC.com | mobility.BG | Bloody's Techblog | Êðèïòîâàëóòè è ìàéíèíã | 3D Vision Blog | Ìàãàçèí çà åëåêòðîííè öèãàðè