Mój problem polega na tym że kod działa ale po wybraniu pierwszej opcji nic się nie dzieje tak jakby się coś ładowało.Pierwszy raz piszę drzewo więc sugerowałem się dość mocno http://eduinf.waw.pl/inf/alg/001_search/0115.php
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
string cr,cl,cp;
struct node
{
int key;
node* left , *right, * up;
};
void printBT(string sp, string sn, node * v)
{
string s;
if(v)
{
s = sp;
if(sn == cr) s[s.length() - 2] = ' ';
printBT(s + cp, cr, v->right);
s = s.substr(0,sp.length()-2);
cout << s << sn << v->key << endl;
s = sp;
if(sn == cl) s[s.length() - 2] = ' ';
printBT(s + cp, cl, v->left);
}
}
void add_node(node *&root,int data)
{
node *w,*p;
w=new node;
w->left = w->right =NULL;
w->key=data;
p=root;
if(!p)
root=w;
else
{
while(true)
if(data<p->key)
{
if (!p->left)
{
p->left=w;
break;
}
else p=p->left;
}
else
{
if (!p->right)
{
p->right =w;
break;
}
else p=p->right;
}
}
w->up=p;
}
int main()
{
srand(time(NULL));
int wybor;
node *root=new node;
cr = cl = cp = " ";
cr[0] = 218; cr[1] = 196;
cl[0] = 192; cl[1] = 196;
cp[0] = 179;
do
{
cout<<"1.Dodawanie wezla o losowej wartosci do drzewa(add_node)"<<endl;;
cout<<"2.Koniec programu"<<endl;
cout<<"Odpowiedz:";
cin>>wybor;
switch(wybor)
{
case 1:
{
int data;
data=rand()%100+1;
cout<<data<<endl;
add_node(root,data);
printBT("","",root);
break;
}
}
}while(wybor!=2);
return 0;
}