Advertisement
k0mZ

Untitled

May 10th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #pragma once
  2.  
  3. class Stek {
  4. int top;
  5. int* stackElems;
  6. int size;
  7. public:
  8.  
  9. ~Stek() {
  10. delete[] stackElems;
  11. }
  12.  
  13.  
  14. bool isEmpty() {
  15. return (this->top < 0);
  16. }
  17.  
  18. int topElem()
  19. {
  20. //ne brise ga
  21. if (this->top < 0)
  22. throw "Underflow";
  23.  
  24. int tmp = stackElems[top];
  25. return tmp;
  26.  
  27. }
  28.  
  29. Stek(int asize)
  30. {
  31. top = -1;
  32. stackElems = new int[asize];
  33.  
  34. this->size = asize;
  35.  
  36. }
  37.  
  38. void push(int a)
  39. {
  40. if (top == size-1)
  41. throw "Overflow!";
  42. top = top + 1;
  43. stackElems[top] = a;
  44. }
  45.  
  46. int pop()
  47. {
  48. if (top < 0)
  49. throw "Underflow";
  50. int tmp = stackElems[top];
  51. top = top - 1;
  52. return tmp;
  53. }
  54.  
  55.  
  56. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement