hopingsteam

Problema BiArbore

Jan 23rd, 2021
633
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include    <iostream>
  2. #include    <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream fin("biarbore.in");
  7. ofstream fout("biarbore.out");
  8.  
  9. struct nod
  10. {
  11.     int valoare;
  12.     nod *left, *right;
  13. };
  14.  
  15. nod *radacina;
  16.  
  17. void citire(nod *&nodeParam)
  18. {
  19.     nod *newNode = new nod;
  20.     int nr;
  21.     if(fin >> nr && nr != 0)
  22.     {
  23.         // cout << "[!!]: Am citit: " << nr << "\n";
  24.         newNode->valoare = nr;
  25.         newNode->left = NULL;
  26.         newNode->right = NULL;
  27.  
  28.         if(nodeParam == NULL)
  29.             nodeParam = newNode;
  30.  
  31.         citire(newNode->left);
  32.         citire(newNode->right);
  33.     }
  34. }
  35.  
  36. void parcurgere(nod *nodeCrt)
  37. {
  38.     if(nodeCrt != NULL)
  39.     {
  40.         // cout << "Nodul: " << nodeCrt->valoare << "\n";
  41.  
  42.         // cout << "[!!]: Left Child: ";
  43.         parcurgere(nodeCrt->left);
  44.  
  45.         // cout << "[!!]: Right Child: ";
  46.         parcurgere(nodeCrt->right);
  47.  
  48.         // cout << "\n\n";
  49.     }
  50. }
  51.  
  52. int main()
  53. {
  54.     citire(radacina);
  55.     // parcurgere(radacina);
  56.     fout << radacina->left->valoare << " " << radacina->right->valoare;
  57.     return 0;
  58. }
  59.  
RAW Paste Data