Return to Snippet

Revision: 38711
at January 6, 2011 08:13 by masrnec


Initial Code
#include <windows.h>
#include <iostream>

#define MAX_DULJINA          10
#define IZLAZ               -1
#define MAX_VELICINA_POLJA   18
#define RAZMAK_X              5
#define RAZMAK_Y              2

#include "ostablo.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 ispisi_sve(node n,tree * stablo){
    node cvor = FirstChildT(n, stablo);
    cout << "  " << LabelT(n, stablo) << endl;
    while(cvor!=IZLAZ){
        ispisi_sve(cvor, stablo);
        cvor=NextSiblingT(cvor, stablo);
    }
}
int prebroji(node n,tree * stablo){
    int brojac=0;
    node cvor = FirstChildT(n, stablo);
    while(cvor!=IZLAZ){
          brojac++;
          cvor = NextSiblingT(cvor, stablo);
    }
    return brojac;
}
void nacrtaj(int x,int y,node n,tree * stablo){
    int pomak = prebroji(n, stablo);
    node cvor = FirstChildT(n, stablo);
    x-=(pomak*pomak);
    gotoxy(x,y); 
    cout << LabelT(n, stablo);
    y+=RAZMAK_Y;
    while(cvor!=IZLAZ){ 
        x+=RAZMAK_X;
        nacrtaj(x-pomak*4,y,cvor, stablo);
        cvor = NextSiblingT(cvor, stablo);
    }
}

int main(){
    tree *stablo;
    stablo=InitT("0",stablo);
    
    int cvor1, i=1, izbor, minus=0;
    char str[10];
    char error[MAX_DULJINA];
    strcpy(error,"Greska ");
    
    do{
        system("cls");
        cout<<"---------------------------"<<endl;
        cout<<" 1. Dodaj element"<<endl;
        cout<<" 2. Ispis stabla"<<endl;
        cout<<" 3. Obrisi vrijednost"<<endl; 
        cout<<" 9. Izlaz"<<endl;
        cout<<"---------------------------"<<endl;
        cin >> izbor;
        system("cls");
        cout<<"\n\n";
        switch(izbor){
            case 1:  do{
                         gotoxy(0,0);
                         cout << "> ";  cin >> cvor1;
                         system("cls");
                         if(cvor1!=-1 && cvor1<i-minus){
                             itoa(i++,str,10);
                             if(CreateT(str,cvor1,stablo)){
                                  gotoxy(1,1);
                                  strcat(error,str);
                                  cout << error << endl;
                                  strcpy(error,"Greska ");
                             }
                             nacrtaj(60,2,RootT(stablo), stablo);  
                         }          
                     }while(cvor1!=-1);
                     nacrtaj(60,2,RootT(stablo), stablo);
               break;
            case 2: ispisi_sve(0,stablo);
               break;
            case 3: nacrtaj(60,2,RootT(stablo),stablo);
                    gotoxy(0,0); cout <<"B> "; cin >> cvor1;
                    minus+=prebroji(cvor1, stablo);
                    DeleteT(cvor1, stablo);
                    system("cls");
                    nacrtaj(60,2,RootT(stablo),stablo);
        } 
        cout<<"\n\n";
        system("pause");
    }while(izbor!=9);
}

Initial URL


Initial Description


Initial Title
opcenito stablo - glavni program

Initial Tags


Initial Language
C++