Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <assert.h>
- #include <ctype.h>
- //#include "tree.h"
- #define LEFT 0
- #define RIGHT 1
- int p,k;
- int maior= -99999999;
- typedef struct tnode *Tree;
- typedef struct tnode {
- int value;
- Tree child [2];
- Tree parent;
- } Tree_node;
- /*---------------------------------*/
- void tree_put (Tree *t, int x, int b); /* pre !tree_parent (t); */
- Tree tree_cons (int x, Tree t, Tree u); /* pre !tree_empty (t) <= !tree_parent (t), !tree_empty (u) <= !tree_parent (u); */
- Tree tree_cons_single (int x, Tree t, int b); /* pre !tree_parent (t); */
- int tree_empty (Tree t);
- int tree_is_leaf (Tree t); /* pre !tree_empty (t) */
- int tree_size (Tree t);
- int tree_count (Tree t, int x);
- int tree_levels (Tree t);
- int tree_height (Tree t); /* pre !tree_empty (t) */
- int tree_depth (Tree t); /* pre !tree_empty (t) */
- int tree_degree (Tree t); /* pre !tree_empty (t); */
- int tree_side (Tree t); /* pre !tree_empty (t), !tree_empty (p->parent) */
- int tree_root (Tree t); /* pre !tree_empty (t); */
- void tree_swap (Tree t, int b, Tree *u); /* pre !tree_empty (t), !tree_empty (*u) <= !tree_parent (*u); */
- // Swaps b child of t with u
- Tree tree_insert (Tree t, int x, int right1, int right2); /* pre !tree_empty (t); */
- // Inserts a new node with value x as the right1 child of the tree t,
- // linking the current right1 child as the right2 child of the new node.
- // Returns the tree at the newly inserted node.
- void tree_remove (Tree *t); /* pre !tree_empty (t), tree_degree (t ) <= 1; */
- int tree_has (Tree t, int x);
- Tree tree_find (Tree t, int x);
- void tree_free (Tree *s);
- int tree_ok (Tree t);
- void tree_write_parenthetically (FILE *f, Tree t);
- void tree_writeln_parenthetically (FILE *f, Tree t);
- void tree_write_star (FILE *f, Tree t);
- void tree_writeln_star (FILE *f, Tree t);
- void tree_write (FILE *f, char *fmt, Tree t);
- void tree_writeln (FILE *f, char *fmt, Tree t);
- void tree_write_indented (FILE *f, char *fmt, Tree t, int tab, int margin);
- void tree_write_indented_star (FILE *f, char *fmt, Tree t, int tab, int margin);
- void tree_write_indented_prefix (FILE *f, char *fmt, Tree t, int tab, int margin);
- void tree_write_diagram (FILE *f, char *fmt, Tree t, int tab, int margin);
- int ints_from_tree (Tree t, int *v);
- Tree tree_from_ints (int *v, int n);
- Tree tree_from_string (char **s);
- void tree_to_string (Tree t, char **s);
- Tree tree_next (Tree t);
- Tree tree_previous (Tree t);
- Tree tree_next2 (Tree t, int b);
- Tree tree_start (Tree t);
- Tree tree_finish (Tree t);
- void tree_prefix (Tree t, void p (int));
- void tree_infix (Tree t, void p (int));
- void tree_postfix (Tree t, void p (int));
- void tree_walk_directly (Tree t, void p (int));
- void tree_walk_reversely (Tree t, void p (int));
- int tree_fill_numbers (Tree t, int *v);
- void tree_walk_directly_empty_recursive (Tree t);
- void tree_walk_directly_empty_iterative (Tree t);
- Tree tree_promote (Tree t);
- #undef max
- #undef min
- int max (int x, int y);
- int min (int x, int y);
- /*---------------------------*/
- int max (int x, int y)
- {
- return x > y ? x : y;
- }
- int min (int x, int y)
- {
- return x < y ? x : y;
- }
- int child_ok (Tree t)
- {
- int result = 1;
- int i;
- assert (t != NULL);
- for (i = 0; result && i < 2; i++)
- result = t->child [i] == NULL || (t->child [i]->parent == t && child_ok (t->child[i]));
- return result;
- }
- int tree_ok (Tree t)
- {
- return t == NULL || (t->parent == NULL && child_ok (t));
- }
- void tree_put (Tree *t, int x, int b)
- {
- assert (tree_ok (*t));
- assert (*t == NULL || (*t)->parent == NULL);
- *t = tree_cons_single (x, *t, b);
- assert (tree_ok (*t));
- }
- Tree tree_cons_single (int x, Tree t, int b)
- {
- assert (t == NULL || t->parent == NULL);
- return b ? tree_cons (x, NULL, t) : tree_cons (x, t, NULL);
- }
- Tree tree_cons (int x, Tree t, Tree u)
- {
- Tree result = NULL;
- assert (t == NULL || t->parent == NULL);
- assert (u == NULL || u->parent == NULL);
- result = (Tree) malloc (sizeof (Tree_node));
- result -> value = x;
- result -> child[0] = t;
- if (t != NULL)
- t -> parent = result;
- result -> child[1] = u;
- if (u != NULL)
- u -> parent = result;
- result -> parent = NULL;
- return result;
- }
- int tree_empty (Tree t)
- {
- return t == NULL;
- }
- int tree_root (Tree t)
- {
- return t->value;
- }
- int tree_is_leaf (Tree t)
- {
- assert (t != NULL);
- return t->child[0] == NULL && t->child[1] == NULL;
- }
- int tree_size (Tree t)
- {
- return t == NULL ? 0 : 1 + tree_size (t->child[0]) + tree_size (t->child[1]);
- }
- int tree_count (Tree t, int x)
- {
- return t == NULL ? 0 : (t->value == x) + tree_count (t->child[0], x) + tree_count (t->child[1], x);
- }
- int nc;
- int tree_levels (Tree t)
- {
- return t == NULL ? 0 : 1 + max (tree_levels (t->child [0]), tree_levels (t->child[1]));
- }
- int tree_height (Tree t)
- {
- return tree_levels (t) - 1;
- }
- int tree_depth (Tree t)
- {
- int result = 0;
- assert (t != NULL);
- while (t->parent != NULL)
- {
- result++;
- t = t->parent;
- }
- return result;
- }
- int tree_degree (Tree t)
- {
- assert (t != NULL);
- return (t->child[0] != NULL) + (t->child[1] != NULL);
- }
- //int tree_at_root (Tree t)
- //{
- // assert (!tree_empty (t));
- // return t->parent == NULL;
- //}
- //
- //Tree tree_child (Tree t, int b)
- //{
- // assert (!tree_empty (t));
- // return t->child [b];
- //}
- //
- //Tree tree_left (Tree t)
- //{
- // assert (!tree_empty (t));
- // return t->child [0];
- //}
- //
- //Tree tree_right (Tree t)
- //{
- // assert (!tree_empty (t));
- // return t->child [1];
- //}
- Tree tree_first_child_0 (Tree t)
- {
- assert (t != NULL);
- return t->child [0] != NULL ? t->child [0] : t->child [1];
- }
- Tree tree_first_child (Tree t)
- {
- assert (t != NULL);
- return t->child [t->child [0] == NULL];
- }
- //Tree tree_parent (Tree t)
- //{
- // assert (!tree_empty (t));
- // return t->parent;
- //}
- int tree_side (Tree t)
- {
- assert (t != NULL);
- assert (t->parent != NULL);
- return t->parent->child [1] == t;
- }
- //void tree_set_value (Tree t, int x)
- //{
- // assert (!tree_empty (t));
- // t -> value = x;
- //}
- //
- //void tree_link (Tree t, Tree *u, int b)
- //{
- // assert (t != NULL);
- // assert (t -> child[b] == NULL);
- // assert (u == NULL || (*u)->parent == NULL);
- // t->child[b] = *u;
- // if (*u != NULL)
- // (*u)->parent = t;
- // *u = NULL;
- //}
- //
- //void tree_unlink (Tree t, int b, Tree *u)
- //{
- // Tree z;
- // assert (t != NULL);
- // z = *u;
- // *u = t->child[b];
- // t->child[b] = z;
- // if (z != NULL)
- // z->parent = t;
- // if (*u == NULL)
- // (*u)->parent = NULL;
- //}
- void tree_swap (Tree t, int b, Tree *u)
- {
- Tree z;
- assert (t != NULL);
- assert (*u == NULL || (*u)->parent == NULL);
- z = *u;
- *u = t->child[b];
- t->child[b] = z;
- if (z != NULL)
- z->parent = t;
- if (*u != NULL)
- (*u)->parent = NULL;
- }
- // inserts a new node with value x as the right1 child of the tree t
- // linking the current right1 child as the right2 child of the new node.
- // return the tree whose root is the newly inserted node.
- Tree tree_insert (Tree t, int x, int right1, int right2)
- {
- Tree u = NULL;
- assert (child_ok (t));
- assert (!tree_empty (t));
- tree_swap (t, right1, &u);
- //u = tree_cons_single (x, u, right2);
- tree_put (&u, x, right2);
- tree_swap (t, right1, &u);
- assert (child_ok (t));
- return t->child[right1];
- }
- void tree_remove1 (Tree *t)
- {
- Tree z;
- Tree f;
- assert (!tree_empty (*t));
- assert (tree_degree (*t) <= 1);
- z = *t;
- f = tree_first_child (z);
- tree_writeln_star (stdout, f);
- if (z->parent == NULL)
- {
- if (f != NULL)
- f ->parent = NULL;
- *t = f;
- }
- else
- {
- int side = tree_side (z); // Is *t a right child?
- *t = f;
- z->parent->child [side] = f;
- if (f != NULL)
- f ->parent = z->parent;
- }
- free (z);
- }
- void tree_remove_version1 (Tree *t)
- {
- Tree p;
- assert (*t != NULL);
- assert (tree_degree (*t) <= 1);
- if ((p = (*t) -> parent) == NULL)
- {
- Tree z = *t;
- *t = tree_first_child (*t);
- if ((*t) != NULL)
- (*t) -> parent = NULL;
- free (z);
- }
- else
- {
- Tree u = NULL;
- int side = tree_side (*t);
- tree_swap (p, side, &u);
- tree_remove (&u);
- tree_swap (p, side, &u);
- *t = p->child [side];
- }
- }
- void tree_remove (Tree *t)
- {
- Tree p;
- assert (*t != NULL);
- assert (tree_degree (*t) <= 1);
- if ((p = (*t) -> parent) == NULL)
- {
- Tree z = *t;
- *t = tree_first_child (*t);
- if ((*t) != NULL)
- (*t) -> parent = NULL;
- free (z);
- }
- else
- {
- Tree u = NULL;
- int side = tree_side (*t);
- tree_swap (p, side, &u);
- tree_remove (&u);
- tree_swap (p, side, &u);
- *t = p;
- }
- }
- void tree_remove0 (Tree *t)
- {
- Tree z = NULL;
- Tree f = NULL;
- assert (!tree_empty (*t));
- assert (tree_degree (*t) <= 1);
- z = *t;
- f = tree_first_child (z);
- //tree_writeln_star (stdout, f);
- if (z->parent != NULL)
- z->parent->child [tree_side (z)] = f;
- if (f != NULL)
- f ->parent = z->parent;
- *t = f;
- free (z);
- }
- int tree_has (Tree t, int x)
- {
- return t != NULL && (t->value == x || tree_has (t->child[0], x) || tree_has (t->child[1], x));
- }
- Tree tree_find (Tree t, int x)
- {
- Tree result = NULL;
- if (t != NULL)
- {
- if (t->value == x)
- result = t;
- if (result == NULL)
- result = tree_find (t->child[0], x);
- if (result == NULL)
- result = tree_find (t->child[1], x);
- }
- return result;
- }
- void tree_free_here (Tree t)
- {
- if (t != NULL)
- {
- tree_free_here (t->child[0]);
- tree_free_here (t->child[1]);
- free (t);
- }
- }
- void tree_free0 (Tree *t)
- {
- tree_free_here (*t);
- *t = NULL;
- }
- void tree_free (Tree *t)
- {
- Tree z = *t;
- if (z != NULL)
- {
- tree_free_here (z->child[0]);
- tree_free_here (z->child[1]);
- free (z);
- }
- *t = NULL;
- }
- void tree_write_star (FILE *f, Tree t)
- {
- if (t == NULL)
- fprintf (f, "*");
- else
- {
- fprintf (f, "(%d", t->value);
- tree_write_star (f, t->child[0]);
- tree_write_star (f, t->child[1]);
- fprintf (f, ")");
- }
- }
- void tree_writeln_star (FILE *f, Tree t)
- {
- tree_write_star (f, t);
- fprintf (f, "\n");
- }
- void tree_write_parenthetically (FILE *f, Tree t)
- {
- fprintf (f, "(");
- if (t)
- {
- fprintf (f, "%d", t->value);
- tree_write_parenthetically (f, t->child[0]);
- tree_write_parenthetically (f, t->child[1]);
- }
- fprintf (f, ")");
- }
- void tree_writeln_parenthetically (FILE *f, Tree t)
- {
- tree_write_parenthetically (f, t);
- fprintf (f, "\n");
- }
- void tree_write (FILE *f, char *fmt, Tree t)
- {
- if (t)
- {
- tree_write (f, fmt, t->child[0]);
- fprintf (f, fmt, t->value);
- tree_write (f, fmt, t->child[1]);
- }
- }
- void tree_writeln (FILE *f, char *fmt, Tree t)
- {
- tree_write (f, fmt, t);
- fprintf (f, "\n");
- }
- void tree_write_indented (FILE *f, char *fmt, Tree t, int tab, int margin)
- {
- if (t)
- {
- tree_write_indented (f, fmt, t->child[1], tab, tab + margin);
- fprintf (f, "%*s", margin, "");
- fprintf (f, fmt, t->value);
- fprintf (f, "\n");
- tree_write_indented (f, fmt, t->child[0], tab, tab + margin);
- }
- }
- void tree_write_indented_star (FILE *f, char *fmt, Tree t, int tab, int margin)
- {
- if (t)
- {
- tree_write_indented_star (f, fmt, t->child[1], tab, tab + margin);
- fprintf (f, "%*s", margin, "");
- fprintf (f, fmt, t->value);
- fprintf (f, "\n");
- tree_write_indented_star (f, fmt, t->child[0], tab, tab + margin);
- }
- else
- fprintf (f, "%*s%s\n", margin, "", "*");
- }
- void tree_write_indented_prefix (FILE *f, char *fmt, Tree t, int tab, int margin)
- {
- if (t)
- {
- fprintf (f, "%*s", margin, "");
- fprintf (f, fmt, t->value);
- fprintf (f, "\n");
- tree_write_indented_prefix (f, fmt, t->child[0], tab, tab + margin);
- tree_write_indented_prefix (f, fmt, t->child[1], tab, tab + margin);
- }
- else
- fprintf (f, "%*s%s\n", margin, "", "-");
- }
- void tree_write_diagram (FILE *f, char *fmt, Tree t, int tab, int margin)
- {
- if (t)
- {
- tree_write_diagram (f, fmt, t->child[1], tab, tab + margin);
- fprintf (f, "%*s", margin, "");
- fprintf (f, fmt, t->value);
- fprintf (f, "\n");
- tree_write_diagram (f, fmt, t->child[0], tab, tab + margin);
- }
- else
- fprintf (f, "%*s%s\n", margin, "", "-");
- }
- void tree_to_numbers0 (Tree t, int *v, int *n)
- {
- *n = 0;
- if (t)
- {
- int n0 = 0;
- int n1 = 0;
- tree_to_numbers0 (t->child[0], v, &n0);
- v[n0] = t->value;
- tree_to_numbers0 (t->child[1], v+n0+1, &n1);
- *n = n0 + 1 + n1;
- }
- }
- int ints_from_tree (Tree t, int *v)
- {
- int result = 0;
- if (t != NULL)
- {
- int n0 = ints_from_tree (t->child[0], v);
- int n1 = ints_from_tree (t->child[1], v+n0+1);
- v[n0] = t->value;
- result = n0 + n1 + 1;
- }
- return result;
- }
- Tree tree_from_ints (int *v, int n)
- {
- return n <= 0 ? NULL : tree_cons (v[n/2], tree_from_ints (v, n/2), tree_from_ints (v+n/2+1, n-(n/2+1)));
- }
- Tree tree_next (Tree t)
- {
- assert (t != NULL);
- if (t->child [RIGHT] != NULL)
- {
- t = t->child [RIGHT];
- while (t->child [LEFT] != NULL)
- t = t->child [LEFT];
- }
- else
- {
- Tree p = t;
- t = t->parent;
- while (t != NULL && p != t->child [LEFT])
- {
- p = p->parent;
- t = t->parent;
- }
- }
- return t;
- }
- Tree tree_following (Tree t, int right)
- {
- assert (t != NULL);
- if (t->child [right] != NULL)
- {
- t = t->child [right];
- while (t->child [!right] != NULL)
- t = t->child [!right];
- }
- else
- {
- Tree p = t;
- t = t->parent;
- while (t != NULL && p != t->child [!right])
- {
- p = p->parent;
- t = t->parent;
- }
- }
- return t;
- }
- Tree tree_previous (Tree t)
- {
- return tree_following (t, LEFT);
- }
- Tree tree_start (Tree t)
- {
- assert (t != NULL);
- while (t->child [LEFT] != NULL)
- t = t->child [LEFT];
- return t;
- }
- Tree tree_finish (Tree t)
- {
- assert (t != NULL);
- while (t->child [RIGHT] != NULL)
- t = t->child [RIGHT];
- return t;
- }
- void tree_prefix (Tree t, void p (int))
- {
- if (t != NULL)
- {
- p (t->value);
- tree_prefix (t->child[0], p);
- tree_prefix (t->child[1], p);
- }
- }
- void tree_infix (Tree t, void p (int))
- {
- if (t != NULL)
- {
- tree_infix (t->child[0], p);
- p (t->value);
- tree_infix (t->child[1], p);
- }
- }
- void tree_walk_directly (Tree t, void p (int))
- {
- if (t != NULL)
- {
- tree_walk_directly (t->child[0], p);
- p (t->value);
- tree_walk_directly (t->child[1], p);
- }
- }
- void tree_walk_reversely (Tree t, void p (int))
- {
- if (t != NULL)
- {
- tree_walk_reversely (t->child[1], p);
- p (t->value);
- tree_walk_reversely (t->child[0], p);
- }
- }
- void tree_postfix (Tree t, void p (int))
- {
- if (t != NULL)
- {
- tree_postfix (t->child[0], p);
- tree_postfix (t->child[1], p);
- p (t->value);
- }
- }
- int count_digits (int n)
- {
- int result = 1;
- while (n >= 10)
- {
- n /= 10;
- result++;
- }
- return result;
- }
- Tree tree_from_string (char **s)
- {
- Tree result = NULL;
- char *p = *s;
- assert (*p == '*' || *p == '(');
- if (*p++ == '(')
- {
- int r;
- Tree t;
- Tree u;
- assert (isdigit (*p));
- sscanf (p, "%d", &r);
- p += count_digits (r);
- if (!(*p == '*' || *p == '('))
- printf (":::%s:::\n", p);
- assert (*p == '*' || *p == '(');
- t = tree_from_string (&p);
- u = tree_from_string (&p);
- assert (*p == ')');
- p++;
- result = tree_cons (r, t, u);
- }
- *s = p;
- return result;
- }
- void tree_to_string (Tree t, char **s)
- {
- char *p = *s;
- if (t == NULL)
- p += sprintf (p, "*");
- else
- {
- p += sprintf (p, "(%d", t->value);
- tree_to_string (t->child[0], &p);
- tree_to_string (t->child[1], &p);
- p += sprintf (p, ")");
- }
- *s = p;
- }
- //void tree_fill_numbers_here (Tree t, int**v)
- //{
- // int *p = *v;
- // if (t != NULL)
- // {
- // tree_fill_numbers_here (t->child[0], &p);
- // //printf ("%d\n", t->value);
- // *p++ = t->value;
- // tree_fill_numbers_here (t->child[1], &p);
- // }
- // *v = p;
- //}
- void tree_fill_numbers_here (Tree t, int**v)
- {
- if (t != NULL)
- {
- tree_fill_numbers_here (t->child[0], v);
- //printf ("%d\n", t->value);
- *(*v)++ = t->value;
- tree_fill_numbers_here (t->child[1], v);
- }
- }
- int tree_fill_numbers (Tree t, int *v)
- {
- int *p = v;
- tree_fill_numbers_here (t, &p);
- return p-v;
- }
- void tree_walk_directly_empty_recursive (Tree t)
- {
- if (t != NULL)
- {
- tree_walk_directly_empty_recursive (t->child[0]);
- tree_walk_directly_empty_recursive (t->child[1]);
- }
- }
- void tree_walk_directly_empty_iterative (Tree t)
- {
- t = tree_start (t);
- while (t != NULL)
- t = tree_next (t);
- }
- Tree tree_promote (Tree t)
- {
- int side = tree_side (t);
- Tree p = t->parent;
- t -> parent = p->parent;
- if (t->parent != NULL)
- t -> parent -> child [tree_side (p)] = t;
- p -> child [side] = t->child [!side];
- if (p -> child [side] != NULL)
- p -> child [side] -> parent = p;
- t -> child [!side] = p;
- p->parent = t;
- return t;
- }
- void int_ (int x)
- {
- if (p==1)
- {
- printf(" %d", x);
- }
- else
- {
- printf("%d", x);
- p=1;
- }
- }
- int tree_sum (Tree t)
- {
- if (t)
- {
- return t->value + tree_sum(t->child[0]) + tree_sum(t->child[1]);
- }
- else
- {
- return 0;
- }
- }
- void maximo (int x)
- {
- if (x>maior)
- {
- maior = x;
- }
- }
- int verifica_se_folha (Tree t)
- {
- return t == NULL ? 0 : t->child[0]==NULL && t->child[1]==NULL;
- }
- void imprime_folhas (Tree t)
- {
- if (t!=NULL)
- {
- if (verifica_se_folha(t) && k==0)
- {
- k=1;
- printf("%d", t->value);
- }
- else if (verifica_se_folha(t) && k==1)
- {
- printf(" %d", t->value);
- }
- imprime_folhas(t->child[0]);
- imprime_folhas(t->child[1]);
- }
- }
- void elimina_folhas (Tree t)
- {
- if (t!=NULL)
- {
- if (verifica_se_folha(t))
- {
- tree_remove(&t);
- }
- elimina_folhas(t->child[0]);
- elimina_folhas(t->child[1]);
- }
- }
- void somar1 (Tree t, int y, int z)
- {
- if (t != NULL)
- {
- if (t->value <=z && t->value >=y)
- {
- t->value = t->value +1;
- }
- somar1(t->child[0],y,z);
- somar1(t->child[1],y,z);
- }
- }
- void task_a (void)
- {
- char k;
- Tree arvores[101];
- while (scanf("%c", &k)!=EOF)
- {
- if (k== 'C')
- {
- int x,y,z,w;
- scanf("%d %d %d %d", &x, &y, &z, &w);
- if (z==-1 && w==-1)
- {
- arvores[x]=tree_cons(y,NULL,NULL);
- }
- else if (z==-1 && w!=-1)
- {
- arvores[x]=tree_cons(y,NULL,arvores[w]);
- }
- else if (z!=-1 && w==-1)
- {
- arvores[x]=tree_cons(y,arvores[z],NULL);
- }
- else
- {
- arvores[x]=tree_cons(y,arvores[z],arvores[w]);
- }
- }
- if (k== 'Z')
- {
- int x;
- scanf("%d", &x);
- printf("%d\n", tree_size (arvores[x]));
- }
- if (k== 'H')
- {
- int x;
- scanf("%d", &x);
- printf("%d\n", tree_height (arvores[x]));
- }
- if (k== 'R')
- {
- int x;
- scanf("%d", &x);
- tree_remove(&arvores[x]);
- }
- if (k== 'W')
- {
- int x;
- scanf("%d", &x);
- tree_writeln_star (stdout, arvores[x]);
- }
- if (k== 'D')
- {
- int x;
- scanf("%d", &x);
- p=0;
- if (arvores[x] == NULL)
- {
- printf("NULL\n");
- }
- else
- {
- tree_walk_directly(arvores[x], int_);
- printf("\n");
- }
- }
- if (k== 'U')
- {
- int x;
- scanf("%d", &x);
- p=0;
- if (arvores[x] == NULL)
- {
- printf("NULL\n");
- }
- else
- {
- tree_walk_reversely(arvores[x], int_);
- printf("\n");
- }
- }
- if (k== 'S')
- {
- int x;
- scanf("%d", &x);
- if (arvores[x])
- {
- printf("%d\n", tree_sum(arvores[x]));
- }
- }
- if (k== 'M')
- {
- int x;
- scanf("%d", &x);
- if (arvores[x])
- {
- tree_walk_directly(arvores[x], maximo);
- }
- printf("%d\n", maior);
- }
- if (k== 'F')
- {
- int x,y;
- scanf("%d %d", &x, &y);
- printf("%d\n", tree_count(arvores[x], y));
- }
- if (k== 'L')
- {
- int x;
- scanf("%d", &x);
- if (arvores[x])
- {
- k=0;
- imprime_folhas(arvores[x]);
- printf("\n");
- }
- }
- if (k== 'T')
- {
- int x;
- scanf("%d", &x);
- if (arvores[x])
- {
- elimina_folhas(arvores[x]);
- }
- }
- if (k== 'Y')
- {
- int x,y,z;
- scanf("%d %d %d", &x, &y, &z);
- if (y<=z)
- {
- somar1(arvores[x],y,z);
- }
- }
- }
- }
- int main (void)
- {
- task_a();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement