Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
1.5 kB
1
Indexable
Never
#include <iostream>

using namespace std;

//the tree
template<class T2>
class vertex{
public:
    T2 data;
    vertex *left = nullptr, *right = nullptr;
};

template<class T>
class node{
public:
    T data;
    node *next, *prev;
};

template<class T>
class List{
public:
    node<T> *sar = nullptr , *tah = nullptr;
    int _size = 0;

    node<T>* first();
    void add_node(T);
    T pop();
    bool isempty();
    int sizee();
    T top();
};

template<class T>
node<T>* List<T>::first()
{
    return this->sar;
}

template<class T>
T List<T>::top()
{
    return this->tah->data;
}

template<class T>
bool List<T>::isempty()
{
    return this->_size == 0;
}

template<class T>
int List<T>::sizee()
{
    return this->_size;
}

template<class T>
T List<T>::pop()
{
    this->_size--;
    if(this->_size == 0){
        this->sar = nullptr;
        T ret = tah->data;
        this->tah = tah->prev;
        return ret;
    }

    T ret = tah->data;
    this->tah = tah->prev;
    this->tah->next = nullptr;
    return ret;
}

template<class T>
void List<T>::add_node(T data)
{
    node<T> *new_node = new node<T>;
    new_node->data = data;
    if(sar == nullptr){
        this->sar = new_node;
        this->tah = new_node;
    }
    else{
        this->tah->next = new_node;
        new_node->prev = tah;
        this->tah = new_node;
    }
    this->_size++;
}


int main()
{
    int n;
    cin >> n;
    vertex<int> *root = new vertex<int>;
    cin >> root->data;
    List<vertex*> tmplist[n];

}