#include<iostream>
#include<fstream>
#include<cstring>
#include<chrono>
using namespace std;
class BST {
struct node {
string data;
int ilosc;
node* left;
node* right;
};
int counter = 0;
int maxdepth=0;
string randsearch="";
node* root;
node* makeEmpty(node* t) {
if(t == NULL)
return NULL;
{
makeEmpty(t->left);
makeEmpty(t->right);
delete t;
}
return NULL;
}
node* insert(string x, int ile, node* t)
{
if(t == NULL)
{
t = new node;
t->data = x;
t->ilosc = ile;
t->left = t->right = NULL;
}
else if(x < t->data)
t->left = insert(x, ile, t->left);
else if(x > t->data)
t->right = insert(x, ile, t->right);
else if(x == t->data){
t->ilosc++;
// cout<<t->ilosc<<" ";
}
return t;
}
void inorder(node* t) {
if(t == NULL)
return;
inorder(t->left);
cout << t->data << " "<<endl;
inorder(t->right);
}
node* find(node* t, string x) {
counter++;
if(t == NULL)
{
cout<<"brak slowa"<<endl;
return NULL;
}
else if (x < t->data)
return find(t->left, x);
else if(x > t->data)
return find(t->right, x);
else if(x == t->data)
{
cout<<t->data<<" jest "<<t->ilosc<<" razy"<<endl;
}
return t;
}
node* randnod(node* root) {
srand(time(0));
int counte = rand() % (2);
if (!root)
cout<<"no";
else
cout<<root->data;
}
node* maxDepth(node* node, int x)
{
if (node == NULL)
{
if(x>maxdepth)maxdepth=x;
return 0;
}
else
{
x++;
maxDepth(node->left, x);
maxDepth(node->right, x);
}
}
public:
BST() {
root = NULL;
}
~BST() {root = makeEmpty(root);}
void insert(string x, int ile) {root = insert(x, ile, root);}
// void remove(int x) {root = remove(x, root);}
void display() {
inorder(root);
cout << endl;}
void search(string x) {find(root, x);}
void insertow() {cout<<"Znaleziono wykonujac "<<counter<<" Operacji"<<endl;}
int maxDepth(node* node)
{
if (node == NULL)
return 0;
else
{
int lDepth = maxDepth(node->left);
int rDepth = maxDepth(node->right);
if (lDepth > rDepth)
return(lDepth + 1);
else return(rDepth + 1);
}
}
void depth(){int x=0;
root = maxDepth(root, x);cout<<maxdepth<<endl;}
};
int main() {
fstream tekst;
BST t;
tekst.open("joyland.txt", ios::in);
string slowo;
int ile=1;
auto t1 = std::chrono::high_resolution_clock::now();
while(tekst >> slowo){t.insert(slowo, 1);}
auto t2 = std::chrono::high_resolution_clock::now();
double durat = std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count();
cout<<"W czasie "<<durat<<" mikrosekund"<<endl;
tekst.close();
// t.display();
cout<<"Szukanie liczb: (wpisz 'stop' aby przerwac i wyswietlic wysokosc drzewa)"<<endl;
while(true)
{
string szukamy;
cout<<"Co mam znalezc?"<<endl;
cin>>szukamy;
if(szukamy=="stop") break;
t.search(szukamy);
}
t.insertow();
cout << "Najwieksza wysokosc drzewa: ";
t.depth();
return 0;
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}