Art_Uspen

Untitled

Sep 21st, 2021
676
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. struct Node {
  7.     Node(Node *n, int v) : next_(n), value(v){}
  8.  
  9.     Node *next_;
  10.     int value;
  11. };
  12.  
  13. struct Stack {
  14.     Node *head = nullptr;
  15.  
  16.     void push(int value) {
  17.         head = new Node(head, value);
  18.     }
  19.  
  20.     void pop() {
  21.         auto tmp = head;
  22.         head = head->next_;
  23.         delete tmp;
  24.     }
  25.  
  26.     void print() {
  27.         auto curr = head;
  28.         while (curr) {
  29.             cout << curr->value << ' ';
  30.             curr = curr->next_;
  31.         }
  32.     }
  33.     ~Stack(){
  34.       while(head){
  35.           pop();
  36.       }
  37.     }
  38. };
RAW Paste Data