cpp_library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub toyama1710/cpp_library

:warning: stack/persistent_stack.cpp

Code

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <memory>
using namespace std;
using llong = long long;

//===
template <class T, template <class> class Alloc = allocator>
struct PersistentStack {
    struct Node {
        T d;
        Node *next = nullptr;
    };
    using Traits = allocator_traits<Alloc<Node> >;
    static Alloc<Node> alc;

    Node *head = nullptr;

    PersistentStack current_stack() {
        return PersistentStack(head);
    };

    T top() {
        return head->d;
    };

    void push(T d) {
        Node *p = Traits::allocate(alc, 1);
        Traits::construct(alc, p, d, head);
        head = p;
    };

    void pop(T d) {
        head = head->next;
    };

    ~PersistentStack() {
        Node *p;
        while (head != nullptr) {
            p = head->next;
            Traits::deallocate(alc, head, 1);
            head = p;
        }
    };
};
//===

int main() {
    return 0;
}
#line 1 "stack/persistent_stack.cpp"
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <memory>
using namespace std;
using llong = long long;

//===
template <class T, template <class> class Alloc = allocator>
struct PersistentStack {
    struct Node {
        T d;
        Node *next = nullptr;
    };
    using Traits = allocator_traits<Alloc<Node> >;
    static Alloc<Node> alc;

    Node *head = nullptr;

    PersistentStack current_stack() {
        return PersistentStack(head);
    };

    T top() {
        return head->d;
    };

    void push(T d) {
        Node *p = Traits::allocate(alc, 1);
        Traits::construct(alc, p, d, head);
        head = p;
    };

    void pop(T d) {
        head = head->next;
    };

    ~PersistentStack() {
        Node *p;
        while (head != nullptr) {
            p = head->next;
            Traits::deallocate(alc, head, 1);
            head = p;
        }
    };
};
//===

int main() {
    return 0;
}
Back to top page