To display all the Nodes in a Binary Search Trees

Hi,
I want to traverse through all the nodes in a binary tree. I know that there are traversals like Preorder,Postorder,Inorder. But I am not able to write a recursive code for performing this operation. Can anyone please help me or give me an idea how to write a code to do any one of these traversal.
Thanks a lot in advance.

Hi,
hmm .. how is a tree-node defined? - As so you have not posted a node-class, I will help you by demonstrating it for inOrder by normal language:
The Idea is as follows:
You have a root, that references to a tree-node. This tree-node has a value and 2 references to other tree-nodes, let's say they are named left and right. Because left an right are references to tree-nodes in the same way root is a reference to the tree-node, this fact can be used for recursive action on the tree.
if you like to display all values in the tree, what do you have to do in a node?
1. display the tree the left reference is pointing to
2. display the value-Field
3. display the tree the right reference is pointing to
that is inOrder, assuming all lesser values are in the left tree and all greater are in the right tree.
How to display the left and right trees?
The same way you display this node, but this time you use the left / right reference as the node.
So do it in pseudo-coding:
void DisplayTree(NodeClass aNode) {
if (aNode == null) return;
DisplayTree(aNode.left);
DisplayValue(aNode.value);
DisplayTree(aNode.right);
That is it - figure it out and try to write a program after this - good luck. To write one for pre-order and post-order should be easy if you have this one for inOrder.
greetings Marsian

Similar Messages

  • How to use evdre to display all the levels under the node user choose

    I used SELF,LDEP(6) in the memberset of evdre trying to display all the 6 levels from the top node of NetIncome, all the display all the level with the correct amount except the top node which is displayed in the row key, but all the cell which should be the aggregation of all it's children is blank, if I choose only self, it shows the amount with only top level. how could I all the level and the corresponding amount display?

    Hi,
    Did you try SELF,ALL ?
    Hope it works...
    regards,
    Raju

  • Cannot display all the tables of the schema!!!

    Hi:
    I use the oracle sql developer on the windows xp, I found that the tables tab cannot display all the tables of the schema owner, I use the sql "select count(*) from user_tables" I found the result is more than the tab can be display, and I also press the "show more" already.... does anyone can help me ???

    Similarly, I have 852 tables owned by the connected user (selected count from user_tables and checked the user tables report which has this many records returned), but when I double-click on the "Show More" and select Show All, I only get approximately 375 tables listed.
    It doesn't help that the sorting is different - ie ASF_ comes before ASFB in the connection pane but the other way around in the report.
    However, it looks as though the problem is that tables that are not analysed (based on the report data in DATE_LAST_ANALYZED) are not being displayed under the Table node.

  • Af:tree inside af:accordion is not showing all the nodes

    Hi All,
    I am using Oracle JDeveloper 11g Release 2.
    I have af:tree enclosed inside af:panelStretchLayout, displaying data from database table. af:tree is not displaying all data(nodes) in the space available to it. It is hiding the data at middle. I have tried number of options but in vein. The code is given below:
    <af:panelAccordion id="pa1">
                                    <af:showDetailItem text="Browse Course Categories" id="sdi1" icon="/Images/tree.png">
                                        *<af:panelStretchLayout id="psl112">*
                                            *<f:facet name="center">*
                                                <af:tree value="#{bindings.BaseCourseCategories1.treeModel}" var="node"
                                                         selectionListener="#{bindings.BaseCourseCategories1.treeModel.makeCurrent}"
                                                         rowSelection="single" id="t3" *styleClass="AFStretchWidth"*>
                                                    <f:facet name="nodeStamp">
                                                        <af:outputText value="#{node.CategoryTitle}" id="ot4"/>
                                                    </f:facet>
                                                    <f:facet name="contextMenu">
                                                        <af:popup childCreation="deferred" autoCancel="disabled" id="p1">
                                                            <af:menu text="Course Categories" id="m1">
                                                                <af:commandMenuItem text="Show Categories" id="cmi1"
                                                                                    actionListener="#{SelectAllCategoryBean.refreshChildCategories}"
                                                                                    action="refresh">
                                                                    <f:attribute name="CategoryId"
                                                                                 value="#{node.CategoryId}"/>
                                                                </af:commandMenuItem>
                                                                <af:commandMenuItem id="cmi2" text="Add Category"
                                                                                    action="goCreateCourseCats"/>
                                                            </af:menu>
                                                        </af:popup>
                                                    </f:facet>
                                                </af:tree>
                                            </f:facet>
                                        </af:panelStretchLayout>
                                    </af:showDetailItem>
                                </af:panelAccordion>Any guidance or help....
    Thanks in advance
    Bilal

    Hi Peter,
    I have checked for stretchChildren="first" property of af:panelAccordion, but didn,t found.
    Thanks for response.
    Regards
    Bilal

  • Building tree when we know all the nodes and levels

    Hi Experts,
    What is the best way to implement tree in web dynpro for abap when we know all the nodes, there levels and parents.
    I have the structure like this:
    id        text             level     parent
    1        root                1         1
    1.1 ;    node1.1 ;      2         1
    1.1.1 ; node 1.1.1 ;  3        1.1
    1.2 ;    node1.2 ;      2        1
    it could be up to 10 levels with hundreds of nodes
    Thanks,
    Anthony

    hi
    Refer this online help:
    http://help.sap.com/saphelp_nw70ehp1/helpdata/en/21/ad884118aa1709e10000000a155106/content.htm
    check the WDA : WDR_TEST_TREE,WDT_TREE,WDT_TREE_TABLE_BY_KEY,WDT_TREE_TABLE_BY_NST.
    refer this wiki :
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/profile/2007/09/11/integrationofTreeStructureinaTableusingWebdynpro+Abap&
    refer this  thread :
    creating tree
    regards,
    amit

  • Show all the drives of a system in Tree format as it displays in windows

    Hi, I have the folloing code which is working fine to display a single drives files and folders but i want to display all the drives of my system with desktop and Doc & Settings in a single trre.
    please help.
    thanks in advanceimport javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.tree.*;
    import java.io.File;
    public class FileTreeDemo
         public static void main(String[] args)
                  File root;
              if (args.length > 0) root = new File(args[0]);
                  else root = new File(System.getProperty("user.home"));   
              /*root=new File("F:\\");
              System.out.println("value of root :"+root);*/
                  FileTreeModel model = new FileTreeModel(root);   
                  JTree tree = new JTree();
                  tree.setModel(model);
              root=new File("E:\\");
                 model = new FileTreeModel(root);
              tree.setModel(model);
              tree.setRootVisible(true);
                  JScrollPane scrollpane = new JScrollPane(tree);   
                  JFrame frame = new JFrame("FileTreeDemo");
                  frame.getContentPane().add(scrollpane, "Center");
                  frame.setSize(400,600);
                  frame.setVisible(true);
    class FileTreeModel implements TreeModel
         protected File root;
           public FileTreeModel(File root) { this.root = root; } 
           public Object getRoot() { return root; } 
           public boolean isLeaf(Object node) {  return ((File)node).isFile(); }
         public int getChildCount(Object parent)
                  String[] children = ((File)parent).list();
                  if (children == null) return 0;
                  return children.length;
           public Object getChild(Object parent, int index)
                  String[] children = ((File)parent).list();
                  if ((children == null) || (index >= children.length)) return null;
                  return new File((File) parent, children[index]);
           public int getIndexOfChild(Object parent, Object child)
                  String[] children = ((File)parent).list();
                  if (children == null) return -1;
                       String childname = ((File)child).getName();
                  for(int i = 0; i < children.length; i++)
                         if (childname.equals(children)) return i;
              return -1;
         public void valueForPathChanged(TreePath path, Object newvalue) {}
         public void addTreeModelListener(TreeModelListener l) {}
         public void removeTreeModelListener(TreeModelListener l) {}

    Hi,
    Use the FileSystemView class of javax.swing.filechooser
    create an instance of the view and choose the method:
    File root = FileSystemView.getHomeDirectory();as your root file object.
    Maybe you need to do some modifications on your FileTreeModel...
    under windows the desktop node and the first level nodes down from there
    are not real file-objects ...
    Olek

  • Binding with all the nodes to the table

    Hi,
    I have requirement like this,
    I have table in which data is displayed using BAPI.
    In my BAPI , there are four tables.
    My criteria is to bind the values to the table from the four nodes which is mapped from BAPI.
    But I can't able to bind the value form all the nodes, it allowing me to only bind form one node.
    Please help me with the procedure to bind the values to the table from all the nodes in the context.
    Thanks,
    Anitha

    Hi Anita,
    I had a similar requirement and resolved my problem by following the below procedure. Try this, it might help you.
    I have got 3 Nodes coming from a BAPI
    Model Node Root--
           Model Node A---
              Attribute- 1
              Attribute- 2
          Model Node B--
              Attribute- X
              Attribute- Y
          Model Node C--
             Attribute- F
             Attribute- G
    Now I want bind all these Nodes to one table. So, I created a "Value Node" - V under Model Node Root. Then create Value Attributes under Node -V with the similar names of the above Model Node attributes and then change their "Type" property exactly same as the Model Attributes Type.
    Then, create a Table and then Bind the table to the Value  Node. Now, in your wdDoinit Method of your Component Controller, give this code
    WDCopyService.copyElements(wdContext.node<modelnode>, wdContext.node<valuenode>);
    Later in your View Implementation give the following Code.
    IPrivate<Name>View.ISourceValueNode iSourceValueNode= wdContext.nodeSourceValueNode();
    IPrivate<Name>View.ISourceValueElement iSourceValueElement;
    IPrivate<Name>View.ITargetRFC Element iTargetRFCElement;
    for(int i=0;i<wdContext.nodeTargetRFC().size();i++){
    iTargetRFCElement = wdContext.nodeTargetRFC().getTargetRFCElementAt(i);
    iSourceValueElement = iSourceValueNode.createSourceValueNodeElement();
    iSourceValueElement.set<attribute name>(iTargetRFCElement.get<Attribute name>());
    iSourceValueNode.addElement(iSourceValueElement);
    iSourceValueNode.moveNext();
    I hope this helps you. Let me know if you need any information.
    Regards,
    Gopal.

  • How can i display all the query items to a table?

    how can i display all the query items to a table in a jsp file?
    i always have an out of memory error..

    any body??any idea?
    is it possible thru configuration or i have to write a program by the abaper??
    Biswa

  • How can I display all the columns on the screen without scrolling from side to side?

    My clinic software has many columns. How can I display all the columns without having to scroll from left to right all the time?

    If the software you are using doesn't offer the ability to increase or decrease document size, as many do, then the only way is to increase your screen resolution. If that's not possible, maybe you can decrease your font size?  If you can't do any of these, I think you're out of luck!

  • How can I get my iPod touch to display all the artwork on my computer?

    Hi,
    I have an iPod touch 4th gen 32 GB with iOS 6.1 on it.  I have trouble getting it to display all the album artwork that I have on my computer.  Not all of my music has it, but about 90% of it does.  Is there any way I can make it display everything that's on my computer?  I have iTunes 11 on it and it is a Windows 7 computer.  Thanks!

    First, try a system reset.  It cures many ills and it's quick, easy and harmless...
    Hold down the on/off switch and the Home button simultaneously until the screen blacks out or you see the Apple logo.  Ignore the "Slide to power off" text if it appears.  You will not lose any apps, data, music, movies, settings, etc.
    If the Reset doesn't work, try a Restore.  Note that it's nowhere near as quick as a Reset.  Connect via cable to the computer that you use for sync.  From iTunes, select the iPad/iPod and then select the Summary tab.  Follow directions for Restore and be sure to say "yes" to the backup.  You will be warned that all data (apps, music, movies, etc.) will be erased but, as the Restore finishes, you will be asked if you wish the contents of the backup to be copied to the iPad/iPod.  Again, say "yes."
    At the end of the basic Restore, you will be asked if you wish to sync the iPad/iPod.  As before, say "yes."  Note that that sync selection will disappear and the Restore will end if you do not respond within a reasonable time.  If that happens, only the apps that are part of the IOS will appear on your device.  Corrective action is simple -  choose manual "Sync" from the bottom right of iTunes.
    If you're unable to do the Restore, go into Recovery Mode per the instructions here.

  • How do i expand all the nodes in a jtree

    Hi,
    I am working on a project where i need to expand all the nodes of a jtree i have tried a few different ways but it never seems to expand all the nodes..
    I would be very greatful if someone could point me in the right direction
    cheers
    Mary

    you could use the following method that expands nodes recursively
    expandNode( myTree, myRootNode, new TreePath( myRootNode ) );
    public static void expandNode( JTree tree, TreeNode node, TreePath path ) {
        tree.expandPath( path );
        int i = node.getChildCount( );
        for ( int j = 0; j< i; j++ ) {
            TreeNode child = node.getChildAt( j );
            expandNode( tree, child , path.pathByAddingChild( child ) );
    }

  • Desktop is no longer displaying all the colors on it's monitor.

    My desktop computer is no longer displaying all the colors on its montior.  I've replaced the monitor with a known good one and the problem remains the same.  The desktop is 6 months old and when I purchased it, the first one had to be replaced because of this exact same issue. This appears to be a common problem.  Is anyone else experienced this is issue and has HP recalled any of these specific desktop's because of it?  

    Wjile there can be no consolation with your plight, you do have the replacement option under warrant.  BTW, it does help if you state the exact model or product #.   Saying a "series" is like called out that I had a Chevy.

  • Report to display all the contacts of an opportunity.

    Hello,
    I have a requirement, can we create a report which displays all the contacts of an opportunity apart from primary contact.
    Any inputs on the same will be appreciatable. TIA
    Edited by: 1004233 on May 6, 2013 12:16 AM
    Edited by: 1004233 on May 6, 2013 3:28 AM
    Edited by: 1004233 on May 6, 2013 3:28 AM

    Hey Aveek;
       Try this, which will get the most recent one.  You would just need to change it to loop at the edids records to get at them all...
          TABLES: *edidc, *edids, *t100.
          DATA: wf_string type string.
          CLEAR *edids.
          SELECT SINGLE *
             INTO *edids
             FROM edids
             WHERE docnum = *edidc-docnum
               AND status = '51'.
          SELECT SINGLE text
             INTO *t100-text
             FROM t100
             WHERE sprsl = 'EN'
               AND arbgb = *edids-stamid
               AND msgnr = *edids-stamno.
             CLEAR wf_string.
          MOVE *edids-stapa1 TO wf_string.
          REPLACE '&' WITH wf_string INTO *t100-text.
          IF sy-subrc EQ 0.
            CLEAR wf_string.
            MOVE *edids-stapa2 TO wf_string.
            REPLACE '&' WITH wf_string INTO *t100-text.
            IF sy-subrc EQ 0.
              CLEAR wf_string.
              MOVE *edids-stapa3 TO wf_string.
              REPLACE '&' WITH wf_string INTO *t100-text.
              IF sy-subrc EQ 0.
                CLEAR wf_string.
                MOVE *edids-stapa4 TO wf_string.
                REPLACE '&' WITH wf_string INTO *t100-text.
              ENDIF.
            ENDIF.
          ENDIF.
          A little sloppy (OK, alot!), but it gets the job done...
    Cheers,
    John

  • RAC Instalation Problem (shared accross all the nodes in the cluster)

    All experts
    I am trying for installing Oracle 10.2.0 RAC on Redhat 4.7
    reff : http://www.oracle-base.com/articles/10g/OracleDB10gR2RACInstallationOnLinux
    All steps successfully completed on all nodes (rac1,rac2) every thing is okey for each node
    on single node rac instalation successfull.
    when i try to install on two nodes
    on specify Oracle Cluster Registry (OCR) location showing error
    the location /nfsmounta/crs.configuration is not shared accross all the nodes in the cluster. Specify a shared raw partation or cluster file system file that is visible by the same name on all nodes of the cluster.
    I create shared disks on all nodes as:
    1 First we need to set up some NFS shares. Create shared disks on NAS or a third server if you have one available. Otherwise create the following directories on the RAC1 node.
    mkdir /nfssharea
    mkdir /nfsshareb
    2. Add the following lines to the /etc/exports file. (edit /etc/exports)
    /nfssharea *(rw,sync,no_wdelay,insecure_locks,no_root_squash)
    /nfsshareb *(rw,sync,no_wdelay,insecure_locks,no_root_squash)
    3. Run the following command to export the NFS shares.
    chkconfig nfs on
    service nfs restart
    4. On both RAC1 and RAC2 create some mount points to mount the NFS shares to.
    mkdir /nfsmounta
    mkdir /nfsmountb
    5. Add the following lines to the "/etc/fstab" file. The mount options are suggestions from Kevin Closson.
    nas:/nfssharea /nfsmounta nfs rw,bg,hard,nointr,tcp,vers=3,timeo=300,rsize=32768,wsize=32768,actimeo=0 0 0
    nas:/nfsshareb /nfsmountb nfs rw,bg,hard,nointr,tcp,vers=3,timeo=300,rsize=32768,wsize=32768,actimeo=0 0 0
    6. Mount the NFS shares on both servers.
    mount /mount1
    mount /mount2
    7. Create the shared CRS Configuration and Voting Disk files.
    touch /nfsmounta/crs.configuration
    touch /nfsmountb/voting.disk
    Please guide me what is wrong

    I think you did not really mount it on the second server. what is the output of 'ls /nfsmounta'.
    step 6 should be 'mount /nfsmounta', not 'mount 1'. I also don't know if simply creating a zero-size file is sufficient for ocr (i have always used raw devices, not nfs for this)

  • How to display All the rows in a Table

    Hi All,
    Our requirement is, we need to display all the records of an VO in a table. We should not have navigation bar with previous and next. Runtime only will come to know how many records the VO has. Is it possible to achieve our requirement using setNumberOfRowsDisplayed() method in OATableBean ?

    Do u want to do it declaratively or programmatically.
    Declaratively You can set no of rows property of table bean. If u want to set it programmatically then u can do it as discussed in the thread..
    Regards,
    Ram

Maybe you are looking for