Traversing up a tree

i need help in traversing up a tree i want to start at a child node and traverse up the tree stoping when i find a certain value and return that node. In the example below i want to start at id 5 and stop when i traverse upwards when i hit the first flag with Y so in this case i would return 2.
example
id partent_id flag
1 null Y
2 1 Y
3 2 N
4 3 N
5 4 N

SQL> with t as
  2  (select 1 id, NULL parent, 'Y' flag from dual
  3  union all
  4  select 2 id, 1 parent, 'Y' from dual
  5  union all
  6  select 3 id, 2 parent, 'N' from dual
  7  union all
  8  select 4 id, 3 parent, 'N' from dual
  9  union all
10  select 5 id, 4 parent, 'N' from dual
11  )
12  , t_twisted as
13  (
14  select id, parent, flag, level l
15  from t
16  connect by id = prior parent
17  start with id = 5
18  ),
19  t_sorted as
20  (
21  select id, l, row_number() over (order by l) rn
22  from t_twisted
23  where flag = 'Y'
24  )
25  select id
26  from t_sorted
27  where rn = 1
28  /
        ID
         2
SQL> Cheers
Sarma.

Similar Messages

  • Breadth First Traversal of a Tree...

    Hi,
    I want to make a program to print every node of a tree in a Breadth First Search (BFS)/Traversal. Since, BFS searches a tree in levels (i.e. 1st the root, then it's Children, then Grand Children etc from left to right), this is where I'm stuck. Here is my TreeNode class:
    class TreeNode {
      Object element;
      TreeNode left;
      TreeNode right;
      public TreeNode(Object o) {
        element = o;
    }Each node has a reference to its Children nodes etc. Here is how my tree looks like. Mine is similar to this: http://www.codeproject.com/KB/vb/SimpleBTree.aspx
    All the lectures I have read in the net are talking about Queue, but my problem is reading the tree in BFS Traversal order. It's almost 4 days I'm trying to solve this probelm, but can't come up with something. Any help is greatly appreciated.
    Here is my Binary Tree class:
    public class BinaryTree {
         private TreeNode root;
         private int size = 0;
         /** Create a default binary tree */
         public BinaryTree() {
         /** Create a binary tree from an array of objects */
        public BinaryTree(Object[] objects) {
          for (int i = 0; i < objects.length; i++)
            insert(objects);
    /** Insert element o into the binary tree
    * Return true if the element is inserted successfully */
    public boolean insert(Object o) {
    if (root == null)
    root = new TreeNode(o); // Create a new root
    else {
    // Locate the parent node
    TreeNode parent = null;
    TreeNode current = root;
    while (current != null)
    if (((Comparable)o).compareTo(current.element) < 0) {
    parent = current;
    current = current.left;
    else if (((Comparable)o).compareTo(current.element) > 0) {
    parent = current;
    current = current.right;
    else
    return false; // Duplicate node not inserted
    // Create the new node and attach it to the parent node
    if (((Comparable)o).compareTo(parent.element) < 0)
    parent.left = new TreeNode(o);
    else
    parent.right = new TreeNode(o);
    size++;
    return true; // Element inserted
    /** Inorder traversal */
    public void inorder() {
    inorder(root);
    /** Inorder traversal from a subtree */
    private void inorder(TreeNode root) {
    if (root == null) return;
    inorder(root.left);
    System.out.print(root.element + " ");
    inorder(root.right);
    /** Postorder traversal */
    public void postorder() {
    postorder(root);
    /** Postorder traversal from a subtree */
    private void postorder(TreeNode root) {
    if (root == null) return;
    postorder(root.left);
    postorder(root.right);
    System.out.print(root.element + " ");
    /** Preorder traversal */
    public void preorder() {
    preorder(root);
    /** Preorder traversal from a subtree */
    private void preorder(TreeNode root) {
    if (root == null) return;
    System.out.print(root.element + " ");
    preorder(root.left);
    preorder(root.right);
    /** Inner class tree node */
    private static class TreeNode {
    Object element;
    TreeNode left;
    TreeNode right;
    public TreeNode(Object o) {
    element = o;
    /** Get the number of nodes in the tree */
    public int getSize() {
    return size;
    /** Search element o in this binary tree */
    public boolean search(Object o){
    TreeNode temp = root;
    boolean found = false;
    if(temp == null)
    found = false;
    else if(((Comparable)(temp.element)).compareTo(o) == 0 && temp != null)
    found = true;
    else if(((Comparable)temp.element).compareTo(o) > 0){
    root = temp.left;
    found = search(o);
    else{
    root = temp.right;
    found = search(o);
    return found;
    /** Display the nodes in breadth-first traversal */
    public void breadthFirstTraversal(){
    TreeNode temp = root;
    // TreeNode leftChild = temp.left;
    // TreeNode rightChild = temp.right;
    MyQueue s = new MyQueue();
    s.enqueue(root);
    // while (s.getSize() == 0){
    System.out.println(s);
    // private void breadthFirstTraversal(TreeNode node){

    ChangBroot wrote:
    All the lectures I have read in the net are talking about Queue, but my problem is reading the tree in BFS Traversal order. It's almost 4 days I'm trying to solve this probelm, but can't come up with something. Any help is greatly appreciated. One simple strategy is to make an ordinary recursive traversal of the tree. Along in the traversal you keep an array of linked lists. When you visit a node you just add it to the list at the entry in the array corresponding to the depth of this node.
    After the traversal you have an array with linked lists. Each list holds the nodes found at a certain tree depth. So each list holds all nodes corresponding to a specific tree "breadth", namely all nodes found at the same tree depth.

  • How to Recursively traverse a Dom Tree

    Hi there, I'm new to java and xml and would like to see some sample code on recursively traversing a DOM tree in java, printing out all Element, Text, etc to the console window.
    Please help

    Use this: DomRead.java at your own risk. caveat: this gets screwed up if the attributes are multi-valued. You can use XPath to get around that. I am struggling with the proper XPath expressions.
    import org.xml.sax.*;
    import org.w3c.dom.*;
    import java.util.*;
    * version 1.0
    public class DomRead implements ErrorHandler
         private static final String CRLF = System.getProperty("line.separator");
         private static String key = "";
         private static String value = "";
         private Hashtable elements = new Hashtable();
         * This constructor has to be used to pass in the DOM document which needs to
         * be read so that this class can generate the hashtable with the attributes as
         * keys and their corresponding values.
         public DomRead(Document rootDoc)
              process(rootDoc);
         private void processChild(NodeList root)
              for(int i=0;i<root.getLength(); i++)
                   process(root.item(i));
         private void printAttrib(Node root)
              NamedNodeMap attrib = root.getAttributes();
              int len = attrib.getLength();
              if(len == 0) return;
              for(int i=0; i < len ; i++)
                   Attr attribute = (Attr) attrib.item(i);
                   key = attribute.getNodeValue();
         private void process(Node root)
              switch( root.getNodeType())
                   case Node.DOCUMENT_NODE :
                        Document doc = (Document) root;
                        processChild(doc.getChildNodes());
                        break;
                   case Node.ELEMENT_NODE :
                        root.setNodeValue(root.getNodeValue() );
                        printAttrib(root);
                        processChild(root.getChildNodes());
                        break;
                   case Node.TEXT_NODE :                    
                        Text text = (Text) root;
                        value = text.getNodeValue().trim();                    
                        //Log("Value: "+value+CRLF);
                        if(!value.equalsIgnoreCase(""))
                             elements.put(key, value);
                        break;
         * Use this method, if you intend to print out the contents of the generated
         * hashtable.
         public void printElements()
              for (Enumeration enum = elements.keys(); enum.hasMoreElements() ;)
                   String tKey = (String)enum.nextElement();
                   Log(tKey+"::::"+(String)elements.get(tKey));
         * This method returns the Hashtable with the attributes that have non-empty
         * values.
         public Hashtable getElements()
              return elements;
         public void error(SAXParseException e)
              e.printStackTrace();
         public void warning(SAXParseException e)
              e.toString();
         public void fatalError(SAXParseException e)
              e.printStackTrace();
         private static void Log(String log)
              System.out.print(log+CRLF);
    }

  • Non recursive preorder traversal of binary tree

    hi,
    I am trying to implement a non-recursive traversal of binary tree. I already know the recursive one.
    I am trying to do it by using a Stack.
    I begin by Pushing the root of an element on to a stack, and then run a while loop in which i pop an element of the stack and get its children from right to left. and push it in the same order on to the stack. So during the next iteration of my while loop the top most element gets popped and its children and pushed on to the stack in the above manner.
    but when i pop an element from a stack its popped as an object so i dont know how to access its children.
    help me i am really stuck.

    Hi, I suppose you have something like this :
    class Stack {
      public void push( Object object ) throws ... { ... }
      public Object pop() throws ... { ... }
    class Element {
      Element elem;
      stack.push(elem);
      /* because pop() method return an object of type Object
      ** if you are sure that your stack only contains Element object
      ** then you need to cast (change the type of) what the pop() method
      ** returns in this way :
      elem = (Element)stack.pop();
      ...further reading on casting will be a good idea anyway.

  • Traversing down catalog tree w/ WLCS

    I'm trying to make an efficient traversal down an entire catalog tree on
              WLCS with a large product catalog, starting at root, and putting all
              subsequent recursive subcategories (with links) into a DHTML menu for
              leftside.inc. WLCS isn't very good at traversing down the tree in my
              attempts (just breadcrumbing ancestors up), so any help would be greatly
              appreciated!
              Andy Hawks
              [email protected]
              

              "Andy Hawks" <[email protected]> wrote in message
              news:[email protected]..
              > I'm trying to make an efficient traversal down an entire catalog tree on
              > WLCS with a large product catalog, starting at root, and putting all
              > subsequent recursive subcategories (with links) into a DHTML menu for
              > leftside.inc. WLCS isn't very good at traversing down the tree in my
              > attempts (just breadcrumbing ancestors up), so any help would be greatly
              > appreciated!
              >
              > Andy Hawks
              > [email protected]
              >
              Just a "me too" posting - we've been trying to do the same thing.
              Currently we're using a very bodge solution - use JDBC to go directly to the
              category and hierarchy tables, and pull out all the relationships between
              categories, then use a bunch of Java and JSP processing to build the
              relevant displayed tree.
              This is not a nice solution, we'd prefer something slightly more elegant,
              possibly a custom tag solution?
              One thing we may do soon is to write a pipeline component which does the
              tree building using the CategoryManager to wander the hierarchy building up
              some form of "hashtable of hashtables" structure which we'll then store in
              the pipeline session for the JSP.
              Any better solutions greatfully received.
              cheers.
              

  • Traversing a binary tree

    Hi
    I've written the following code for converting Postfix to Infix,it reads a string then reads it letter by letter ,a stack and a Tree is used,and I want to traverse the last object that has poped from the stack,in the following code I used this line:
    System.out.println((Character)(((TreeNode)stack.pop()).data));
    but it only prints the root of the tree,I tried to traverse it but I don't have any idea,I did sth like this( for traversing another node):
    (TreeNode)stack.pop() = ( (TreeNode)stack.pop() ).data;
    System.out.println((Character)(((TreeNode)stack.pop()).data));
    but it didn't work.
    would you plz help me with it.
    Here is the code:
    import java.util.Scanner;
    public class Test
    public static void main( String args[])
    Scanner input = new Scanner( System.in );
    System.out.printf("Enter your String(in Postfix):\n");
    String c = input.nextLine();//read a line of text
    Stack stack = new Stack();
    int i = 0 ;
    while( i < c.length() )
    char a = c.charAt( i );
    if( Character.isLetterOrDigit (a) )
    System.out.printf("\n%c" , a );
    stack.push( new TreeNode( a ) );
    else if( a == '+' || a == '-' || a == '*' || a == '/' )
    TreeNode t = new TreeNode( a );
    t.insert( 0 , stack.pop() );
    t.insert( 1 , stack.pop() );
    stack.push( t );
    i++;
    (TreeNode)stack.pop() = ( (TreeNode)stack.pop() ).data; //<-----Here is the problem
    System.out.println((Character)(((TreeNode)stack.pop()).data));
    Thax
    Bita

    Well, two things. First, you're trying to assign to a method call, which isn't valid. The compiler probably told you this.
    Second, you're popping things from the stack more often than you need to (e.g., for printing) so the stack probably won't be in the state you need.
    When you post code, please wrap it in code tags so it'll be legible. Highlight it and then click the CODE button above the text input box.

  • Traverse a binary tree from root to every branch

    I have a couple of other questions. I need to get all the different combinations of a binary tree and store them into a data structure. For the example in the code below, the combinations would be:
    1) Start, A1, A2, A3, B1, B2, B3
    2) Start, A1, A2, B1, A3, B2, B3
    3) Start, A1, A2, B1, B2, A3, B3
    4) Start, A1, A2, B1, B2, B3, A3
    5) Start, A1, B1, A2, A3, B2, B3
    etc.
    I understand that this is very similar to the preorder traversal, but preorder does not output the parent nodes another time when the node splits into a left and right node. Any suggestions?
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package binarytreetest;
    import java.util.ArrayList;
    import java.util.Iterator;
    * @author vluong
    public class BinaryTreeTest {
         * @param args the command line arguments
        public static void main(String[] args) {
            // TODO code application logic here
            int countA = 0;
            int countB = 0;
            ArrayList listA = new ArrayList();
            ArrayList listB = new ArrayList();
            listA.add("A1");
            listA.add("A2");
            listA.add("A3");
            listB.add("B1");
            listB.add("B2");
            listB.add("B3");
            //listB.add("B1");
            Node root = new Node("START");
            constructTree(root, countA, countB, listA, listB);
            //printInOrder(root);
            //printFromRoot(root);
        public static class Node{
            private Node left;
            private Node right;
            private String value;
            public Node(String value){
                this.value = value;
        public static void constructTree(Node node, int countA, int countB, ArrayList listA, ArrayList listB){
            if(countA < listA.size()){
                if(node.left == null){
                    System.out.println("There is no left node. CountA is " + countA);
                    System.out.println("Created new node with value: " + listA.get(countA).toString() + " with parent, "
                            + node.value);
                    System.out.println();
                    node.left = new Node(listA.get(countA).toString()); 
                    constructTree(node.left, countA+1, countB, listA, listB);   
                }else{
                    System.out.println("There is a left node. CountA + 1 is " + countA+1);
                    constructTree(node.left, countA+1, countB, listA, listB);   
            if(countB < listB.size()){
                if(node.right == null){
                    System.out.println("There is no right node. CountB is " + countB);
                    System.out.println("Created new node with value: " + listB.get(countB).toString() + " with parent, "
                            + node.value);
                    System.out.println();
                    node.right = new Node(listB.get(countB).toString());
                    constructTree(node.right, countA, countB+1, listA, listB);
                }else{
                    System.out.println("There is a right node. CountB + 1 is " + countB+1);
                    constructTree(node.right, countA, countB+1, listA, listB);
        }My second question is, if I need to add another list (listC) and find all the combinations of List A, listB and list C, is it correct to define the node class as
    public static class Node{
            private Node left;
            private Node mid;
            private Node right;
            private String value;
            public Node(String value){
                this.value = value;
        }Node left = listA, Node mid = listB, Node right = listC
    The code for the 3 lists is below.
    3 lists (A, B, C):
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package binarytreetest;
    import java.util.ArrayList;
    * @author vluong
    public class BinaryTreeTest {
         * @param args the command line arguments
        public static void main(String[] args) {
            // TODO code application logic here
            insert(root, "A1");
            insert(root, "A2");
            insert(root, "B1");
            insert(root, "B2"); 
            insert(root, "A2");
            int countA = 0;
            int countB = 0;
            int countC = 0;
            ArrayList listA = new ArrayList();
            ArrayList listB = new ArrayList();
            ArrayList listC = new ArrayList();
            listA.add("A1");
            listA.add("A2");
            //listA.add("A3");
            listB.add("B1");
            listB.add("B2");
            //listB.add("B3");
            //listB.add("B1");
            listC.add("C1");
            listC.add("C2");
            Node root = new Node("START");
            constructTree(root, countA, countB, countC, listA, listB, listC);
            //ConstructTree(root, countA, countB, listA, listB);
            //ConstructTree(root, countA, countB, listA, listB);
            printInOrder(root);
            //printFromRoot(root);
        public static class Node{
            private Node left;
            private Node mid;
            private Node right;
            private String value;
            public Node(String value){
                this.value = value;
        public static void constructTree(Node node, int countA, int countB, int countC, ArrayList listA, ArrayList listB, ArrayList listC){
            if(countA < listA.size()){
                if(node.left == null){
                    System.out.println("There is no left node. CountA is " + countA);
                    System.out.println("Created new node with value: " + listA.get(countA).toString() + " with parent, "
                            + node.value);
                    System.out.println();
                    node.left = new Node(listA.get(countA).toString()); 
                    constructTree(node.left, countA+1, countB, countC, listA, listB, listC);   
                }else{
                    System.out.println("There is a left node. CountA + 1 is " + countA+1);
                    constructTree(node.left, countA+1, countB, countC, listA, listB, listC);   
            if(countB < listB.size()){
                if(node.mid == null){
                    System.out.println("There is no mid node. CountB is " + countB);
                    System.out.println("Created new node with value: " + listB.get(countB).toString() + " with parent, "
                            + node.value);
                    System.out.println();
                    node.mid = new Node(listB.get(countB).toString());
                    constructTree(node.mid, countA, countB+1, countC, listA, listB, listC);
                }else{
                    System.out.println("There is a right node. CountB + 1 is " + countB+1);
                    constructTree(node.mid, countA, countB+1, countC, listA, listB, listC);
            if(countC < listC.size()){
                if(node.right == null){
                    System.out.println("There is no right node. CountC is " + countC);
                    System.out.println("Created new node with value: " + listC.get(countC).toString() + " with parent, "
                            + node.value);
                    System.out.println();
                    node.right = new Node(listC.get(countC).toString());
                    constructTree(node.right, countA, countB, countC+1, listA, listB, listC);
                }else{
                    System.out.println("There is a right node. CountC + 1 is " + countC+1);
                    constructTree(node.mid, countA, countB, countC+1, listA, listB, listC);
        }Thank you in advance!

    It looks to me like you are interleaving two lists. It looks like you are doing this while leaving the two subsequences in their original order.
    If that is in fact what you are doing, then this is just a combinatorics problem. Here is psuedo code (NOT java!)
    List path = new List();
    show(List A, int a, List B, int b, path){
      if(a >= A.length() && b >= b.length()){
        spew(path);
      } else {
        if(a < A.length()){path.push(A[a]); show(A,a+1,B,b,); path.pop();}
        if(b < B.length()){path.push(B); show(A,a,B,b+1,); path.pop();}
    show(A, 0, B, 0);
    In order to interleave 3 lists, you would add C and c arguments to the function and you would add one more line in the else block.

  • How to remember the path while traverse a binary tree?

    Hi, again, I have difficulty handling tree search problems.
    The quesion is How to search for a node from a binary tree A, return true if found meanwhile generate the path which can be used to locate the node.
    I think the signature should be:
    // The path contains only 0s and 1s. 0 means go left and 1 means go right.
    public staic boolean search(Node rootOfA, Node b, ArrayList<Integer> path){
    // the class Node only has two fields:
    Node{
    Node left;
    Node right;
    I know if there is another field in the Node class (say, a flag), the quesion would be much easier, but the space is really critical.
    I tried to use recursion but havn't got a correct solution. I am thinking of usinga non-recursion algo.
    Anyone wants to help?

    Hi, JosAh,
    That's mind provoking. However, I do think it works. It does not pop some stuff it should pop. I tested it over a very simple tree and it failed. Did you test it? I might be wrong...
    The tree I am working on does not have null pointers, the condition to test if a node is a leaf is if(node.right == right). Namly, all the right pointer of leaves points to itself.
    So I changed your code to be:
    Stack search(Node root, Node node, Stack<Integer> path) {
         if (root == null || root.right ==right) return null;
         if (root.equals(node)) return path;
         path.push(0);
    if (search(root.left, node, path) != null) return path;
    path.pop();
    path.push(1);
    return search(root.right, node, path);
    }I simply tested it with
    Stack<Integer> path = new Stack<Integer>();
    System.out.println( root, root.right.right, path);
    root is the root of a complete binary tree with 7 nodes(4 leaves).
    Apparenly, if the path is built correctly search(root, root.right.right, path) would return [1,1] whereas this seach returns [ 0 , 1, 1].
    Considerring , the right branch never pops, I changed it into
    Then I changed it to :
    Stack search(Node root, Node node, Stack<Integer> path) {
         if (root == null || root.right ==right ) return null;
         if (root.equals(node)) return path;
         path.push(0);
    if (search(root.left, node, path) != null) return path;
    path.pop();
    path.push(1);
    if (search(root.right, node, path) != null) return path;
    path.pop();
    return path;
    With the same test case, it returns [].
    I will keep working on it.
    Cheers,
    Message was edited by:
    since81
    Message was edited by:
    since81

  • How to traverse the XML tree.

    hi ,
    i would like to know if there is a sample code snippet
    showing how to walk through the Document object tree
    generated by the DOM parser for a given XML input.
    Thanks.
    Sandeep.
    null

    sandeep (guest) wrote:
    : hi,
    : can you please tell as to where is the selectNodes() method
    : defined. I could not locate it.
    : Thanks.
    : Sandeep.
    : Oracle XML Team wrote:
    : : Sandeep (guest) wrote:
    : : : hi ,
    : : : i would like to know if there is a sample code snippet
    : : : showing how to walk through the Document object tree
    : : : generated by the DOM parser for a given XML input.
    : : : Thanks.
    : : : Sandeep.
    : : Take a look at the selectNodes() method. It takes XPath
    syntax
    : : to navigate through the XML document.
    : : Oracle XML Team
    : : http://technet.oracle.com
    : : Oracle Technology Network
    selectNodes() is part of oracle.xml.parser.v2.XMLNode. You can
    find any method by opening AllNames.html in the doc directory.
    Oracle XML Team
    http://technet.oracle.com
    Oracle Technology Network
    null

  • Binary tree inorder traversal without recursion

    Using Java, write a method that does an in-order traversal of a binary tree WITHOUT using recursion. based on the following code
    BTreeNode.java
    public class BTreeNode
    public BTreeNode LEFT;
    public BTreeNode RIGHT;
    public String VALUE;
    BTreeUtil.java
    public class BTreeUtil
    public static void listNodes(BTreeNode a_oRootNode)
    // insert code here...
    }

    This is definitely the wrong place to post this. Nevertheless you'll have to use a stack. While traversing down the tree you push the parents onto the stack.
    stephan

  • How to traverse level by level in tree

    Wondering if there were any suggestions on how to efficiently traverse through a tree level by level.
    Here is my code for creating the tree.
    public static void main(String[] args)
              String userInput = "";
              StringTokenizer tokenizedUserInput;
              int numAdd = 0;
              STree<Integer> completeTree = new STree<Integer>();
              Scanner keyboard = new Scanner(System.in);
              System.out.println("Enter values for tree: ");
              userInput = keyboard.nextLine();
              tokenizedUserInput = new StringTokenizer(userInput, ", ");
              while (tokenizedUserInput.hasMoreTokens())
                 numAdd = Integer.parseInt(tokenizedUserInput.nextToken());
                 completeTree.add(numAdd);             
            } 

    I have found a method to traverse through the tree level by level but it takes in a parameter of a node. I'm
    not sure how to take my tree and pass it through the method. Here is the method:
    public static <T> String levelByLevel(TNode<T> t)
              LinkedQueue<TNode<T>> q = new LinkedQueue<TNode<T>>();
              TNode<T> p;
              String s = "";
              q.push(t);
              while(!q.isEmpty())
                   p = q.pop();
                   s += p.nodeValue + " ";
                   if(p.left != null)
                        q.push(p.left);
                   if(p.right != null)
                        q.push(p.right);
              return s;
    }

  • Traversing a tree with breadthFirstEnumeration

    Hi all,
    I'm trying to traverse a DefaultMutableNode tree using breadthFirstEnumeration. However, while traversing I need to remove some branches and continue with the Enumeration.
    Do you know any way to preserve the Enumeration after removing a branch???
    For example:
    for(Enumeration en = trial.breadthFirstEnumeration(); en.hasMoreElements() ;) {
                   DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode)en.nextElement();
                   if((String)currentNode.getUserObject() == "2") {
                        ((DefaultMutableTreeNode)(currentNode)).removeAllChildren();
                   System.out.println((String)currentNode.getUserObject());
    This code traverses a tree with depth 3 and branching factor 3. In the meanwhile it removes node 2's children.
    However the otuput is
    0 1 2 3 4 5 6
    instead of: 0 1 2 3 4 5 6 10 11 12
    I'd be very grateful if someone can help me.
    Regards,
    Pesho

    This is how it usually is done.
    Start with an empty map, e.g. HashMap. The map has e.g. company name as key, and company as value.
    Start traversing, and do a lookup towards the map when you find a company reference. Use the company within the map if there is one, and create a new company and place it in the map if it doesn't exist. Populate the companies within the map with information when you bump into them during traversal.
    The map will contain fully populated companies when the traversal is completed, and all companies will reference the same instances since you always are checking the map.
    Kaj

  • Flow chart like tree traversing

    I m facing some problem to traverse a a graph sort of thing.
    What i m doing is I have one flow chart sort of thing.
    I have one start node and one stop node and many nodes between these two.
    Which algo you guiess will suggest to implement for traversing.
    Thanx in advance.
    - Vikas

    Hi,
    To traverse a graph, is almost as traversing of a tree, since tree is a graph. Look at how you write a recursive method to traverse a tree. The only difference this time is that in a graph you have to pass along a collection that contains nodes that you already have visited (since a node in a normal graph might be reachable in many ways, but you only want to visit each node one time)
    Hope this helps
    /Kaj

  • A tree-view in HTML page with nodes generated with java script in run time is not visible in the UI Automation Tree. Need Help

    I have a HTML page with an IFrame. Inside the Iframe there is a table with a tree view
    <iframe>
    <table>
    <tr>
    <td>
    <treeview id="tv1"></treeview>
    </td>
    </tr>
    </table>
    </iframe>
    In UIA, i am able to traverse till the tree view but not able to see it.
    I have used the TreeWalker.RawViewWalker Field to traverse the node from the desktop Automation.RootElement. 
    I tried to use AutomationElement.FromPoint method to check whether i am able to get that element. Fortunately i was able to get the automation element. 
    i tried to get the path to root element from the node element using the TreeWalker.RawViewWalker. I was able to get the parent path to the root element.
    But trying the reverse way like navigating from root element to tree node, was not getting the element for me. 
    Please help me with suggestions or inputs to resolve this issue. 

    Thanks Bernard,
    It works fine with JInitiator but not working with
    the JPI. For JPI what settings I need to do ??hi TKARIM and Bernard, i am having similar problem even with the Bernard's recommended setup. could you post the webutiljini.htm (i presume you are using config=test) ?
    i am actually using jinitiator 1.3.1.28 with Oracle HTTP Server of OAS 10gR2) calling Forms Server 6i (f60cgi). After setting up according to Bernard's recommended setup steps, the java console showed that it loaded the icon jar file when it could not read the form, but it skipped the loading of the icon jar file once it read and started the form. How do we specify in the form to pick up the icon from the jar file instead from a directory ? Or do we need to specify ? Any ideas ?
    Thx and Regards
    dkklau

  • Listing File Hierarchy in console using a Tree structure

    first off i'm a college student. i'm not that good at java... we got this CA in class and try as i might i just can't get my head around it
    i was wondering if someone who know a bit more about java then i do would point me in the right direction, were i'm going wrong in my code
    i have to list out sub-files and sub-directorys of a folder (i.e. C:/test) to console using tree structure
    like this
    startingdir
    dir1 //subfolder of startingdir
    dir11 //subfolder of dir1
    dir111 //subfolder of dir11
    dir12 //subfolder of dir1
    file1A // document on dir1
    dir2 //subfolder of startingdir
    Tree.java
    import java.util.Iterator;
    import java.util.LinkedList;
    import java.util.ListIterator;
    import java.util.NoSuchElementException;
    import java.util.Deque;
    public class Tree<E> {
        // Each Tree object is an unordered tree whose
        // elements are arbitrary objects of type E.
        // This tree is represented by a reference to its root node (root), which
        // is null if the tree is empty. Each tree node contains a link to its
        // parent and a LinkedList of child nodes
        private Node root;
        //////////// Constructor ////////////
        public Tree () {
        // Construct a tree, initially empty.
            root = null;
        //////////// Accessors ////////////
        public boolean isEmpty () {
        // Return true is and only if this tree is empty.
             return (root == null);
        public Node root () {
        // Return the root node of this tree, or null if this tree is empty.
            return root;
        public Node parent (Node node) {
        // Return the parent of node in this tree, or null if node is the root node.
            return node.parent;
        public void makeRoot (E elem) {
        // Make this tree consist of just a root node containing element elem.
            root = new Node(elem);
        public Node addChild (Node node, E elem) {
        // Add a new node containing element elem as a child of node in this
        // tree. The new node has no children of its own. Return the node
        // just added.
            Node newChild = new Node(elem);
            newChild.parent = node;
            node.children.addLast(newChild);
            return newChild;
        public E element (Node node) {
             return node.getElement();
        //////////// Iterators ////////////
        public Iterator childrenIterator (Node node) {
            return node.children.iterator();
        public Iterator nodesPreOrder () {
        // Return an iterator that visits all nodes of this tree, with a pre-order
        // traversal.
            return new Tree.PreOrderIterator();
        //////////// Inner classes ////////////
        public class Node {
            // Each Tree.Node object is a  node of an
            // unordered tree, and contains a single element.
            // This tree node consists of an element (element),
            // a link to its parent
            // and a LinkedList of its children
            private E element;
            private Node parent;
            private LinkedList<Node> children;
            private Node (E elem) {
                // Construct a tree node, containing element elem, that has no
                // children and no parent.
                this.element = elem;
                this.parent = null;
                children = new LinkedList<Node>();
            public E getElement () {
            // Return the element contained in this node.
                return this.element;
            public String toString () {
            // Convert this tree node and all its children to a string.
                String children = "";
                // write code here to add all children
                return element.toString() + children;
            public void setElement (E elem) {
            // Change the element contained in this node to be elem.
                this.element = elem;
        public class PreOrderIterator implements Iterator {
            private Deque<Node> track; //Java recommends using Deque rather
            // than Stack. This is used to store sequence of nomempty subtrees still
            //to be visited
            private PreOrderIterator () {
                track = new LinkedList();
                if (root != null)
                    track.addFirst(root);
            public boolean hasNext () {
                return (! track.isEmpty());
            public E next () {
                Node place = track.removeFirst();
                //stack the children in reverse order
                if (!place.children.isEmpty()) {
                    int size = place.children.size(); //number of children
                    ListIterator<Node> lIter =
                            place.children.listIterator(size); //start iterator at last child
                    while (lIter.hasPrevious()) {
                        Node element = lIter.previous();
                        track.addFirst(element);
                return place.element;
            public void remove () {
                throw new UnsupportedOperationException();
        FileHierarchy.java
    import java.io.File;
    import java.util.Iterator;
    public class FileHierarchy {
        // Each FileHierarchy object describes a hierarchical collection of
        // documents and folders, in which a folder may contain any number of
        // documents and other folders. Within a given folder, all documents and
        // folders have different names.
        // This file hierarchy is represented by a tree, fileTree, whose elements
        // are Descriptor objects.
        private Tree fileTree;
        //////////// Constructor ////////////
        public FileHierarchy (String startingDir, int level) {
            // Construct a file hierarchy with level levels, starting at
            // startingDir
            // Can initially ignore level and construct as many levels as exist
            fileTree = new Tree();
            Descriptor descr = new Descriptor(startingDir, true);
            fileTree.makeRoot(descr);
            int currentLevel = 0;
            int maxLevel = level;
            addSubDirs(fileTree.root(), currentLevel, maxLevel);
        //////////// File hierarchy operations ////////////
        private void addSubDirs(Tree.Node currentNode, int currentLevel,
                int maxLevel) {
        // get name of directory in currentNode
        // then find its subdirectories (can add files later)
        // for each subdirectory:
        //    add it to children of currentNode - call addChild method of Tree
        //    call this method recursively on each child node representing a subdir
        // can initially ignore currentLevel and maxLevel   
            Descriptor descr = (Descriptor) currentNode.getElement();
            File f = new File(descr.name);
            File[] list = f.listFiles();
            for (int i = 0; i < list.length; ++i) {
                if (list.isDirectory()) {
    File[] listx = null;
    fileTree.addChild(currentNode, i);
    if (list[i].list().length != 0) {
    listx = list[1].listFiles();
    addSubDirs(currentNode,i,1);
    } else if (list[i].isFile()) {
    fileTree.addChild(currentNode, i);
    // The following code is sample code to illustrate how File class is
    // used to get a list of subdirectories from a starting directory
    // list now contains subdirs and files
    // contained in dir descr.name
    ////////// Inner class for document/folder descriptors. //////////
    private static class Descriptor {
    // Each Descriptor object describes a document or folder.
    private String name;
    private boolean isFolder;
    private Descriptor (String name, boolean isFolder) {
    this.name = name;
    this.isFolder = isFolder;
    FileHierarchyTest.javapublic class FileHierarchyTest {
    private static Tree fileTree;
    public static void main(String[] args) {
    FileHierarchy test = new FileHierarchy ("//test", 1);
    System.out.println(test.toString());

    Denis,
    Do you have [red hair|http://www.dennisthemenace.com/]? ;-)
    My advise with the tree structure is pretty short and sweet... make each node remember
    1. it's parent
    2. it's children
    That's how the file system (inode) actually works.
    <quote>
    The exact reasoning for designating these as "i" nodes is unsure. When asked, Unix pioneer Dennis Ritchie replied:[citation needed]
    In truth, I don't know either. It was just a term that we started to use. "Index" is my best guess, because of the
    slightly unusual file system structure that stored the access information of files as a flat array on the disk, with all
    the hierarchical directory information living aside from this. Thus the i-number is an index in this array, the
    i-node is the selected element of the array. (The "i-" notation was used in the 1st edition manual; its hyphen
    became gradually dropped).</quote>

Maybe you are looking for

  • Use bindings for a variable in sql

    Hello, I have the following query: select request_number, ktna_notes.request_notes(20, &request_number) from request_table where request_number = &request_number the &request_number is a variable within the database. I need to implement this in my AD

  • Bridge won't open within Photoshop CS6

    I have no problem opening bridge on its own, or if I right-click on an image in my folder, but if Photoshop is open and I click on the "Launch Bridge' button at the bottom, I see "Waiting for bridge to open" forever. And then if I launch bridge on it

  • File to RFC to File error "No receiver could be determined"

    Hi everybody. I have a errors in BPM ... <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> - <!--  Receiver Identification   --> - <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SO

  • Connect to dynamic link taking ages

    Win 7 64bit GTX 550TI i have created a new Encore project and gone to File/Dynamic link/import Premiere Pro. In the dialog box, I selected the appropriate PP file and now I'm seeing a "connecting to dynamic link server" with a barbers shop pole graph

  • Corrupted Harddrive! Stuck in disk utility!

    Upon starting up my Macbook Pro (Late 2011- Lion) gets stuck on the gray screen with the Apple symbol and the spinning gear. When I enter disk utility by ressing the option key at startup and verify my harddrive it tells me the disk needs to be repai