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 {
- private:
- void operator =(const StackADT&) {}
- StackADT(const StackADT&) {}
- E *stack;
- int top = 0;
- public:
- StackADT() {
- stack = new int[2];
- }
- ~StackADT() {
- delete [] stack;
- }
- void clear(){
- top = 0;
- }
- void push(const E& it){
- if(top < sizeof(stack)){
- stack[top] = it;
- top++;}
- else{
- stack = (int *) realloc( stack, 2*sizeof(int) );
- stack[top] = it;
- top++;
- }
- }
- E pop(){
- E top = stack[this->top - 1];
- this->top--;
- cout << "Pop de: " << top << endl;
- return 0;
- }
- const E& topValue(){
- return stack[top - 1];
- }
- int length(){
- return top;
- }
- };
- #endif // STACKADT_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement