Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <iostream>
  3.  
  4. #include <cstdlib>
  5.  
  6. using namespace std;
  7.  
  8. template <typename Type>
  9. class Stack{
  10. Type stos[10];
  11. int ilosElementow;
  12. public:
  13. Stack(){
  14. ilosElementow=0;
  15. for(int i=0; i<10; i++){
  16. stos[i]=0;
  17. };
  18. };
  19. int push(Type add){
  20. if(ilosElementow!=10) {
  21. stos[ilosElementow] = add;
  22.  
  23. ilosElementow++;
  24.  
  25. }else {
  26.  
  27. for(int i = 0; i<9; i++){
  28. stos[i] = stos[i+1];
  29. }
  30. stos[9]=add;
  31. }
  32.  
  33. return 0;
  34. };
  35. int pop(){
  36. int zwroc;
  37. if(ilosElementow>0){
  38. zwroc=ilosElementow-1;
  39. ilosElementow--;
  40.  
  41. }
  42. return stos[zwroc];
  43. };
  44. void print(){
  45.  
  46. cout<< ilosElementow << ':';
  47.  
  48. for(int i = ilosElementow-1; i>=0; i--){
  49.  
  50. cout<< stos[i];
  51.  
  52. }
  53. };
  54. };
  55.  
  56.  
  57. int main() {
  58.  
  59.  
  60. Stack<int> * stack = new Stack<int>();
  61. stack->push(1);
  62. stack->push(2);
  63. stack->push(3);
  64. stack->push(4);
  65. stack->push(5);
  66.  
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement