Exemplo n.º 1
0
 public void postOrder(TreeNode <T> root)
 {
     if (root != null)
     {
         postOrder(root.getLeft());
         postOrder(root.getRight());
         order.addLast(root);
     }
 }
Exemplo n.º 2
0
 public void preOrder(TreeNode <T> root)
 {
     if (root != null)
     {
         Console.WriteLine(root.getElement());
         order.addLast(root);
         preOrder(root.getLeft());
         preOrder(root.getRight());
     }
 }
Exemplo n.º 3
0
        public MyLinkedList <T> purge(exists <T> comparador)
        {
            Node <T>         aux      = head;
            Node <T>         aux2     = aux.getNext();
            MyLinkedList <T> repeated = new MyLinkedList <T>();

            while (aux2.getNext() != null)
            {
                while (aux2 != null)
                {
                    if (comparador(aux, aux2))
                    {
                        Node <T> auxiliar = head;
                        while (auxiliar.getNext() != aux2)
                        {
                            auxiliar = auxiliar.getNext();
                        }
                        auxiliar.setNext(aux2.getNext());
                        repeated.addLast(aux2.getElement());
                        listSize--;
                    }
                    aux2 = aux2.getNext();
                }
                aux  = aux.getNext();
                aux2 = aux.getNext();
                if (aux == null || aux2 == null)
                {
                    break;
                }
            }

            return(repeated);
        }
Exemplo n.º 4
0
 private void addElement(TreeNode <T> root, T element, int key)
 {
     if (this.root == null)
     {
         this.root = new TreeNode <T>(element, null, null, null, key);
         numberOfTreeNodes++;
     }
     else
     {
         if (key < root.getKey())//x es menor que y
         {
             if (root.getLeft() == null)
             {
                 root.setLeft(new TreeNode <T>(element, root, null, null, key));
                 numberOfTreeNodes++;
             }
             else
             {
                 addElement(root.getLeft(), element, key);
             }
         }
         else if (key > root.getKey())//x es mayor que y
         {
             if (root.getRight() == null)
             {
                 root.setRight(new TreeNode <T>(element, root, null, null, key));
                 numberOfTreeNodes++;
             }
             else
             {
                 addElement(root.getRight(), element, key);
             }
         }
         else if (key == root.getKey())//x es igual que y
         {
             //si las llave actual es igual a la llave se le restará o se sumará un número aleatorio
             //para luego agregarlo al arbol binario
             repeatedKeys.addLast(key);
             key = generator.Next(6500, 9500);
             add(element, key);
         }
     }
 }
Exemplo n.º 5
0
 public override void enqueue(T t)
 {
     myList.addLast(t);
 }