home *** CD-ROM | disk | FTP | other *** search
- #include <iostream>
- #include <string>
-
- using namespace std;
-
- struct node_t {
- struct node_t *next;
- string data;
- };
-
- class CStack {
- public:
- CStack() { head=0; }
- ~CStack() { Clear(); };
- bool Push(const string &s);
- bool Pop( string &s );
- private:
- void Clear();
- node_t *head;
- };
-
- bool CStack::Push( const string &s )
- {
- node_t *n = new node_t;
- if (!n)
- return false;
- n->data = s;
- n->next = head;
- head = n;
- return true;
- }
-
- bool CStack::Pop( string &s )
- {
- if (!head)
- return false;
- node_t *n = head;
- s = n->data;
- head = n->next;
- delete n;
- return true;
- }
-
- void CStack::Clear()
- {
- node_t *n = head;
-
- while (n) {
- head = n->next;
- delete n;
- n = head;
- }
- head = 0;
- }
-
-
- int main()
- {
- string s;
- CStack cs;
- int count = 0;
-
- while (getline( cin, s ) && s.length()) {
- count++;
- if (!cs.Push( s ))
- break;
- }
-
- while (cs.Pop(s))
- cout << s << '\n';
-
- return 0;
- }
-
-
-