Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "GrootTree.h"
- int main()
- {
- // int map - лямбда функции
- auto mapI1 = [](const int& element) { return element * 2; }; //multiply by 2
- auto mapI2 = [](const int& element) { return (float)element / 3; }; //divide by 3
- auto mapI3 = [](const int& element) { return element % 5; }; //Nmod5
- // int where
- auto whereI1 = [](const int& element) { return (element * 2.0) < 24; }; //(N * 2) < 24
- auto whereI2 = [](const int& element) { return (element % 3) == 1; }; //Nmod3 == 1
- auto whereI3 = [](const int& element) { return element != 2; }; //N != 2
- // float map
- auto mapF1 = [](const float& element) { return element * 3.5f; }; // multiply by 3.5
- auto mapF2 = [](const float& element) { return (element / 2.0f) + 2.5f; }; //divide by 2 and add 2.5
- auto mapF3 = [](const float& element) { return exp(element); }; //e^N
- // float where
- auto whereF1 = [](const float& element) { return (element * 2.0) < 24.0; }; //(N * 2) < 24
- auto whereF2 = [](const float& element) { return (element / 3.0) > 10.0; }; //N / 3 > 10
- auto whereF3 = [](const float& element) { return element != 2.0; }; //N != 2
- // Complex map
- auto mapC1 = [](const Complex& element) { return element * 3; }; // mul by 3
- auto mapC2 = [](const Complex& element) { return element + Complex(2, 3); }; // plus 2 + 3i
- auto mapC3 = [](const Complex& element) { return (element * 2) + Complex(3, 4); }; // mul by 2 + (3 + 4i)
- // Complex where
- auto whereC1 = [](const Complex& element) { return element == 24; }; // |Z| == 25
- auto whereC2 = [](const Complex& element) { return element > 11; }; // |Z| > 11
- auto whereC3 = [](const Complex& element) { return element < 30; }; //|Z| < 30
- /*Tree<int> t = "4,2,1,3,6,5,7";
- cout << t.toString("klp") << endl;
- cout << t.toString("kpl") << endl;
- cout << t.toString("lpk") << endl;
- cout << t.toString("lkp") << endl;
- cout << t.toString("plk") << endl;
- cout << t.toString("pkl") << endl;
- t.map<int>(mul2);
- cin.get();
- */
- string travese; // способ обхода
- string data, data2;// числа
- int oper, type, test;
- cout << "Hello, I am Groot. Would you like to test all functions?" << endl;
- cin >> test;
- while ((test != 1) && (test != 2))
- {
- cout << "error (enter 1 or 2)" << endl;
- cin >> test;
- }
- if (test == 1) // testAll();
- cout << "Choose the type of numbers: \n 1 - int\n 2 - float \n 3 - complex \n 4 - exit program" << endl;
- cin >> type;
- while ((type != 1) && (type != 2) && (type != 3) && (type != 4))
- {
- cout << "error (enter 1, 2, 3 or 4)" << endl;
- cin >> type;
- }
- if (type == 1) //int
- {
- cout << "Choose an operation: \n 1 - map\n 2 - where\n 3 - merging\n 4 - retrieval a tree by an element \n 5 - searching a subtree \n 6 - searching am element " << endl;
- cin >> oper;
- while ((oper != 1) && (oper != 2) && (oper != 3) && (oper != 4))
- {
- cout << "error (enter 1, 2, 3 or 4)" << endl;
- cin >> oper;
- }
- if (oper == 1) //map
- {
- cout << "Choose the map function: \n1 - multiply by 2 \n2 - divide by 3 \n3 - Nmod5" << endl;
- int cond;
- cin >> cond;
- switch (cond) {
- case 1: {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<int> tree(data);
- cout << tree.map<int>(mapI1).toString(travese) << endl;
- }
- break;
- case 2: {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<int> tree(data);
- cout << tree.map<float>(mapI2).toString(travese) << endl;
- }
- break;
- case 3: {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<int> tree(data);
- cout << tree.map<int>(mapI3).toString(travese) << endl;
- }
- break;
- default: {
- cout << "What are you doing? Try again!" << endl;
- cin >> cond;
- }
- }
- } else if (oper == 2) //where
- {
- cout << "Choose the where function: \n1 - (N * 2) < 24 \n2 - Nmod3 == 1 \n3 - N != 2" << endl;
- int cond;
- cin >> cond;
- switch (cond) {
- case 1: {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<int> tree(data);
- cout << tree.where(whereI1).toString(travese) << endl;
- }
- break;
- case 2: {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<int> tree(data);
- cout << tree.where(whereI2).toString(travese) << endl;
- }
- break;
- case 3: {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<int> tree(data);
- cout << tree.where(whereI3).toString(travese) << endl;
- }
- break;
- default: {
- cout << "What are you doing? Try again!" << endl;
- cin >> cond;
- }
- }
- } else if (oper == 3) //merging
- {
- cout << "Enter string of numbers to first tree" << endl;
- cin >> data;
- Tree<int> tree1(data);
- cout << "Enter string of numbers to second tree" << endl;
- cin >> data2;
- Tree<int> tree2(data2);
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<int> treeRes = tree1 + tree2;
- cout << treeRes.toString(travese) << endl;
- } else if (oper == 4) // retrieval
- {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter a wanted element" << endl;
- int element;
- cin >> element;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<int> tree(data);
- cout << tree.extract(element).toString(travese) <<endl;
- } else if (oper == 5) // search subtree
- {
- //хер его знает
- } else if (oper == 6) // search an element
- {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter a wanted element" << endl;
- int element;
- cin >> element;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<int> tree(data);
- cout << boolalpha << tree.containsElement(element) << endl;
- }
- } else if (type == 2) //float
- {
- cout << "Choose an operation: \n 1 - map\n 2 - where\n 3 - merging\n 4 - retrieval a tree by an element \n 5 - searching a subtree \n 6 - searching am element " << endl;
- cin >> oper;
- while ((oper != 1) && (oper != 2) && (oper != 3) && (oper != 4))
- {
- cout << "error (enter 1, 2, 3 or 4)" << endl;
- cin >> oper;
- }
- if (oper == 1) //map
- {
- cout << "Choose the map function: \n1 - multiply by 3.5 \n2 - divide by 2 and add 2.5 \n3 - e^N" << endl;
- int cond;
- cin >> cond;
- switch (cond) {
- case 1: {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<float> tree(data);
- cout << tree.map<float>(mapF1).toString(travese) << endl;
- }
- break;
- case 2: {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<float> tree(data);
- cout << tree.map<float>(mapF2).toString(travese) << endl;
- }
- break;
- case 3: {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<float> tree(data);
- cout << tree.map<float>(mapF3).toString(travese) << endl;
- }
- break;
- default: {
- cout << "What are you doing? Try again!" << endl;
- cin >> cond;
- }
- }
- } else if (oper == 2) //where
- {
- cout << "Choose the where function: \n1 - (N * 2) < 24 \n2 - N / 3 > 10 \n3 - N != 2" << endl;
- int cond;
- cin >> cond;
- switch (cond) {
- case 1: {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<float> tree(data);
- cout << tree.where(whereF1).toString(travese) << endl;
- }
- break;
- case 2: {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<float> tree(data);
- cout << tree.where(whereF2).toString(travese) << endl;
- }
- break;
- case 3: {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<float> tree(data);
- cout << tree.where(whereF3).toString(travese) << endl;
- }
- break;
- default: {
- cout << "What are you doing? Try again!" << endl;
- cin >> cond;
- }
- }
- } else if (oper == 3) //merging
- {
- cout << "Enter string of numbers to first tree" << endl;
- cin >> data;
- Tree<float> tree1(data);
- cout << "Enter string of numbers to second tree" << endl;
- cin >> data2;
- Tree<float> tree2(data2);
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<float> treeRes = tree1 + tree2;
- cout << treeRes.toString(travese) << endl;
- } else if (oper == 4) // retrieval
- {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter a wanted element" << endl;
- float element;
- cin >> element;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<float> tree(data);
- cout << tree.extract(element).toString(travese) <<endl;
- } else if (oper == 5) // search subtree
- {
- //хер его знает
- } else if (oper == 6) // search an element
- {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter a wanted element" << endl;
- float element;
- cin >> element;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<float> tree(data);
- cout << boolalpha << tree.containsElement(element) << endl;
- }
- } else if (type == 3) //Complex
- {
- cout << "Choose an operation: \n 1 - map\n 2 - where\n 3 - merging\n 4 - retrieval a tree by an element \n 5 - searching a subtree \n 6 - searching am element " << endl;
- cin >> oper;
- while ((oper != 1) && (oper != 2) && (oper != 3) && (oper != 4))
- {
- cout << "error (enter 1, 2, 3 or 4)" << endl;
- cin >> oper;
- }
- if (oper == 1) //map
- {
- cout << "Choose the map function: \n1 - multiply by 3 \n2 - add (2 + 3i) \n3 - mul by 2 + (3 + 4i)" << endl;
- int cond;
- cin >> cond;
- switch (cond) {
- case 1: {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<Complex> tree(data);
- cout << tree.map<Complex>(mapC1).toString(travese) << endl;
- }
- break;
- case 2: {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<Complex> tree(data);
- cout << tree.map<Complex>(mapC2).toString(travese) << endl;
- }
- break;
- case 3: {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<Complex> tree(data);
- cout << tree.map<Complex>(mapC3).toString(travese) << endl;
- }
- break;
- default: {
- cout << "What are you doing? Try again!" << endl;
- cin >> cond;
- }
- }
- } else if (oper == 2) //where
- {
- cout << "Choose the where function: \n1 - |Z| == 25 \n2 - |Z| > 11 \n3 - |Z| < 30" << endl;
- int cond;
- cin >> cond;
- switch (cond) {
- case 1: {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<Complex> tree(data);
- cout << tree.where(whereC1).toString(travese) << endl;
- }
- break;
- case 2: {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<Complex> tree(data);
- cout << tree.where(whereC2).toString(travese) << endl;
- }
- break;
- case 3: {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<Complex> tree(data);
- cout << tree.where(whereC3).toString(travese) << endl;
- }
- break;
- default: {
- cout << "What are you doing? Try again!" << endl;
- cin >> cond;
- }
- }
- } else if (oper == 3) //merging
- {
- cout << "Enter string of numbers to first tree" << endl;
- cin >> data;
- Tree<Complex> tree1(data);
- cout << "Enter string of numbers to second tree" << endl;
- cin >> data2;
- Tree<Complex> tree2(data2);
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<Complex> treeRes = tree1 + tree2;
- cout << treeRes.toString(travese) << endl;
- } else if (oper == 4) // retrieval
- {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter a wanted element" << endl;
- Complex element;
- cin >> element;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<Complex> tree(data);
- cout << tree.extract(element).toString(travese) <<endl;
- } else if (oper == 5) // search subtree
- {
- //хер его знает
- } else if (oper == 6) // search an element
- {
- cout << "Enter string of numbers" << endl;
- cin >> data;
- cout << "Enter a wanted element" << endl;
- Complex element;
- cin >> element;
- cout << "Enter the way of traverse" << endl;
- cin >> travese;
- Tree<Complex> tree(data);
- cout << boolalpha << tree.containsElement(element) << endl;
- }
- }else if (type == 4)
- {
- cout << "- Hey. I got the blue dye.\n - No, we are not allowed to use dye's. That's against the rules.\n - Gonna do it\n -NO NO NO GOD DAMN IT!!!" << endl;
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement