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.
          

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 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.

  • Catalog Tree doesn't show hidden folders

    Hi,
    I have set some folders in the presentation catalog to 'hidden' to hide from all users but for some roles Administrators & Authors I have permissioned the 'Show hidden items' privilege so they can see the folders. Both the Administrators & Authors can create new Analysis & dashboard prompts and see the hidden folders. However when i create a new dashboard and attempt to add content the hidden folders are not shown in the Catalog tree on the left hand side when in edit dashboard mode.
    Is this an known issue?
    Any help would be great
    Regards
    Adrian

    Hi Veeravalli
    I have tested it for an Administrator user and an Author user and the same issue applies (i.e. can't see the hidden folders in the catalog tree in dashboard edit mode)
    I'm running 11.1.1.6.1 on Linux 64
    Thanks
    Regards
    Adrian

  • Drill down in tree report

    Hi gurus,
    This is regarding the drill down in the Tree report.
    My scenario is,
    i am doing a budget variance report which displays the report in tree format.
    i have texts for different nodes in the tree, along with that i have a 10 feilds which i display using fieldcat in output along with nodes.
    now i want to have the drill down to the 2 of the fields, where it has to go to some transaction.
    i tried with hotspot in fieldcat definition but it is not working.
    please can u tell me a solution as how can i do this drill down.
    thanks in advance.
    u will be rewarded heavily.

    Hi Vipin,
    You can try with following example:
    *& Report  ZPRG                                                *
    &--INTERACTIVE ALV REPORT PROGRAM--
    &This program displays order detais for a particular customer----
    REPORT  zprg                              .
    --TYPE POOLS--
    TYPE-POOLS slis.
    --TABLES--
    TABLES : kna1, vbak.
    --DATA TYPES--
    TYPES : BEGIN OF ty_vbak,
    vbeln TYPE vbak-vbeln,
    erdat TYPE vbak-erdat,
    netwr TYPE vbak-netwr,
    END OF ty_vbak.
    TYPES : BEGIN OF ty_vbap,
    posnr TYPE vbap-posnr,
    arktx TYPE vbap-arktx,
    werks TYPE vbap-werks,
    END OF ty_vbap.
    --WORK AREAS--
                              FOR FIRST PAGE                            *
    DATA w_fcat TYPE slis_fieldcat_alv.   "Used as Header for Field Catalog
    DATA w_vbak TYPE ty_vbak.             "Used as Header for Data Table
    DATA w_events TYPE slis_alv_event.    "Used as header for Events Table
    DATA w_comments TYPE slis_listheader. "Used as Header for Comments Table
                               SECOND PAGE                              *
    DATA w2_fcat TYPE slis_fieldcat_alv.   "Used as Header for Field Catalog
    DATA w2_vbap TYPE ty_vbap.             "Used as Header for Data Table
    DATA w2_events TYPE slis_alv_event.    "Used as header for Events Table
    DATA w2_comments TYPE slis_listheader."Used as Header for Comments Table
    --INTERNAL TABLES--
                              FOR FIRST PAGE                            *
    DATA t_fcat TYPE slis_t_fieldcat_alv.   "Table for Field Catalog
    DATA t_vbak TYPE ty_vbak OCCURS 1.      "Data Table
    DATA t_events TYPE slis_t_event.        "Table for events
    DATA t_comments TYPE slis_t_listheader. "Comments table
                               SECOND PAGE                              *
    DATA t2_fcat TYPE slis_t_fieldcat_alv.   "Table for Field Catalog
    DATA t2_vbap TYPE ty_vbap OCCURS 1.      "Data Table
    DATA t2_events TYPE slis_t_event.        "Table for events
    DATA t2_comments TYPE slis_t_listheader. "Comments table
    *****************VIPIN: START*****************************
    DATA: V_REPID LIKE SY-REPID.
    V_REPID = SY-REPID.
    *****************VIPIN: END*******************************
    --SELECTION SCREEN--
    PARAMETERS p_custno TYPE kna1-kunnr.
    --FILLING FIELD CATALOG--
                              FOR FIRST PAGE                            *
    w_fcat-col_pos = 1.
    w_fcat-fieldname = 'VBELN'.
    w_fcat-seltext_m = 'ORDER NUMBER'.
    APPEND w_fcat TO t_fcat.
    w_fcat-col_pos = 2.
    w_fcat-fieldname = 'ERDAT'.
    w_fcat-seltext_m = 'ORDER DATE'.
    APPEND w_fcat TO t_fcat.
    w_fcat-col_pos = 3.
    w_fcat-fieldname = 'NETWR'.
    w_fcat-seltext_m = 'ORDER VALUE'.
    APPEND w_fcat TO t_fcat.
                               SECOND PAGE                              *
    w2_fcat-col_pos = 1.
    w2_fcat-fieldname = 'POSNR'.
    w2_fcat-seltext_m = 'ITEM NUMBER'.
    APPEND w2_fcat TO t2_fcat.
    w2_fcat-col_pos = 2.
    w2_fcat-fieldname = 'ARKTX'.
    w2_fcat-seltext_m = 'ITEM DESCRIPTION'.
    APPEND w2_fcat TO t2_fcat.
    w2_fcat-col_pos = 3.
    w2_fcat-fieldname = 'WERKS'.
    w2_fcat-seltext_m = 'PLANT'.
    APPEND w2_fcat TO t2_fcat.
    --FILLING DATA TABLE--
                              FOR FIRST PAGE                            *
    SELECT vbeln
           erdat
           netwr
    FROM vbak
    INTO TABLE t_vbak
    WHERE kunnr = p_custno.
    SORT t_vbak BY vbeln.
                               SECOND PAGE                              *
    DATA FOR 2ND PAGE IS FILLED IN THE SUBROUTINE HANDLING USER_COMMAND *
    --FILLING EVENTS TABLE--
    w_events-name = 'TOP_OF_PAGE'.
    w_events-form = 'SUB1'.
    APPEND w_events TO t_events.
    w_events-name = 'USER_COMMAND'.
    w_events-form = 'SUB2'.
    APPEND w_events TO t_events.
    --FILLING COMMENTS TABLE--
    w_comments-typ = 'H'.
    w_comments-info = 'CUSTOMER ORDER INFORMATION'.
    APPEND w_comments TO t_comments.
    w_comments-typ = 'S'.
    w_comments-key = 'Sold To Party'.
    w_comments-info = p_custno.
    APPEND w_comments TO t_comments.
    -----PASSING FIELD CATALOG AND THE DATA TABLE TO THE FUNCTION-----
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
        I_INTERFACE_CHECK                 = ' '
        I_BYPASSING_BUFFER                = ' '
        I_BUFFER_ACTIVE                   = ' '
          i_callback_program                = V_REPID
        I_CALLBACK_PF_STATUS_SET          = ' '
        I_CALLBACK_USER_COMMAND           = ' '
        I_CALLBACK_TOP_OF_PAGE            = ' '
        I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
        I_CALLBACK_HTML_END_OF_LIST       = ' '
        I_STRUCTURE_NAME                  =
        I_BACKGROUND_ID                   = ' '
        I_GRID_TITLE                      =
        I_GRID_SETTINGS                   =
        IS_LAYOUT                         =
          it_fieldcat                       = t_fcat
        IT_EXCLUDING                      =
        IT_SPECIAL_GROUPS                 =
        IT_SORT                           =
        IT_FILTER                         =
        IS_SEL_HIDE                       =
        I_DEFAULT                         = 'X'
        I_SAVE                            = ' '
        IS_VARIANT                        =
          it_events                         = t_events
        IT_EVENT_EXIT                     =
        IS_PRINT                          =
        IS_REPREP_ID                      =
        I_SCREEN_START_COLUMN             = 0
        I_SCREEN_START_LINE               = 0
        I_SCREEN_END_COLUMN               = 0
        I_SCREEN_END_LINE                 = 0
        IT_ALV_GRAPHICS                   =
        IT_HYPERLINK                      =
        IT_ADD_FIELDCAT                   =
        IT_EXCEPT_QINFO                   =
        I_HTML_HEIGHT_TOP                 =
        I_HTML_HEIGHT_END                 =
      IMPORTING
        E_EXIT_CAUSED_BY_CALLER           =
        ES_EXIT_CAUSED_BY_USER            =
      TABLES
        t_outtab                          = t_vbak
      EXCEPTIONS
        PROGRAM_ERROR                     = 1
        OTHERS                            = 2
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
                Subroutine for the Event TOP_OF_PAGE
    FORM sub1 .
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary       = t_comments
          i_logo                   = 'COMPANY LOGO'
      I_END_OF_LIST_GRID       =
    ENDFORM.                                                    " sub1
                Subroutine for the Event USER_COMMAND
    Here u_comm contains the function code of the selected function
    and slis_field is a structure containing cursor information
    FORM sub2 USING u_comm LIKE sy-ucomm rs_field TYPE slis_selfield.
    CASE u_comm.
        WHEN '&IC1'.
          IF rs_field-fieldname = 'VBELN'.
            SELECT posnr
                   arktx
                   werks
            FROM vbap INTO TABLE t2_vbap WHERE vbeln = rs_field-value.
          ENDIF.
      ENDCASE.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
        I_INTERFACE_CHECK                 = ' '
        I_BYPASSING_BUFFER                = ' '
        I_BUFFER_ACTIVE                   = ' '
        I_CALLBACK_PROGRAM                = ' '
        I_CALLBACK_PF_STATUS_SET          = ' '
        I_CALLBACK_USER_COMMAND           = ' '
        I_CALLBACK_TOP_OF_PAGE            = ' '
        I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
        I_CALLBACK_HTML_END_OF_LIST       = ' '
        I_STRUCTURE_NAME                  =
        I_BACKGROUND_ID                   = ' '
        I_GRID_TITLE                      =
        I_GRID_SETTINGS                   =
        IS_LAYOUT                         =
          it_fieldcat                       = t2_fcat
        IT_EXCLUDING                      =
        IT_SPECIAL_GROUPS                 =
        IT_SORT                           =
        IT_FILTER                         =
        IS_SEL_HIDE                       =
        I_DEFAULT                         = 'X'
        I_SAVE                            = ' '
        IS_VARIANT                        =
        IT_EVENTS                         =
        IT_EVENT_EXIT                     =
        IS_PRINT                          =
        IS_REPREP_ID                      =
        I_SCREEN_START_COLUMN             = 0
        I_SCREEN_START_LINE               = 0
        I_SCREEN_END_COLUMN               = 0
        I_SCREEN_END_LINE                 = 0
        IT_ALV_GRAPHICS                   =
        IT_HYPERLINK                      =
        IT_ADD_FIELDCAT                   =
        IT_EXCEPT_QINFO                   =
        I_HTML_HEIGHT_TOP                 =
        I_HTML_HEIGHT_END                 =
      IMPORTING
        E_EXIT_CAUSED_BY_CALLER           =
        ES_EXIT_CAUSED_BY_USER            =
        TABLES
          t_outtab                          = t2_vbap.
      EXCEPTIONS
        PROGRAM_ERROR                     = 1
        OTHERS                            = 2
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                                                    "sub2

  • Run time error on collapsing the catalog tree node

    Hi Experts,
    Scenario is of SAPCRM 7.0.
    On the Catalog page we get a tree in the left pane with all the poducts listed.
    We can expand/close the tree and see the products.
    While i select - (minus) and close the node, the system throws a run time error.
    Trace shows a run time error at SetItemPageSizeAction.
    Please help if any of you have faced a similar issue.
    Thanks,
    Rohit

    Hi Ashok,
    We have B2B webshop with ECC and CRM. Product catalog are all maintained in CRM.
    Where do i exactly need to check the xcm settings ?
    I went thru a bit with XCM but couldnt find the field mentioned by you.
    Thanks in anticipation,
    Rohit Sharma

  • 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

  • NMSP Down on MSE-PRIME-WLC

    Hi,
    I am trying to synchronize MSE with WLC by Prime.
    Everything is correct but the NMSP service does not synchronize between them.
    On the part of the WLC, OK, time and HASH, but in the MSE gives me the error of time.
    Not sure what else I can do, Has anyone had the same problem?
    Attach two images.
    Thanks for all

    MSE doesn't sync with WLC when added with PI 2.1.1
    CSCup93101
    Description
    Symptom:
    NMSP is not active between MSE and WLC when added using PI 2.1.1.
    Conditions:
    This applies to only MSE added Prime Infrastructure after upgrade to 2.1.1 on Prime Infrastructure.
    If the MSE was already added to Prime Infrastructure in 2.1 or previous releases, and then upgrade to PI 2.1.1 was performed customers will not run into the NMSP problem between MSE and WLC after the PI upgrade to PI 2.1.1.
    Workaround:
    Push a template (Templates > Features and Technologies > Controller > Security > AAA > AP or MSE Authorization) with MSE MAC address and key hash.
    Please contact Cisco TAC for a patch.
    Last Modified:
    Dec 11,2014
    Status:
    Fixed
    Severity:
    2 Severe
    Product:
    Network Level Service
    Known Affected Releases:
    (1)
    2.1(1)

  • 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 should inheritance of permissions on AD behave?

    Hi Forum members, I am not an AD expert in fact far from it. We have an in house software and we have used Active Directory to authenticate NT accounts to login to our application. In our application we can configure/setup AD groups in such a way that those
    group members can get access to specific features and servers in our application. Please see my situation described below:-
    I have the following config in place in my application:
    LondonGroup (a user group, as present in AD) can manage HR Module of server LondonServer.
    BirminghamGroup (as present in AD) can manage Finance Module of server BirminghamServer.
    So when a user of AD group LondonGroup logs in to our application, he/she can manage the HR module on LondonServer. Similarly when an user of BirminghamGroup logs in, he/she can manage Finance module on BirminghamServer. That's all fine. The issue arises
    when someone in AD makes BirminghamGroup a sub group of LondonGroup i.e. BirminghamGroup is a member of LondonGroup. When this is setup, when a user of AD group LondonGroup logs in to our application, he/she can manage the HR module on LondonServer -
    which is still fine BUT when a user of BirminghamGroup logs in he/she can now access HR and Finance modules of both LondonServer and BirminghamServer!! This could be because we support inheritance feature of AD where a sub group should get all access permissions
    from its parent group. But is this a problem? for e.g in our application we never set up BirminghamGroup to get access to HR module on LondonServer! 
    so my question is:
    1) Is this expected behaviour from AD point of view? Is this because the Group setup on the AD is wrong (but there is nothing stopping users to do this)
    2) Our application looks for the configured Groups and then traverses down the tree to locate the user and on the way additively gives access rights - is this a wrong implementation?
    Sorry for the long story but any guidance will be highly appreciated.

    1) Is this expected behaviour from AD point of view? Is this because the Group setup on the AD is wrong (but there is nothing stopping users to do this)
    2) Our application looks for the configured Groups and then traverses down the tree to locate the user and on the way additively gives access rights - is this a wrong implementation?
    Yes This is by design. There is nothing wrong in it. As Pierre mentioned it is called 'Group Nesting'.
    I believe your application is following the concepts of 'Group Nesting' which is fine. It is behaving properly.
    If you would like to not to have these sort of traversing in your application, you need to isolate the user accounts of being member in 'Nested Groups'.
    Mahdi Tehrani   |  
      |  
    www.mahditehrani.ir
    Please click on Propose As Answer or to mark this post as
    and helpful for other people.
    This posting is provided AS-IS with no warranties, and confers no rights.
    How to query members of 'Local Administrators' group in all computers?

Maybe you are looking for

  • Can I access my kids family share account from my iTunes account? It's the master account.

    I Have kids with family share iTunes accounts off of my master iTunes account. Is there a way I can get into their account from my Mac or iPad to check their account balance or even say, add a gift card to their account without having their iPads in

  • Disable delete option for a list? But where ?

    hi all, via Console Application I can hide/disbale the Delete This List option: static void Main(string[] args) SPSite site = new SPSite("http://localhost"); SPWeb web = site.OpenWeb(); SPList list = web.Lists["DemoList"]; list.AllowDeletion = false;

  • Runtime analysis for an RFC function Module

    Hi, How to get an Runtime analysis for an RFC function Module? I have an RFC function Module I am using it for a WEB INTERFACE . For this function Module I need to get Runtime Analysis. Please do not duplicate or cross post Edited by: Rob Burbank on

  • Error while Transport objects from DEv to QA-File transport

    Hai Experts! While exporting objects from Dev to Quality using File Transport. it taking long time and no erro msg is thown and it is not getting end .Did any face this problem. Can any one help me to solve this. Regard's Preethi.

  • Re: [iPlanet-JATO] No corresponding method

    Mike & John-- John, can you verify the return type of getRepeated1()? It should be pgClientSelectRepeated1TiledView. If not, then the compiler will not see the getdoCustomerModel() method. Perhaps you could also send the pgClientSelectRepeated1TiledV