Dzień dobry, dostałem kilka zadań do wykonania które zrobiłem, jednak obawiam się że mimo dobrych wyników troche to zbyt skomplikowałem. Czy mógłbym prosić o ocene napisanego kodu i rady co moge poprawić?
i mój kod:
Tree::Tree(string name)
{
tree_name = name;
actual_position = 0;
}
Tree::Tree(string name, int position)
{
tree_name = name;
actual_position = position + 1;
}
int Tree::GetSubCount()
{
return next_branch.size();
}
int Tree::GetAllSubCount()
{
int return_value = 0;
for(int i = 0; i < next_branch.size(); i++)
{
return_value += next_branch[i]->GetAllSubCount();
}
return_value += next_branch.size();
return return_value;
}
void Tree::Del(int branch_number)
{
vector <Tree*> help_vector;
for(int i = 0; i < next_branch.size(); i++)
{
if(i != branch_number)
help_vector.push_back(next_branch[i]);
}
delete(next_branch[branch_number]);
next_branch.pop_back();
next_branch.swap(help_vector);
}
Tree* Tree::AddSub(string name)
{
Tree* branch = new Tree (name, actual_position);
next_branch.push_back(branch);
return next_branch.back();
}
void Tree::print(int branch_number, bool numeration)
{
cout << tree_name << endl;
for(int i = 0; i < next_branch.size(); i++)
{
if(numeration)
cout << i+1;
next_branch[i]->print_next_branch(branch_number,numeration, to_string(i+1), actual_position+1);
}
}
int Tree::print_next_branch(int branch_number, bool numeration, string numbers, int actual_position)
{
cout << " " << tree_name << endl;
string next_number;
for(int i = 0; i < next_branch.size(); i++)
{
next_number = numbers;
next_number +=".";
next_number += to_string(i+1);
for(int i = 0; i < actual_position; i++)
{
cout << " ";
}
if(numeration)
cout << next_number;
next_branch[i]->print_next_branch(branch_number, numeration, next_number, actual_position+1);
}
}
Tree::~Tree()
{
for(int i = 0; i < next_branch.size(); i++)
{
delete(next_branch[i]);
}
}