Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- template <typename Type>
- class Stack{
- Type stos[10];
- int ilosElementow;
- public:
- Stack(){
- ilosElementow=0;
- for(int i=0; i<10; i++){
- stos[i]=0;
- };
- };
- int push(Type add){
- if(ilosElementow!=10) {
- stos[ilosElementow] = add;
- ilosElementow++;
- }else {
- for(int i = 0; i<9; i++){
- stos[i] = stos[i+1];
- }
- stos[9]=add;
- }
- return 0;
- };
- int pop(){
- int zwroc;
- if(ilosElementow>0){
- zwroc=ilosElementow-1;
- ilosElementow--;
- }
- return stos[zwroc];
- };
- void print(){
- cout<< ilosElementow << ':';
- for(int i = ilosElementow-1; i>=0; i--){
- cout<< stos[i];
- }
- };
- };
- int main() {
- Stack<int> * stack = new Stack<int>();
- stack->push(1);
- stack->push(2);
- stack->push(3);
- stack->push(4);
- stack->push(5);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement