Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- struct Node {
- Node(Node *n, int v) : next_(n), value(v){}
- Node *next_;
- int value;
- };
- struct Stack {
- Node *head = nullptr;
- void push(int value) {
- head = new Node(head, value);
- }
- void pop() {
- auto tmp = head;
- head = head->next_;
- delete tmp;
- }
- void print() {
- auto curr = head;
- while (curr) {
- cout << curr->value << ' ';
- curr = curr->next_;
- }
- }
- ~Stack(){
- while(head){
- pop();
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement