Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- struct Node{
- int value;
- Node* next;
- };
- void PushBack(Node* &prev, int digit) {
- Node *cur = new Node;
- cur->value = digit;
- cur->next = prev;
- prev = cur;
- }
- int PopBack(Node* &cur) {
- int digit = cur->value;
- Node *temp = cur;
- cur = cur->next;
- delete temp;
- return digit;
- }
- int main() {
- std::ifstream in;
- std::ofstream out;
- in.open("input.txt");
- out.open("output.txt");
- int n;
- in >> n;
- Node* stack = new Node;
- char operation;
- int digit;
- for (int i = 0; i < n; i++) {
- in >> operation;
- if (operation=='+') {
- in >> digit;
- PushBack(stack, digit);
- }
- else {
- if (operation=='-') {
- out << PopBack(stack) << std::endl;
- }
- }
- }
- out.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement