Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int pojav[100000], red[10000], m;
- void ntiNivo (int n, cvor *root, int &m)
- {
- if (root!=NULL)
- {
- if (n)
- {
- ntiNivo(n-1, root->l, m);
- ntiNivo(n-1, root->r, m);
- }
- else
- {
- pojav[root->val]++;
- red[m++]=root->val;
- }
- }
- }
- int dubina (cvor *root)
- {
- if (root==NULL) return -1;
- else return 1+max(dubina(root->l), dubina(root->r));
- }
- void ispisi (int &m)
- {
- int d=dubina(root);
- for (int i=0;i<d;i++)
- {
- ntiNivo(i, root, m);
- for (int j=0;j<m;j++) printf ("%d %d\n", red[j], pojav[red[j]]);
- for (int j=0;j<m;j++) pojav[red[j]]=0;
- m=0;
- printf ("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment