I have made a class of tree with 12 children. I insert the data in the tree systematically, Like first root, then first children , second children, and so on.
I am having problems in coding this function.
I am sharing with you, whatever i have managed so far.
here is the code, Kindly help with the insert function.
Code:
class Node
{
public:
char data[25];
Node *next[12];
};
class Tree
{
Node* root;
public:
Tree()
{
root=NULL;
}
void insert(char a[25])
{
Node* temp = new Node();
strcpy(temp->data,a );
//temp = root;
for (int i = 1; i < 13; i ++)
temp->next[i] = NULL;
for (int i = 1; i <13; i ++)
{
if (temp->next[i] == NULL)
strcpy(temp->data,a);
//break;
return;
}
for (int i= 1; i < 13; i++)
{
temp = temp->next[i];
for (int i = 1; i <13; i ++)
{
if (temp->next[i] == NULL)
strcpy(temp->data,a);
//break;
return;
}
temp = root;
}
for (int i= 1; i < 13; i++)
{
temp = temp->next[i]->next[i];
for (int i = 1; i <13; i ++)
{
if (temp->next[i] == NULL)
strcpy(temp->data,a);
return;
}
temp = root;
}
}
void treeSearch(char a[25])
{
Node* temp;
temp = root;
bool flag = false;
for ( int i = 1; i < 13; i++ )
{
if (strcmp(temp->next[i]->data,a)== 0)
{
flag = true;
cout<<"Found";
break;
}
}
if ( flag == false)
{
for ( int i = 1; i < 13; i++ )
{
temp = temp->next[i];
for (int i = 1; i < 13; i++ )
{
if (strcmp(temp->next[i]->data,a)== 0)
{
flag = true;
cout<<"Found";
break;
}
}
temp = root;
}
for ( int i = 1; i < 13; i++ )
{
temp = temp->next[i]->next[i];
for (int i = 1; i < 13; i++ )
{
if (strcmp(temp->next[i]->data,a)== 0)
{
flag = true;
cout<<"Found";
break;
}
}
temp = root;
}
}
}