Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Elem {
- long long value;
- Elem *next;
- };
- class List
- {
- Elem *begin;
- Elem *first;
- public:
- List() {
- begin = NULL;
- first = NULL;
- }
- ~List() {
- Elem *pt;
- while (first != NULL) {
- pt = first;
- first = first->next;
- delete pt;
- }
- }
- void push(long long value) {
- Elem *pt = new Elem;
- pt->value = value;
- pt->next = NULL;
- if (begin == NULL)
- begin = pt;
- begin->next = pt;
- if (first == NULL)
- first = begin;
- begin = begin->next;
- }
- long long pop() {
- if (!first)
- return -1;
- Elem *pt = first;
- int value = pt->value;
- first = pt->next;
- delete pt;
- return value;
- }
- bool empty() {
- if (first == NULL)
- return true;
- else
- return false;
- }
- };
- int main() {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- long long tmp;
- List list;
- while (cin >> tmp) {
- list.push(tmp);
- }
- while (!list.empty())
- cout << list.pop() << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement