Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct stos
- {
- int wartosc;
- stos *next;
- };
- bool isempty(stos *top)
- {
- return top==NULL;
- }
- bool push(stos *&top, int val)
- {
- stos *nowy = new stos;
- nowy->next=top;
- nowy->wartosc=val;
- top=nowy;
- return 1;
- }
- bool pop(stos *&top, int &wart)
- {
- if(isempty(top))
- return 0;
- stos *temp = new stos;
- temp=top;
- wart=temp->wartosc;
- top=temp->next;
- delete temp;
- return 1;
- }
- void showtop(stos *top)
- {
- if(isempty(top))
- cout<<"Pusty"<<endl;
- else
- cout<<"top: "<<top->wartosc<<endl;
- }
- int main()
- {
- stos *top = NULL;
- int val;
- push(top, 1);
- showtop(top);
- push(top, 2);
- showtop(top);
- push(top, 3);
- showtop(top);
- push(top, 4);
- showtop(top);
- push(top, 5);
- showtop(top);
- push(top, 6);
- showtop(top);
- push(top, 7);
- showtop(top);
- push(top, 8);
- showtop(top);
- pop(top, val);
- cout<<val<<endl;
- showtop(top);
- pop(top, val);
- cout<<val<<endl;
- showtop(top);
- pop(top, val);
- cout<<val<<endl;
- showtop(top);
- pop(top, val);
- cout<<val<<endl;
- showtop(top);
- pop(top, val);
- cout<<val<<endl;
- showtop(top);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement