## Posted By

sanovinic on 01/06/11

# â€žprvo dijete, sljedeÄ‡i bratâ€œ

/ Published in: C++

`#include <windows.h>#include <iostream> #define MAX_D 10#define LAMBD -1#define M_V_P 18#define R_X 5#define R_Y 2 #include "ostablo1.h" using namespace std; void gotoxy(int x,int y){    COORD coord;    coord.X=x;        coord.Y=y;    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord); } void ispis(node n,tree *t){    node cvor = FirstChildT(n,t);    cout << "  " << LabelT(n,t) << endl;    while(cvor!=LAMBD){        ispis(cvor,t);        cvor=NextSiblingT(cvor,t);    }}int broji(node n,tree *t){    int br=0;    node cvor = FirstChildT(n,t);    while(cvor!=LAMBD){          br++;          cvor = NextSiblingT(cvor,t);    }    return br;}void crtaj(int x,int y,node n,tree *t){    int pomak = broji(n,t);    node cvor = FirstChildT(n,t);    x-=(pomak*pomak);    gotoxy(x,y);     cout << LabelT(n,t);    y+=R_Y;    while(cvor!=LAMBD){         x+=R_X;        crtaj(x-pomak*4,y,cvor,t);        cvor = NextSiblingT(cvor,t);    }} int main(){    tree *t;    t=InitT("0",t);     int c, i=1, izb, minus=0;    char str[10];    char greska[MAX_D];    strcpy(greska,"Greska ");     do{        system("cls");        printf(" 1. Dodaj element u stablo\n");        printf(" 2. Ispis stabla\n");        printf(" 3. Obrisi vrijednost iz stabla\n");        printf(" 9.Izlaz ");        printf("\n--------------------\n Izbor : ");        cin >> izb;        system("cls");        printf("\n\n");        switch(izb){            case 1:  do{                         gotoxy(0,0);                         cout << "> ";  cin >> c;                         system("cls");                         if(c!=-1 && c<i-minus){                             itoa(i++,str,10);                             if(CreateT(str,c,t)){                                  gotoxy(1,1);                                  strcat(greska,str);                                  cout << greska << endl;                                  strcpy(greska,"Greska ");                             }                             crtaj(60,2,RootT(t),t);                           }                               }while(c!=-1);                     crtaj(60,2,RootT(t),t);               break;            case 2: ispis(0,t);               break;            case 3: crtaj(60,2,RootT(t),t);                    gotoxy(0,0); cout <<"Brisi : "; cin >> c;                    minus+=broji(c,t);                    DeleteT(c,t);                    system("cls");                    crtaj(60,2,RootT(t),t);        }         printf("\n\n");        system("pause>NUL");    }while(izb!=9);}`