Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <stdlib.h>
- using namespace std;
- bool isFull(int top, int size){
- return (top==(size-1));
- }
- bool isEmpty(int top){
- return (top == -1);
- }
- bool push(int *tab, int &top, int size, int wartosc){
- if(isFull(top, size)){
- cout << "PELNE"<<endl;
- return 0;
- }
- top++;
- tab[top]=wartosc;
- return 1;
- }
- int pop(int *tab, int &top){
- if(isEmpty(top)){
- cout << "PUSTY"<<endl;
- return 0;
- }
- int temp = tab[top];
- top--;
- return temp;
- }
- void showTop(int * tab, int top){
- if(isEmpty(top)) cout << "PUSTO"<<endl;
- else cout << tab[top]<<endl;
- }
- int main(){
- int tab[5];
- int size = 5;
- int top=-1;
- push(tab, top, size, 1);
- showTop(tab, top);
- push(tab, top, size, 2);
- showTop(tab, top);
- push(tab, top, size, 3);
- showTop(tab, top);
- push(tab, top, size, 4);
- showTop(tab, top);
- push(tab, top, size, 5);
- showTop(tab, top);
- push(tab, top, size, 6);
- showTop(tab, top);
- cout << pop(tab, top)<<endl;
- cout << pop(tab, top)<<endl;
- cout << pop(tab, top)<<endl;
- cout << pop(tab, top)<<endl;
- cout << pop(tab, top)<<endl;
- cout << pop(tab, top)<<endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement