Advertisement
Loesome

Untitled

Apr 6th, 2014
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 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. delete [] stack;
  22. }
  23. void clear(){
  24. top = 0;
  25. }
  26. void push(const E& it){
  27. if(top < sizeof(stack)){
  28. stack[top] = it;
  29. top++;}
  30. else{
  31. stack = (int *) realloc( stack, 2*sizeof(int) );
  32. stack[top] = it;
  33. top++;
  34.  
  35. }
  36. }
  37. E pop(){
  38. E top = stack[this->top - 1];
  39. this->top--;
  40. cout << "Pop de: " << top << endl;
  41.  
  42. return 0;
  43. }
  44. const E& topValue(){
  45. return stack[top - 1];
  46. }
  47. int length(){
  48. return top;
  49. }
  50.  
  51. };
  52.  
  53.  
  54. #endif // STACKADT_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement