opcenito stablo - glavni program


/ Published in: C++
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #include <windows.h>
  2. #include <iostream>
  3.  
  4. #define MAX_DULJINA 10
  5. #define IZLAZ -1
  6. #define MAX_VELICINA_POLJA 18
  7. #define RAZMAK_X 5
  8. #define RAZMAK_Y 2
  9.  
  10. #include "ostablo.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 ispisi_sve(node n,tree * stablo){
  22. node cvor = FirstChildT(n, stablo);
  23. cout << " " << LabelT(n, stablo) << endl;
  24. while(cvor!=IZLAZ){
  25. ispisi_sve(cvor, stablo);
  26. cvor=NextSiblingT(cvor, stablo);
  27. }
  28. }
  29. int prebroji(node n,tree * stablo){
  30. int brojac=0;
  31. node cvor = FirstChildT(n, stablo);
  32. while(cvor!=IZLAZ){
  33. brojac++;
  34. cvor = NextSiblingT(cvor, stablo);
  35. }
  36. return brojac;
  37. }
  38. void nacrtaj(int x,int y,node n,tree * stablo){
  39. int pomak = prebroji(n, stablo);
  40. node cvor = FirstChildT(n, stablo);
  41. x-=(pomak*pomak);
  42. gotoxy(x,y);
  43. cout << LabelT(n, stablo);
  44. y+=RAZMAK_Y;
  45. while(cvor!=IZLAZ){
  46. x+=RAZMAK_X;
  47. nacrtaj(x-pomak*4,y,cvor, stablo);
  48. cvor = NextSiblingT(cvor, stablo);
  49. }
  50. }
  51.  
  52. int main(){
  53. tree *stablo;
  54. stablo=InitT("0",stablo);
  55.  
  56. int cvor1, i=1, izbor, minus=0;
  57. char str[10];
  58. char error[MAX_DULJINA];
  59. strcpy(error,"Greska ");
  60.  
  61. do{
  62. system("cls");
  63. cout<<"---------------------------"<<endl;
  64. cout<<" 1. Dodaj element"<<endl;
  65. cout<<" 2. Ispis stabla"<<endl;
  66. cout<<" 3. Obrisi vrijednost"<<endl;
  67. cout<<" 9. Izlaz"<<endl;
  68. cout<<"---------------------------"<<endl;
  69. cin >> izbor;
  70. system("cls");
  71. cout<<"\n\n";
  72. switch(izbor){
  73. case 1: do{
  74. gotoxy(0,0);
  75. cout << "> "; cin >> cvor1;
  76. system("cls");
  77. if(cvor1!=-1 && cvor1<i-minus){
  78. itoa(i++,str,10);
  79. if(CreateT(str,cvor1,stablo)){
  80. gotoxy(1,1);
  81. strcat(error,str);
  82. cout << error << endl;
  83. strcpy(error,"Greska ");
  84. }
  85. nacrtaj(60,2,RootT(stablo), stablo);
  86. }
  87. }while(cvor1!=-1);
  88. nacrtaj(60,2,RootT(stablo), stablo);
  89. break;
  90. case 2: ispisi_sve(0,stablo);
  91. break;
  92. case 3: nacrtaj(60,2,RootT(stablo),stablo);
  93. gotoxy(0,0); cout <<"B> "; cin >> cvor1;
  94. minus+=prebroji(cvor1, stablo);
  95. DeleteT(cvor1, stablo);
  96. system("cls");
  97. nacrtaj(60,2,RootT(stablo),stablo);
  98. }
  99. cout<<"\n\n";
  100. system("pause");
  101. }while(izbor!=9);
  102. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.