4eyes4u

Untitled

Jan 16th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. int pojav[100000], red[10000], m;
  2.  
  3. void ntiNivo (int n, cvor *root, int &m)
  4. {
  5.     if (root!=NULL)
  6.     {
  7.         if (n)
  8.         {
  9.             ntiNivo(n-1, root->l, m);
  10.             ntiNivo(n-1, root->r, m);
  11.         }
  12.         else
  13.         {
  14.             pojav[root->val]++;
  15.             red[m++]=root->val;
  16.         }
  17.     }
  18. }
  19.  
  20. int dubina (cvor *root)
  21. {
  22.     if (root==NULL) return -1;
  23.     else return 1+max(dubina(root->l), dubina(root->r));
  24. }
  25.  
  26. void ispisi (int &m)
  27. {
  28.     int d=dubina(root);
  29.     for (int i=0;i<d;i++)
  30.     {
  31.         ntiNivo(i, root, m);
  32.         for (int j=0;j<m;j++) printf ("%d %d\n", red[j], pojav[red[j]]);
  33.         for (int j=0;j<m;j++) pojav[red[j]]=0;
  34.         m=0;
  35.         printf ("\n");
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment