Ejemplo n.º 1
0
    private boolean repOK_isAcyclic()
    {
        RoopsList visited = new RoopsList();

        visited.add(root);
        RoopsList workList = new RoopsList();

        workList.add(root);
        while (!workList.isEmpty())
        {
            BinTreeNode current = (BinTreeNode)workList.get(0);
            workList.remove(0);
            if (current.left != null)
            {
                // checks that the tree has no cycle
                if (visited.contains(current.left))
                {
                    return(false);
                }
                else
                {
                    visited.add(current.left);
                }

                workList.add(current.left);
            }
            if (current.right != null)
            {
                // checks that the tree has no cycle
                if (visited.contains(current.right))
                {
                    return(false);
                }
                else
                {
                    visited.add(current.right);
                }

                workList.add(current.right);
            }
        }
        return(true);
    }
Ejemplo n.º 2
0
    private static boolean repOK_isAcyclic(BinomialHeapNode start, RoopsList seen)
    {
        if (seen.contains(start))
        {
            return(false);
        }

        if (start.degree < 0)
        {
            return(false);
        }

        seen.add(start);

        BinomialHeapNode child = start.child;

        int child_count = 0;

        while (child != null)
        {
            child_count++;

            if (child.parent != start)
            {
                return(false);
            }

            if (!repOK_isAcyclic(child, seen))
            {
                return(false);
            }

            if (child.sibling != null)
            {
                if (child.degree <= child.sibling.degree)
                {
                    return(false);
                }
            }
            child = child.sibling;
        }

        if (start.degree != child_count)
        {
            return(false);
        }

        if (start.child != null)
        {
            int tam_child = 1;
            if (start.child.child != null)
            {
                BinomialHeapNode curr = start.child.child;
                while (curr != null)
                {
                    tam_child += repOK_count_nodes(start.child.child);
                    curr       = curr.sibling;
                }
            }

            int tam_sibling = 1;
            if (start.child.sibling != null)
            {
                BinomialHeapNode curr = start.child.sibling;
                while (curr != null)
                {
                    tam_sibling += repOK_count_nodes(start.child.sibling);
                    curr         = curr.sibling;
                }
            }

            if (tam_child != tam_sibling)
            {
                return(false);
            }
        }

        return(true);
    }
Ejemplo n.º 3
0
    private boolean repOK_isAcyclic()
    {
        RoopsList visited = new RoopsList();
          visited.add(root);
          RoopsList workList = new RoopsList();
          workList.add(root);
          while (!workList.isEmpty()) {
        BinTreeNode current = (BinTreeNode)workList.get(0);
        workList.remove(0);
        if (current.left != null) {
          // checks that the tree has no cycle
          if (visited.contains(current.left))
            return false;
          else
            visited.add(current.left);

          workList.add(current.left);
        }
        if (current.right != null) {
          // checks that the tree has no cycle
          if (visited.contains(current.right))
            return false;
          else
        visited.add(current.right);

          workList.add(current.right);
        }
          }
          return true;
    }
Ejemplo n.º 4
0
 public boolean containsKey(K key)
 {
     return(keys.contains(key));
 }
Ejemplo n.º 5
0
    private static boolean repOK_isAcyclic(BinomialHeapNode start, RoopsList seen)
    {
        if (seen.contains(start))
             return false;

         if (start.degree<0)
             return false;

         seen.add(start);

         BinomialHeapNode child = start.child;

         int child_count = 0;

         while (child!=null) {

             child_count++;

             if (child.parent != start)
                 return false;

             if (!repOK_isAcyclic(child, seen))
                 return false;

             if (child.sibling!=null) {
                 if (child.degree<=child.sibling.degree)
                     return false;
             }
             child = child.sibling;
         }

         if (start.degree!=child_count)
             return false;

         if (start.child!=null) {
             int tam_child=1;
             if (start.child.child!=null) {
                 BinomialHeapNode curr = start.child.child;
                 while (curr!=null) {
                   tam_child+= repOK_count_nodes(start.child.child);
                   curr = curr.sibling;
                 }
             }

             int tam_sibling=1;
             if (start.child.sibling!=null) {
                 BinomialHeapNode curr = start.child.sibling;
                 while (curr!=null) {
                   tam_sibling+= repOK_count_nodes(start.child.sibling);
          			       curr = curr.sibling;
                 }
             }

             if (tam_child!=tam_sibling)
                 return false;

         }

         return true;
    }