RLL(Reduced linked list)项目

· · 个人记录

RLL(Reduced linked list)项目

namespace rll { //Reduced linked list
    template<typename T, const unsigned int MAX_LENGTH>
    class stack
    {
    public:
        unsigned int t = 0;
        T s[MAX_LENGTH];
        const T& operator[](unsigned int x) const
        {
            if (x >= t)
                exit(11);
            return s[x];
        }
        T& operator[](unsigned int x)
        {
            if (x >= t)
                exit(11);
            return s[x];
        }
        void push(T x)
        {
            s[t++] = x;
            return;
        }
        T pop()
        {
            return s[--t];
        }
        T top()
        {
            return s[t - 1];
        }
        T find(unsigned int x)
        {
            if (x >= t)
                exit(11);
            return s[t - 1 - x];
        }
        void clear()
        {
            delete this;
        }
        ~stack()
        {
            delete this;
        }
    };
}
\color{#E4671E}\mathsf{『该醒了。』}\\\scriptsize\mathsf{—Wake\ up.—}