Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef STACKADT_H
- #define STACKADT_H
- #include <Stack.h>
- #include <stdlib.h>
- #include <iostream>
- using namespace std;
- template <typename E> class StackADT : public Stack<E>
- {
- private:
- void operator =(const StackADT&) {}
- StackADT(const StackADT&) {}
- E *stack;
- int top = 0;
- public:
- StackADT() {
- stack = new E[2];
- }
- ~StackADT() {}
- void clear(){
- top = 0;
- }
- void push(const E& it){
- if(top < sizeof(stack)){
- stack[top] = it;
- top++;}
- else{
- stack = (E *) realloc( stack, 2*sizeof(E));
- stack[top] = it;
- top++;
- }
- }
- E pop(){
- E aux = stack[this->top - 1];
- this->top--;
- return aux;
- }
- const E& topValue()const{
- return stack[top - 1];
- }
- int length()const{
- return top;
- }
- };
- #endif // STACKADT_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement