Posted By

Elmax on 01/13/14


Tagged


Versions (?)

Main


 / Published in: C++
 

Main

  1. #include <iostream>
  2. #include "bs_polje.h"
  3. //#include "bs_pokazivac.h"
  4. #include "opcenito.h"
  5.  
  6. using namespace std;
  7.  
  8. int main( void ){
  9.  
  10. cout << "1. Binarno stablo\n2. Opcenito stablo (prvo dijete - sljedeci brat)\n\n";
  11.  
  12. int Q; cin >> Q;
  13.  
  14. switch ( Q ){
  15. case 1:{
  16. _tree *BT = initBT( 1, BT );
  17.  
  18. // Korijen stabla
  19. cout << "Korijen stabla: " << rootBT( BT ) << "\n\n";
  20.  
  21. // Dodavanje cvorova
  22. cout << "Dodajem lijevo dijete cvoru 1...\n"; createLeftBT( 2, find( 1, BT ), BT );
  23. cout << "Dodajem desno dijete cvoru 1...\n"; createRightBT( 3, find( 1, BT ), BT );
  24. cout << "Dodajem lijevo dijete cvoru 3...\n"; createLeftBT( 4, find( 3, BT ), BT );
  25. cout << "Dodajem desno dijete cvoru 3...\n"; createRightBT( 5, find( 3, BT ), BT );
  26. cout << "Dodajem lijevo dijete cvoru 2..\n\n"; createLeftBT( 6, find( 2, BT ), BT );
  27.  
  28. // Ispis roditelja
  29. cout << "Roditelj cvora 2: " << labelBT( parentBT( find( 2, BT ), BT ), BT ) << "\n";
  30. cout << "Roditelj cvora 4: " << labelBT( parentBT( find( 4, BT ), BT ), BT ) << "\n\n";
  31.  
  32. // Promjena labele
  33. cout << "Promjena oznake na cvoru 5 u oznaku 10...\n"; changeLabelBT( 10, find( 5, BT ), BT );
  34. cout << "Oznaka cvora 5: " << labelBT( find( 10, BT ), BT ) << "\n\n";
  35.  
  36. // Brisanje cvora
  37. cout << "Brisem cvor 2...\n"; deleteBT( find( 2, BT ), BT );
  38. cout << "Oznaka cvora 2: " << labelBT( find( 2, BT ), BT ) << "\n";
  39. cout << "Oznaka cvora 6: " << labelBT( find( 6, BT ), BT ) << "\n\n";
  40.  
  41. break;
  42. }
  43.  
  44. case 2:{
  45. _treeT *T = initT( 1, T );
  46.  
  47. scanf( "%d%d", &N, &K );
  48.  
  49. for ( int i = 0; i < K; ++i ){
  50. int a, b; scanf( "%d%d", &a, &b );
  51. createT( b, a, T );
  52. }
  53.  
  54. cout << "Prije brisanja cvora: \n";
  55. output( T );
  56.  
  57. deleteT( 4, T );
  58.  
  59. cout << "\n\nNakon brisanja cvora 4: \n";
  60. output( T );
  61.  
  62. changeLabelT( 20, 1, T );
  63.  
  64. cout << "Promjena oznake cvora 1 u 10: \n";
  65. output( T );
  66.  
  67. break;
  68. }
  69. }
  70.  
  71. return 0;
  72. }

Report this snippet  

You need to login to post a comment.