Я хочу создать базовый класс для моих классов. Как мне это сделать правильно? #include…
- User
Я хочу создать базовый класс для моих классов. Как мне это сделать правильно? #include #include #include #include #include
template struct Node { Node* left_child{}; Node* right_child{}; T value{}; };
template <typename KeyType, typename ValueType> struct AA_node { KeyType key{}; ValueType value{}; AA_node<KeyType, ValueType>* left{}; AA_node<KeyType, ValueType>* right{};
AA_node(KeyType k, ValueType v) : key(k), value(v), left(nullptr), right(nullptr) {}};
template struct DL_node { T value{}; DL_node* prev{}; DL_node* next{};
//DL_node(int d) : data(d), prev(nullptr), next(nullptr) {}};
template class PersistentArray { private:
// base version T* base{}; // size of base version int size{}; // container for roots of versions std::vector<Node<T>*> versions{}; std::vector<std::pair<int, int>> parent_children_relation{}; // recursive function to build tree with leafs as elemnts of _array in [_l..._r] and _node as root of version void buildTree(Node<T>* _node, T* _array, int _left_border, int _right_border); // recursive function to add new version by changing one value in one of previous version void add(Node<T>* _to, Node<T>* _from, int _left_border, int _right_border, int _position, T _new_value); // recursive function to get element of specific node T get(Node<T>* _node, int _left_border, int _right_border, int _position); // recursive function to count leaves in a tree int countLeaves(Node<T>* _node); // print from [_left] to [_right] void printSlice(T* _arr, int _left, int _right);public:
// constructor with empty array of _size * elements PersistentArray(int _size); // constructor with _array of _size * elements PersistentArray(T* _arr, int _size); // destructor ~PersistentArray(); // set element to base version void setElementToBase(int _index, T _value); // change element by index in a specific version with new value void changeVersion(int _number_of_version, int _change_index, T _new_value); // add new version by changing one value in one of previous version void addVersion(int _root_position, int _change_inde, T _new_value); // print all versions as a table void printAllVersions(); // get size of a specific version int versionSize(int _number_of_version); // get a specific version as array T* getArray(int _number_of_version); // delete element in a specific version void deleteElement(int _root_position, int _delete_index); // insert a new value in a specific version void insertElement(int _root_position, int _insert_index, T _new_value); // get a root of specific version Node<T>* getVersion(int _number_of_version); // get number of versions int sizeVersions();};
template class PersistentDoublyLinkedList { private:
// base version DL_node<T>* base; // size of base version int size{}; // container for roots of versions std::vector<Node<T>*> versions{}; std::vector<std::pair<int, int>> parent_children_relation{}; // recursive function to build tree with leafs as elemnts of _array in [_l..._r] and _node as root of version void buildTree(Node<T>* _node, DL_node<T>* _list_head, int _left_border, int _right_border); // recursive function to add new version by changing one value in one of previous version void add(Node<T>* _to, Node<T>* _from, int _left_border, int _right_border, int _position, T _new_value); // recursive function to get element of specific node T get(Node<T>* _node, int _left_border, int _right_border, int _position); // making a single node with data and assign it to base void initDL(T _data); // recursive function to count leaves in a tree int countLeaves(Node<T>* _node); - Assistant