Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- No noMinimo (No no) {
- No aux = no;
- while (aux.esq != null) {
- aux = aux.esq;
- }
- return aux;
- }
- void transplantar (No a, No b) {
- if(a.mae == null) {
- this.raiz = b;
- } else if (a == a.mae.esq) {
- a.mae.esq = b;
- } else {
- a.mae.dir = b;
- }
- if (b != null) {
- b.mae = a.mae;
- }
- }
- void remover2 (No no, int num) {
- No a = buscar(no, num);
- if (a == null) {
- return;
- } else {
- if (a.esq == null) {
- transplantar (a, a.dir);
- } else if (a.dir == null) {
- transplantar (a, a.esq);
- } else {
- No b = noMinimo(a.dir);
- if (b.mae != a){
- transplantar (b, b.dir);
- b.dir = a.dir;
- b.dir.mae = b;
- }
- transplantar (a, b);
- b.esq = a.esq;
- b.esq.mae = b;
- }
- }
- }
- void inserir2 (int num) {
- No c = new No(num);
- No b = raiz;
- No a = b;
- while(b != null) {
- a = b;
- if (c.num < b.num) {
- b = b.esq;
- } else if (c.num > b.num) {
- b = b.dir;
- } else {
- return;
- }
- }
- c.mae = a;
- if(a == null) {
- raiz = c;
- } else if (c.num < a.num){
- a.esq = c;
- } else if (c.num > a.num){
- a.dir = c;
- } else {
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement