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); }
private boolean repOK_parentsAllRight() { RoopsList workList = new RoopsList(); workList.add(root); while (!workList.isEmpty()) { BinTreeNode current = (BinTreeNode)workList.get(0); workList.remove(0); if (current.left != null) { if (current.left.parent != current) { return(false); } else { workList.add(current.left); } } if (current.right != null) { if (current.right.parent != current) { return(false); } else { workList.add(current.right); } } } return(true); }
//************************************************************************* //************** From now on repOK() ************************************* //************************************************************************* public boolean repOK() { RoopsSet allNodes = new RoopsSet(); RoopsList parent_headers_to_visit = new RoopsList(); if (min != null) { // check first level { int child_cound = 0; FibHeapNode curr = min; do { if (curr.left.right != curr) { return(false); } if (curr.parent != null) { return(false); } if (curr.child != null) { parent_headers_to_visit.add(curr); } if (!allNodes.add(curr)) { return(false); // repeated node } curr = curr.left; child_cound++; } while (curr != min); } while (!parent_headers_to_visit.isEmpty()) { // check other levels FibHeapNode node = (FibHeapNode)parent_headers_to_visit.get(0); parent_headers_to_visit.remove(0); int node_count = 0; FibHeapNode curr_node = node.child; do { if (curr_node.left.right != curr_node) { return(false); } if (curr_node.parent != null) { return(false); } if (curr_node.child != null) { parent_headers_to_visit.add(curr_node); } if (curr_node.cost > node.cost) { return(false); } if (!allNodes.add(curr_node)) { return(false); // repeated node } curr_node = curr_node.left; node_count++; } while (curr_node != node.child); if (node_count != node.degree) { return(false); } } } if (allNodes.getSize() != this.n) { return(false); } return(true); }
private boolean repOK_parentsAllRight() { RoopsList workList = new RoopsList(); workList.add(root); while(!workList.isEmpty()) { BinTreeNode current = (BinTreeNode)workList.get(0); workList.remove(0); if (current.left != null) { if (current.left.parent != current) return false; else workList.add(current.left); } if (current.right != null) { if (current.right.parent != current) return false; else workList.add(current.right); } } return true; }
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; }
public boolean isEmpty() { return(entries.isEmpty()); }
public boolean isEmpty() { return(keys.isEmpty()); }
//************************************************************************* //************** From now on repOK() ************************************* //************************************************************************* public boolean repOK() { RoopsSet allNodes = new RoopsSet(); RoopsList parent_headers_to_visit = new RoopsList(); if (min != null) { // check first level { int child_cound = 0; FibHeapNode curr = min; do { if (curr.left.right != curr) return false; if (curr.parent != null) return false; if (curr.child != null) parent_headers_to_visit.add(curr); if (!allNodes.add(curr)) return false;// repeated node curr = curr.left; child_cound++; } while (curr!=min); } while (!parent_headers_to_visit.isEmpty()) { // check other levels FibHeapNode node = (FibHeapNode) parent_headers_to_visit.get(0); parent_headers_to_visit.remove(0); int node_count = 0; FibHeapNode curr_node = node.child; do { if (curr_node.left.right != curr_node) return false; if (curr_node.parent != null) return false; if (curr_node.child != null) parent_headers_to_visit.add(curr_node); if (curr_node.cost>node.cost) return false; if (!allNodes.add(curr_node)) return false; // repeated node curr_node = curr_node.left; node_count++; } while (curr_node != node.child); if (node_count != node.degree) return false; } } if (allNodes.getSize() != this.n) return false; return true; }