Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- struct el
- {
- int val;
- el* link;
- };
- int main()
- {
- int st_size=0;
- el head;
- head.link=NULL;
- string order="";
- fstream fin;
- fin.open("input.txt");
- while (order!="exit")
- {
- if (order=="push")
- {
- int n;
- fin >>n;
- el* y = new el;
- (*y).link=&head;
- (*y).val=n;
- head=*y;
- st_size++;
- cout <<"ok" <<endl;
- }
- else if (order=="pop")
- {
- if (st_size==0) cout <<"error" <<endl;
- else {
- cout <<head.val <<endl;
- el* y = &head;
- head=*(head.link);
- delete y;
- st_size--;
- }
- }
- else if (order=="back")
- {
- if (st_size==0) cout <<"error" <<endl;
- else cout <<head.val <<endl;
- }
- else if (order=="size")
- {
- cout <<st_size << endl;
- }
- else if (order=="clear")
- {
- while (head.link!=NULL)
- {
- el* y = &head;
- head=*(head.link);
- delete y;
- st_size--;
- }
- cout <<"ok" <<endl;
- }
- fin >>order;
- }
- cout <<"bye" <<endl;
- fin.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement