Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- struct Node {
- long long key = 0;
- Node* parent = nullptr;
- Node* left = nullptr;
- Node* right = nullptr;
- Node* root;
- void insert(long long key) {
- auto z = new Node;
- z->key = key;
- Node* ptr = root;
- while (ptr != nullptr) {
- if (key == ptr->key) {
- return;
- }
- if (key > ptr->key) {
- if (ptr->right != nullptr) {
- ptr = ptr->right;
- } else {
- z->parent = ptr;
- ptr->right = z;
- return;
- }
- } else if (key < ptr->key) {
- if (ptr->left != nullptr) {
- ptr = ptr->left;
- } else {
- z->parent = ptr;
- ptr->left = z;
- return;
- }
- }
- }
- root = z;
- }
- };
- int main() {
- ifstream fin("set.in");
- ofstream fout("set.out");
- Set myset;
- myset.res();
- string str;
- int k;
- bool fl;
- while(fin>>str>>k){
- if (str == "insert") {
- myset.insert(k);
- }
- else if (str == "exists") {
- int hash_numb = abs(k) % 1000001;
- fl = find(myset.numb[hash_numb].begin(), myset.numb[hash_numb].end(), k) != myset.numb[hash_numb].end();
- if (fl) {
- fout << "true\n";
- }
- else {
- fout << "false\n";
- }
- }
- else if (str == "delete") {
- myset.deleete(k);
- }
- }
- cin.close();
- cout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement