Advertisement
Loesome

Stack

Apr 6th, 2014
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #ifndef STACKADT_H
  2. #define STACKADT_H
  3. #include <Stack.h>
  4. #include <stdlib.h>
  5. #include <iostream>
  6.  
  7. using namespace std;
  8. template <typename E>
  9. class StackADT {
  10. private:
  11. void operator =(const StackADT&) {}
  12. StackADT(const StackADT&) {}
  13. E *stack;
  14. int top = 0;
  15.  
  16. public:
  17. StackADT() {
  18. stack = new int[2];
  19. }
  20. ~StackADT() {}
  21.  
  22. void clear(){
  23. top = 0;
  24. }
  25. void push(const E& it){
  26. if(top < sizeof(stack)){
  27. stack[top] = it;
  28. top++;}
  29. else{
  30. stack = (int *) realloc( stack, 2*sizeof(int) );
  31. stack[top] = it;
  32. top++;
  33.  
  34. }
  35. }
  36. E pop(){
  37. E top = stack[this->top - 1];
  38. this->top--;
  39. cout << "Pop de: " << top << endl;
  40.  
  41. return 0;
  42. }
  43. const E& topValue(){
  44. return stack[top - 1];
  45. }
  46. int length(){
  47. return top;
  48. }
  49.  
  50. };
  51.  
  52.  
  53. #endif // STACKADT_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement