## Posted By

sanovinic on 01/06/11

# „prvo dijete, sljedeći brat“

/ Published in: C++

1. #include <windows.h>
2. #include <iostream>
3.
4. #define MAX_D 10
5. #define LAMBD -1
6. #define M_V_P 18
7. #define R_X 5
8. #define R_Y 2
9.
10. #include "ostablo1.h"
11.
12. using namespace std;
13.
14. void gotoxy(int x,int y){
15. COORD coord;
16. coord.X=x;
17. coord.Y=y;
18. SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
19. }
20.
21. void ispis(node n,tree *t){
22. node cvor = FirstChildT(n,t);
23. cout << " " << LabelT(n,t) << endl;
24. while(cvor!=LAMBD){
25. ispis(cvor,t);
26. cvor=NextSiblingT(cvor,t);
27. }
28. }
29. int broji(node n,tree *t){
30. int br=0;
31. node cvor = FirstChildT(n,t);
32. while(cvor!=LAMBD){
33. br++;
34. cvor = NextSiblingT(cvor,t);
35. }
36. return br;
37. }
38. void crtaj(int x,int y,node n,tree *t){
39. int pomak = broji(n,t);
40. node cvor = FirstChildT(n,t);
41. x-=(pomak*pomak);
42. gotoxy(x,y);
43. cout << LabelT(n,t);
44. y+=R_Y;
45. while(cvor!=LAMBD){
46. x+=R_X;
47. crtaj(x-pomak*4,y,cvor,t);
48. cvor = NextSiblingT(cvor,t);
49. }
50. }
51.
52. int main(){
53. tree *t;
54. t=InitT("0",t);
55.
56. int c, i=1, izb, minus=0;
57. char str[10];
58. char greska[MAX_D];
59. strcpy(greska,"Greska ");
60.
61. do{
62. system("cls");
63. printf(" 1. Dodaj element u stablo\n");
64. printf(" 2. Ispis stabla\n");
65. printf(" 3. Obrisi vrijednost iz stabla\n");
66. printf(" 9.Izlaz ");
67. printf("\n--------------------\n Izbor : ");
68. cin >> izb;
69. system("cls");
70. printf("\n\n");
71. switch(izb){
72. case 1: do{
73. gotoxy(0,0);
74. cout << "> "; cin >> c;
75. system("cls");
76. if(c!=-1 && c<i-minus){
77. itoa(i++,str,10);
78. if(CreateT(str,c,t)){
79. gotoxy(1,1);
80. strcat(greska,str);
81. cout << greska << endl;
82. strcpy(greska,"Greska ");
83. }
84. crtaj(60,2,RootT(t),t);
85. }
86. }while(c!=-1);
87. crtaj(60,2,RootT(t),t);
88. break;
89. case 2: ispis(0,t);
90. break;
91. case 3: crtaj(60,2,RootT(t),t);
92. gotoxy(0,0); cout <<"Brisi : "; cin >> c;
93. minus+=broji(c,t);
94. DeleteT(c,t);
95. system("cls");
96. crtaj(60,2,RootT(t),t);
97. }
98. printf("\n\n");
99. system("pause>NUL");
100. }while(izb!=9);
101. }

You need to login to post a comment.