public static List<BinTree> funct1(BinTree var0) { List<BinTree> res = new ArrayList<BinTree>(); BinTree cptExpr1 = new BinTree(" cptExpr1", BinTree.NIL, var0); BinTree tmp1 = new BinTree(" tmp1", BinTree.NIL, cptExpr1); BinTree cptExpr2 = new BinTree(" cptExpr2", BinTree.NIL, var0); final int cpt1 = var0.nbHd(); for (int i1 = 0; i1 < cpt1; i1++) { final int cpt2 = var0.nbHd(); for (int i2 = 0; i2 < cpt2; i2++) { final int cpt3 = var0.nbHd(); for (int i3 = 0; i3 < cpt3; i3++) { System.out.println("Nop"); // *********Affectation******* List<BinTree> varTmp1 = new ArrayList<BinTree>(); varTmp1.add(tmp1); int cmpt1 = 0; var0 = varTmp1.get(cmpt1); cmpt1++; // ******endAffectation******* } } } res.add(var0); return res; }
public BinTree geBSTFromPreOrder(int[] preOrder) { BinTree binTree = null; if (preOrder.length > 0) { binTree = new BinTree(); BNode root = getBSTFromPreOrder(preOrder, Integer.MIN_VALUE, Integer.MAX_VALUE); binTree.theBTRootNode = root; } return binTree; }
public static void main(String[] args) { BinTree tree = new BinTree(); int value; Random randomNumber = new Random(); System.out.println("building binary tree.."); for (int i = 1; i <= 10; i++) { value = randomNumber.nextInt(100); System.out.printf("%d ", value); tree.insertNode(value); } System.out.println("\n\nInorder traversal"); tree.treeWalk(); }
// Procura o ultimo lugar false disponivel private boolean procurarLugarFalseArvore( BinTree noAtual, int noIDExistente, int novoNoID, String pergunta) { if (noAtual.nodeID == noIDExistente) { // Encontrou nó if (noAtual.falseArvore == null) noAtual.falseArvore = new BinTree(novoNoID, pergunta); else { } return true; } else { // Tentar arvore "true" if (noAtual.trueArvore != null) { if (procurarLugarFalseArvore(noAtual.trueArvore, noIDExistente, novoNoID, pergunta)) { return true; } else { // Tentar arvore "false" if (noAtual.falseArvore != null) { return (procurarLugarFalseArvore( noAtual.falseArvore, noIDExistente, novoNoID, pergunta)); } else return false; // Não encontrou aqui } } else return false; // Não encontrou aqui } }
public static void main(String[] args) { TraversalOperations to = new TraversalOperations(); int[] preOrder = {4, 2, 1, 3, 6, 5, 7}; BinTree binTree = to.geBSTFromPreOrder(preOrder); binTree.inorder(binTree.theBTRootNode); }