Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <string>
- using namespace std;
- struct element
- {
- string dane;
- element *nast;
- };
- element *wierzch = NULL;
- void push(string nowedane)
- {
- element *punkt;
- punkt = wierzch;
- wierzch = new element;
- wierzch->dane = nowedane;
- wierzch->nast = punkt;
- }
- string pop()
- {
- string x;
- element *punkt;
- if(wierzch != NULL)
- {
- x = wierzch->dane;
- punkt = wierzch->nast;
- delete wierzch;
- wierzch = punkt;
- }
- return x;
- }
- bool empty()
- {
- if(wierzch == NULL)
- return true;
- else return false;
- }
- int main()
- {
- string linia;
- getline(cin, linia);
- while(linia != "KONIEC"){
- push(linia);
- getline(cin, linia);
- }
- while(!empty()){
- cout << pop() << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement