Don't understand this Stack assignment

Here is what my instructor gave me :

1
2
3
4
5
6
7
8
3) Write a full, templated Stack class with a Pointer Based Implementation.

Write tests to fully ensure that the Stack works under all conditions.
 

4) Write a full, templated Stack class with an Array Based Implementation.

Write tests to fully ensure that the Stack works under all conditions. (Do you need to write new tests?)


I need to ask, what is a "Pointer Based Implementation" and what is "Array Based Implementation"? Thank you in advance for clarification.
Anyone?
Look at http://www.cplusplus.com/reference/stack/stack/ and note that there is a mention about std::list and std::vector.
JLBorges posted this about 3 weeks back - you might have to tinker with it a bit to meet your exact requirements but it will certainly show you best practices re how it's done
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <cassert>

template < typename T > class stack
{
    // note: move semantics ignored
    public:

        stack() = default ;
        ~stack() { while( !empty() ) pop() ; }

        // non-copyable
        stack( const stack<T>& ) = delete ;
        stack<T>& operator= ( const stack<T>& ) = delete ;

        bool empty() const { return p_top == nullptr ; }

        void push( const T& value ) { node* n = new node( value, p_top ) ; p_top = n ; }

        void pop() // invariant: !empty()
        { assert( !empty() ) ; node* n = p_top ; p_top = p_top->next ; delete n ; }

        const T& top() const { assert( !empty() ) ;  return p_top->value ; } // invariant: !empty()
        T& top() { assert( !empty() ) ; return p_top->value ; } // invariant: !empty()

    private:

        struct node
        {
            node( T v, node* n = nullptr ) : value(v), next(n) {}
            T value ;
            node* next ;
        };

        node *p_top = nullptr ;
};

int main()
{
    stack<int> stk ;
    for( int i = 0 ; i < 20 ; ++i ) stk.push(i) ;
    for (int i = 0; i < 20; ++i)stk.push(i);

    while( !stk.empty() )
    {
        std::cout << stk.top() << ' ' ;
        stk.pop() ;
    }
    std::cout << '\n' ;*/

}


PS: this was the link I'd saved for the above code but it doesn't seem to be working just now http://www.cplusplus.com/forum/general/209182/
Topic archived. No new replies allowed.