Drzewo binarne

0

Jak można dodać albo odjąć poziom drzewa w kodzie który napisałem? To drzewo ma 4 poziomy a jak np. dodać 5?

#include <iostream>

int dane[15];
bool pusty[15];

void gotoxy(int x, int y)
{
    COORD c;
    c.X=x-1;
    c.Y=y-1;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);
}

void wyswietl_drzewo()
{
    system("CLS");
    gotoxy(40,1);
    if (pusty[1]==true) cout<<"_";
    else cout<<dane[1];
    gotoxy(20,4);
    if (pusty[2]==true) cout<<"_";
    else cout<<dane[2];
    gotoxy(60,4);
    if (pusty[3]==true) cout<<"_";
    else cout<<dane[3];
    gotoxy(10,6);
    if (pusty[4]==true) cout<<"_";
    else cout<<dane[4];
    gotoxy(30,6);
    if (pusty[5]==true) cout<<"_";
    else cout<<dane[5];
    gotoxy(50,6);
    if (pusty[6]==true) cout<<"_";
    else cout<<dane[6];
    gotoxy(70,6);
    if (pusty[7]==true) cout<<"_";
    else cout<<dane[7];
    gotoxy(5,10);
    if (pusty[8]==true) cout<<"_";
    else cout<<dane[8];
    gotoxy(15,10);
    if (pusty[9]==true) cout<<"_";
    else cout<<dane[9];
    gotoxy(25,10);
    if (pusty[10]==true) cout<<"_";
    else cout<<dane[10];
    gotoxy(35,10);
    if (pusty[11]==true) cout<<"_";
    else cout<<dane[11];
    gotoxy(45,10);
    if (pusty[12]==true) cout<<"_";
    else cout<<dane[12];
    gotoxy(55,10);
    if (pusty[13]==true) cout<<"_";
    else cout<<dane[13];
    gotoxy(65,10);
    if (pusty[14]==true) cout<<"_";
    else cout<<dane[14];
    gotoxy(75,10);
    if (pusty[15]==true) cout<<"_";
    else cout<<dane[15];
    cout<<endl<<endl<<endl;
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15);
}
5

Och tak samo jak to teraz zrobiłeś. Copy & paste. Innej drogi nie ma.

edit: a tak zupełnie poważnie to napisz to zupełnie od nowa. Stosujac struktury danych do przechowywania tego drzewa.

1 użytkowników online, w tym zalogowanych: 0, gości: 1