Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #define _CRT_SECURE_NO_WARNINGS
- #include "BinaryFileManagement.h"
- #include <memory>
- #include <iostream>
- using namespace std;
- struct TreeNode {
- string key;
- long filePosition; // Позиция записи в файле
- shared_ptr<TreeNode> left; // Используем умные указатели
- shared_ptr<TreeNode> right;
- TreeNode(const string& key, long filePosition)
- : key(key), filePosition(filePosition), left(nullptr), right(nullptr) {}
- };
- class BinarySearchTree {
- public:
- BinarySearchTree(const string& fileName);
- void insert(const string& key, long filePosition);
- void remove(const string& key);
- void search(const string& key) const;
- void printTree() const;
- // Вспомогательные функции
- shared_ptr<TreeNode> insertRecursively(shared_ptr<TreeNode> node, const string& key, long filePosition);
- shared_ptr<TreeNode> removeRecursively(shared_ptr<TreeNode> node, const string& key);
- shared_ptr<TreeNode> findMinimum(shared_ptr<TreeNode> node) const;
- void printTreeRecursively(shared_ptr<TreeNode> node, int space) const;
- void buildTreeFromFile();
- private:
- shared_ptr<TreeNode> root;
- string fileName; // Имя файла, из которого строится дерево
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement