Help with a node tree

hi guys here's the problem i'm having:
I have a class called Node that I am building a tree out of. Node is a very simple structure, has three parts: element, left and right, with element being the top. Then I have a class called converterTree. This class will take in a postfix (polish notation) string and convert it into a tree through tokenizing etc. for an ultimate calculator class. The code I will post below uses a stack implementation to do so. It should: add all operands to the stack until it hits an operator, then make a new node with the operator as the element, and the left and right are the top and second stack objects respectively. then it pushes this entire tree back onto the stack and keeps going, at each step creating a new tree and linking it to the old one. The problem is that for some reason when I get the top node back in the return, it comes back as only that node, as if all the things it referenced are gone. You wont be able to run the code below since it needs some other classes, but in my main method where all those printlns are know that the return comes back as -, null, null, null, null, null, null with - being the thing on the stack that is SUPPOSED to link to the rest of them, yet for some reason they all come back null? any suggestions? heres the code:
import java.util.StringTokenizer;
public class ConverterTree
     String stringToConvert;
     static QueueLi returnQueue = new QueueLi();
     public ConverterTree (String toConvert)
          stringToConvert = toConvert;
     public static boolean isOperator(String op)
          char c = op.charAt(0);
          return (c == '*'|| c =='/' || c == '+' || c =='-');
     public static boolean isLParen (String op )
          char c = op.charAt(0);
          return c== '(';
     public static boolean isRParen (String op)
          char c = op.charAt(0);
          return c == ')';
     public static boolean isSpace(String op)
          char c = op.charAt(0);
          return c == ' ';
     public static boolean isOperand (String op)
          return (!( isOperator(op) || isLParen(op) || isRParen(op) || isSpace(op)));
     public Node toTree (String toConvert)
          String delims = new String("+-/* ");
          StringTokenizer tokenizer = new StringTokenizer(stringToConvert, delims, true);
          String token = new String();
          StackLi stack = new StackLi();
          while (tokenizer.hasMoreTokens())
               token = tokenizer.nextToken();
               System.out.println("token: " + token);
               if (isOperand(token))
                    ListNode node1 = new ListNode(token);
                    System.out.println("This operand is being pushed: " + token);
                    stack.push(token);
               else if (isOperator(token))
                    Node op2 = new Node(stack.topAndPop());
                    Node op1 = new Node(stack.topAndPop());
                    Node opTree = new Node(token, op1, op2);
                    System.out.println("node and left and right: " + opTree.element + opTree.left + opTree.right);
                    stack.push(opTree);
                    System.out.println("node and left and right: " + opTree.element + opTree.left + opTree.right);
          Node returnNode = new Node(stack.topAndPop());
          return returnNode;
     public static void main (String [] args)
          String toConvert1 = "2 5 + 6 8 + -";
          ConverterTree treeTest = new ConverterTree(toConvert1);
          Node testNode = treeTest.toTree(toConvert1);
          Node right = new Node(testNode.right);
          Node left = new Node(testNode.left);
          System.out.println(testNode);
          System.out.println(left);
          System.out.println(right);
          System.out.println(left.left);
          System.out.println(left.right);
          System.out.println(right.left);
          System.out.println(right.right);
}

hi guys here's the problem i'm having:
I have a class called Node that I am building a tree out of. Node is a very simple structure, has three parts: element, left and right, with element being the top. Then I have a class called converterTree. This class will take in a postfix (polish notation) string and convert it into a tree through tokenizing etc. for an ultimate calculator class. The code I will post below uses a stack implementation to do so. It should: add all operands to the stack until it hits an operator, then make a new node with the operator as the element, and the left and right are the top and second stack objects respectively. then it pushes this entire tree back onto the stack and keeps going, at each step creating a new tree and linking it to the old one. The problem is that for some reason when I get the top node back in the return, it comes back as only that node, as if all the things it referenced are gone. You wont be able to run the code below since it needs some other classes, but in my main method where all those printlns are know that the return comes back as -, null, null, null, null, null, null with - being the thing on the stack that is SUPPOSED to link to the rest of them, yet for some reason they all come back null? any suggestions? heres the code:
import java.util.StringTokenizer;
public class ConverterTree
     String stringToConvert;
     static QueueLi returnQueue = new QueueLi();
     public ConverterTree (String toConvert)
          stringToConvert = toConvert;
     public static boolean isOperator(String op)
          char c = op.charAt(0);
          return (c == '*'|| c =='/' || c == '+' || c =='-');
     public static boolean isLParen (String op )
          char c = op.charAt(0);
          return c== '(';
     public static boolean isRParen (String op)
          char c = op.charAt(0);
          return c == ')';
     public static boolean isSpace(String op)
          char c = op.charAt(0);
          return c == ' ';
     public static boolean isOperand (String op)
          return (!( isOperator(op) || isLParen(op) || isRParen(op) || isSpace(op)));
     public Node toTree (String toConvert)
          String delims = new String("+-/* ");
          StringTokenizer tokenizer = new StringTokenizer(stringToConvert, delims, true);
          String token = new String();
          StackLi stack = new StackLi();
          while (tokenizer.hasMoreTokens())
               token = tokenizer.nextToken();
               System.out.println("token: " + token);
               if (isOperand(token))
                    ListNode node1 = new ListNode(token);
                    System.out.println("This operand is being pushed: " + token);
                    stack.push(token);
               else if (isOperator(token))
                    Node op2 = new Node(stack.topAndPop());
                    Node op1 = new Node(stack.topAndPop());
                    Node opTree = new Node(token, op1, op2);
                    System.out.println("node and left and right: " + opTree.element + opTree.left + opTree.right);
                    stack.push(opTree);
                    System.out.println("node and left and right: " + opTree.element + opTree.left + opTree.right);
          Node returnNode = new Node(stack.topAndPop());
          return returnNode;
     public static void main (String [] args)
          String toConvert1 = "2 5 + 6 8 + -";
          ConverterTree treeTest = new ConverterTree(toConvert1);
          Node testNode = treeTest.toTree(toConvert1);
          Node right = new Node(testNode.right);
          Node left = new Node(testNode.left);
          System.out.println(testNode);
          System.out.println(left);
          System.out.println(right);
          System.out.println(left.left);
          System.out.println(left.right);
          System.out.println(right.left);
          System.out.println(right.right);
}

Similar Messages

  • Help with Minimum Spanning Tree

    Hello, I need some help with Kruskal's Algorithm, Thanks. This is the link:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=325804&tstart=0&trange=15

    I don't think the error is mine. I copied the link just as it shows on the address bar.
    http://forum.java.sun.com/thread.jsp?forum=31&thread=325804

  • Help with a binary tree

    I'm writing a binary tree class and am having some trouble with the Insert function. Here is the code for the TreeNode class...
    public class TreeNode
         TreeNode Left;
         TreeNode Right;
         String Name;
         public TreeNode(String NodeName)
              Left = null;
              Right = null;
              Name = NodeName;
    }And this is the code for the Tree class...
    public class Tree
         TreeNode Root;
         public Tree(String RootNode)
              Root = new TreeNode(RootNode);
         public void Insert(String Name)
              InsertNode(Root, Name);
         public void InsertNode(TreeNode t, String NodeName)
              if (t == null)
                   t = new TreeNode(NodeName);
              else
                   if (NodeName.compareTo(t.Name) < 0)
                        InsertNode(t.Left, NodeName);
                   else if (NodeName.compareTo(t.Name) > 0)
                        InsertNode(t.Right, NodeName);
                   else if (NodeName.compareTo(t.Name) == 0)
                        System.out.println("Entered node that was already in Tree");
    }When I enter a new node into a Tree containing just the root, it follows the recursion through once, then creates the new TreeNode as it should. However, the new node is not really recognized by the tree because when I try to insert another node, it only finds the root in the tree and only goes through one recursion. What's wrong?

    I believe t.Left (or t.Right) is getting set in the line
    t = new TreeNode(NodeName);
    Since it is a recursive function, when it is called the second time, the "t" that is passed in is actually the original t.left (I think), which is getting set then.

  • Help with JTree node handles icon

    Hi
    In my application i use Jtree to display the hirearchical data.But i don't want to the node handles icon to be displayed in the screen.The root node handle icon will be not be displayed if we set jtree.setShowsRootHandles(false) .Is there any way to diable the other node handles icons too?.Please help me in overcoming the problem.
    So, i will be handling the expand/collapse operations of the node with the help of mouse click event.
    Thanks in advance.
    Regards,
    Krish.

    Hi all,
    Any ideas to overcome this problem.?
    Thanks,
    Krish

  • Help with property node

    I have a graph chart with 3 plots. I can make any of the plots visible or not using property node as shown in the attached file.
    Is there a any way I can scale the block diagram and use less case structure . for instance is it possible to use just one case structure to set the plot visible property of the three plots.
    Thank you.
    Attachments:
    PropertyNodeChartAssign.vi ‏29 KB

    (You are using way too much code for these cases! Your true and false cases only differ by the boolean, which you already have from the control. In a first cleanup, you can delete the case structure and wire the button directly to the "visible" property. Same functionality! Right?)
    Still, that's not the way to go!
    Property nodes are expensive! You only need to write these properties if one of the selector changes, and not with every iteration of the loop! You should handle these thing in a seperate loop using an event structure. Attached is a simple example. See if it makes sense.
    Notice that the bottom loop waits until needed and rarely spins.
    Also: Instead of a column of similar controls, use an array of controls. Instead of using thee sets of "dices" use one in a FOR loop.
    Message Edited by altenbach on 05-18-2007 08:32 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ChartVisible.png ‏16 KB
    PropertyNodeChartAssignMOD.vi ‏28 KB

  • Need help with creating B*Tree XMLIndex on a structured object-relational xmltype column

    The following is my schema:
    CREATE TABLE TST_AUDIT_TBL
       NOTE                  VARCHAR2(25 CHAR)     null,
       CHANGE_HISTORY        XMLTYPE               not null,
       CHANGE_HISTORY_EXT    XMLTYPE               null
    XMLTYPE COLUMN CHANGE_HISTORY STORE AS OBJECT RELATIONAL XMLSCHEMA "http://www.oracle.com/a.xsd" element "A"
    XMLTYPE COLUMN CHANGE_HISTORY_EXT STORE AS CLOB XMLSCHEMA "http://www.oracle.com/a.xsd" element "AX"
    XML Schema for the above is defined as follows:
    <schema targetNamespace="http://www.oracle.com/a.xsd"
            xmlns:a="http://www.oracle.com/a.xsd"
            xmlns="http://www.w3.org/2001/XMLSchema"  elementFormDefault="qualified">
        <complexType name="AuditExtType">
          <sequence>
            <element name="C" maxOccurs="unbounded" minOccurs="0">
              <complexType>
                <sequence>
                  <element type="string" name="CN"/>
                  <element type="string" name="OV" minOccurs="0" maxOccurs="1"/>
                  <element type="string" name="NV" minOccurs="0" maxOccurs="1"/>
                </sequence>
              </complexType>
            </element>
          </sequence>
        </complexType>
        <complexType name="AuditType">
          <sequence>
            <element type="string" name="M" maxOccurs="1" minOccurs="0"/>
            <element type="string" name="O"/>
            <element name="B" maxOccurs="1" minOccurs="0">
              <complexType>
                <sequence>
                  <element name="BC" minOccurs="1" maxOccurs="unbounded">
                    <complexType>
                      <sequence>
                        <element type="string" name="BN"/>
                        <element name="F" maxOccurs="unbounded" minOccurs="0">
                          <complexType>
                            <sequence>
                              <element type="string" name="FN"/>
                              <element type="string" name="OV" minOccurs="0" maxOccurs="1"/>
                              <element type="string" name="NV" minOccurs="0" maxOccurs="1"/>
                            </sequence>
                          </complexType>
                        </element>
                      </sequence>
                    </complexType> 
                  </element>
                </sequence>
              </complexType>
            </element>
            <element name="T" maxOccurs="1" minOccurs="0">
              <complexType>
                <sequence>
                  <element name="TL" minOccurs="1" maxOccurs="unbounded">
                    <complexType>
                      <sequence>
                        <element type="string" name="TN"/>
                        <element name="C" maxOccurs="unbounded" minOccurs="0">
                          <complexType>
                            <sequence>
                              <element type="string" name="CN"/>
                              <element type="string" name="OV" minOccurs="0" maxOccurs="1"/>
                              <element type="string" name="NV" minOccurs="0" maxOccurs="1"/>
                            </sequence>
                          </complexType>
                        </element>
                      </sequence>
                    </complexType>
                  </element>
                </sequence>
              </complexType>
            </element>
            <element name="I" maxOccurs="1" minOccurs="0">
              <complexType>
                <sequence>
                  <element name="K" maxOccurs="unbounded" minOccurs="0">
                    <complexType>
                      <sequence>
                        <element type="string" name="N"/>
                        <element type="string" name="V"/>
                      </sequence>
                    </complexType>
                  </element>
                </sequence>
              </complexType>
            </element>
          </sequence>
        </complexType>
        <element name="A" type="a:AuditType"/>
        <element name="AX" type="a:AuditExtType"/>
    </schema>
    I want to create a B*Tree XML Index on the above table for the following:
    1. CN
    2. TN
    in the above schema.
    Following the doc, this is what I am issuing:
    SQL> CREATE INDEX audt_audit_idx1 ON TST_AUDIT_TBL(CHANGE_HISTORY) INDEXTYPE IS XDB.XMLINDEX PARAMETERS ('XMLTABLE IXTAB
      2  XMLNAMESPACES(DEFAULT ''http://www.oracle.com/a.xsd''), ''/A'' COLUMNS COLUMN_NAME VARCHAR2(128) PATH ''A/T/TL/C/CN'' ');
    CREATE INDEX audt_audit_idx1 ON TST_AUDIT_TBL(CHANGE_HISTORY) INDEXTYPE IS XDB.XMLINDEX PARAMETERS ('XMLTABLE IXTAB
    ERROR at line 1:
    ORA-29958: fatal error occurred in the execution of ODCIINDEXCREATE routine
    ORA-19276: XPST0005 - XPath step specifies an invalid element/attribute name:
    (A)
    Not sure what is going wrong (and what would be a working xmlindex will look like?)

    Here goes...
    1) Schema registration
    begin
    dbms_xmlschema.registerSchema(
      schemaURL => 'http://www.oracle.com/a.xsd'
    , local     => true
    , genTypes  => true
    , genTables => false
    , enableHierarchy => dbms_xmlschema.ENABLE_HIERARCHY_NONE
    , schemaDoc =>
    '<schema targetNamespace="http://www.oracle.com/a.xsd"
            xmlns:a="http://www.oracle.com/a.xsd"
            xmlns="http://www.w3.org/2001/XMLSchema"  elementFormDefault="qualified">
        <complexType name="AuditExtType">
          <sequence>
            <element name="C" maxOccurs="unbounded" minOccurs="0">
              <complexType>
                <sequence>
                  <element type="string" name="CN"/>
                  <element type="string" name="OV" minOccurs="0" maxOccurs="1"/>
                  <element type="string" name="NV" minOccurs="0" maxOccurs="1"/>
                </sequence>
              </complexType>
            </element>
          </sequence>
        </complexType>
        <complexType name="AuditType">
          <sequence>
            <element type="string" name="M" maxOccurs="1" minOccurs="0"/>
            <element type="string" name="O"/>
            <element name="B" maxOccurs="1" minOccurs="0">
              <complexType>
                <sequence>
                  <element name="BC" minOccurs="1" maxOccurs="unbounded">
                    <complexType>
                      <sequence>
                        <element type="string" name="BN"/>
                        <element name="F" maxOccurs="unbounded" minOccurs="0">
                          <complexType>
                            <sequence>
                              <element type="string" name="FN"/>
                              <element type="string" name="OV" minOccurs="0" maxOccurs="1"/>
                              <element type="string" name="NV" minOccurs="0" maxOccurs="1"/>
                            </sequence>
                          </complexType>
                        </element>
                      </sequence>
                    </complexType>
                  </element>
                </sequence>
              </complexType>
            </element>
            <element name="T" maxOccurs="1" minOccurs="0">
              <complexType>
                <sequence>
                  <element name="TL" minOccurs="1" maxOccurs="unbounded">
                    <complexType>
                      <sequence>
                        <element type="string" name="TN"/>
                        <element name="C" maxOccurs="unbounded" minOccurs="0">
                          <complexType>
                            <sequence>
                              <element type="string" name="CN"/>
                              <element type="string" name="OV" minOccurs="0" maxOccurs="1"/>
                              <element type="string" name="NV" minOccurs="0" maxOccurs="1"/>
                            </sequence>
                          </complexType>
                        </element>
                      </sequence>
                    </complexType>
                  </element>
                </sequence>
              </complexType>
            </element>
            <element name="I" maxOccurs="1" minOccurs="0">
              <complexType>
                <sequence>
                  <element name="K" maxOccurs="unbounded" minOccurs="0">
                    <complexType>
                      <sequence>
                        <element type="string" name="N"/>
                        <element type="string" name="V"/>
                      </sequence>
                    </complexType>
                  </element>
                </sequence>
              </complexType>
            </element>
          </sequence>
        </complexType>
        <element name="A" type="a:AuditType"/>
        <element name="AX" type="a:AuditExtType"/>
    </schema>'
    end;
    2) Table creation
    CREATE TABLE TST_AUDIT_TBL
       NOTE                  VARCHAR2(25 CHAR)     null,
       CHANGE_HISTORY        XMLTYPE               not null,
       CHANGE_HISTORY_EXT    XMLTYPE               null
    XMLTYPE COLUMN CHANGE_HISTORY STORE AS OBJECT RELATIONAL XMLSCHEMA "http://www.oracle.com/a.xsd" element "A"
    XMLTYPE COLUMN CHANGE_HISTORY_EXT STORE AS CLOB XMLSCHEMA "http://www.oracle.com/a.xsd" element "AX"
    3) Retrieving the nested table and column related to the target element :
    SQL> select dbms_xmlstorage_manage.xpath2TabColMapping(
      2           owner_name => 'DEV'
      3         , table_name => 'TST_AUDIT_TBL'
      4         , column_name => 'CHANGE_HISTORY'
      5         , xpath => '/A/T/TL/C/CN'
      6         , namespaces =>'default ''http://www.oracle.com/a.xsd'''
      7         )
      8  from dual;
    DBMS_XMLSTORAGE_MANAGE.XPATH2T
    <Result>
      <Mapping TableName="SYS_NTr0U7dPWyRu6OVvDN2f5HEg==" ColumnName="CN"/>
    </Result>
    4) Creating the index :
    SQL> create index CHANGE_HISTORY_IX1 on "SYS_NTr0U7dPWyRu6OVvDN2f5HEg==" ("CN");
    Index created
    If you're going to create multiple indexes like this, you could really benefit from renaming all the nested tables to meaningful names. That can be done via DBMS_XMLSTORAGE_MANAGE as well.

  • Please can anyone help with ajax memory tree

    I need to have the ajax memory tree expanded on page load. Can anyone please give me some ideas or piece of code. I have the tree working perfectly but only, the users have to click on the + sign to see the branches. This is from Scott Spendolini's example.
    Thanks in advance,
    Suma

    Hi Suma,
    I posted this on the other thread but if you haven't checked that, here is the code I use to simulate the first button click (in a PL/SQL region after the tree region)
    declare
    l_id number;
    begin
    select id into l_id from tree_view where pid is null;
    htp.p('<script language="Javascript">var table = document.getElementsByName("level_1");
    if (table.item(0).name = "level_1")
    getTreeNode(table.item(0),'||l_id||');
    </script>');
    end;
    Cheers,
    Paul

  • Please help with JTree Node Duplication

    Iam building a JTree which should not allow node duplication.
    1.)First i construct a ArrayList which stores all the previous nodes.
    treeNodeNames=new ArrayList();
    2.)i call the method
              readTreeNodeNames((DefaultMutableTreeNode)dtm.getRoot());
    3.)The method readTreeNodeNames is
    public void readTreeNodeNames(DefaultMutableTreeNode node) {
              if(node.toString().toLowerCase().length()!=0) {
              treeNodeNames.add(node.toString().toLowerCase());
              for(Enumeration en=node.children();en.hasMoreElements();) {
                   DefaultMutableTreeNode childNode=(DefaultMutableTreeNode)en.nextElement();      
                   if(childNode.toString().toLowerCase().length()!=0) {
                        treeNodeNames.add(childNode.toString().toLowerCase());
                   if(!childNode.isLeaf()) {
                        readTreeNodeNames(childNode);
    4.)i have four menu when right click a node add,modify,add subnode,delete.
    node duplication fails in my case.when should i call this method?should i call while doing every above mentioned operations or in TreeModelEvent implementations?
    i have mailed this problem already two times.but no one has not replied.Kinldy consider it and give me a solution.Or anyone having code for JTree Node duplication please send me to [email protected]

    Hi all,
    Any ideas to overcome this problem.?
    Thanks,
    Krish

  • Help with displaying a tree...

    Hello,
    I created a window program that displays some data in a tree structure. I have two versions of the program. One that works and one that doesn't. The one that does, builds the tree in the constructor method of my window class, creates a scrollPane for it, and adds the scrollPane to the window. Again, this version displays the tree fine.
    The second version, what I want to accomplish is load the tree when a button is pressed. When the button is pressed, I execute exactly the same steps that I do in the constructor but now these steps are in the actionPerformed method associated to the button. The thing is that the program does not display the tree. I have tried the repaint methods at the contentPane level, at the tree level, reloading the treeModel, but cannot get the tree to show. I would very appreciate any ideas on this...
    Thanks
    Antonio

    Hey...
    Thanks for the tip...that did the trick. What does the validate() method do exactly? The documentation doesn't say much....Thanks again...
    Antonio

  • Help on Deleting Node in Tree?

    I'm trying to delete a node on a tree and some weird stuff is
    occurring. Here is my code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    initialize="init();" layout="absolute">
    <mx:Script>
    <![CDATA[
    private function click () : void {
    if (MyTree.selectedItems.length > 0) {
    var items:Array = MyTree.selectedItems;
    for (var i:int = 0; i < items.length; i++) {
    var nodeToDelete:XML = XML(items
    var xlcParent:XMLListCollection = new
    XMLListCollection(nodeToDelete.parent().children());
    var iIndex:int = xlcParent.getItemIndex(nodeToDelete);
    xlcParent.removeItemAt(iIndex);
    ]]>
    </mx:Script>
    <mx:XMLListCollection id="MyDP">
    <mx:XMLList>
    <root label="Default Policy">
    <node label="node1"/>
    <node label="node2"/>
    <node label="node3"/>
    <node label="node4"/>
    <node label="node5">
    <node label="node1"/>
    <node label="node2"/>
    <node label="node3"/>
    <node label="node4"/>
    <node label="node5">
    <node label="node1"/>
    <node label="node2"/>
    <node label="node3"/>
    <node label="node4"/>
    </node>
    </node>
    </root>
    </mx:XMLList>
    </mx:XMLListCollection>
    <mx:Tree labelField="@label" id="MyTree"
    dataProvider="{MyDP}" x="141" y="109" width="528" height="440"/>
    <mx:Button click="click();" x="141" y="557" label="Delete
    Selected Node"/>
    </mx:Application>
    For some reason when I expand all the nodes and try to delete
    one of the great grand children all of the great grand children
    shift over as if they are siblings of the node that I deleted the
    great grand children from.
    Anyone have some good ideas? I sure wish deletion of nodes
    was as easy as in actionscript 2.0

    There a quite a few posts about this problem here already -
    it seems to be a tree rendering bug (seems to come in various
    different flavours).
    The safest work around after fiddling with the nodes in the
    tree is to get the axe out and reassign the data provider. To be
    nice to the user, you might want to keep the expansion state (this
    may not work if you made big "structural" changes to the tree).
    The following works for me (after your changed the tree data
    model):
    var openItems:Object = treeopenItems;
    tree.dataProvider = tree.dataProvider;
    this.openItems = openItems;
    Hope this helps.
    Robert.

  • CheckBox node tree with two diferent kind of nodes

    Hai ,
    I need to build a check box tree with two different kind of nodes , Child and Parent nodes .
    CheckBox node tree with two diferent kind of nodes.
    HOw will i write the renderer and editor for this ?

    Study the method getTreeCellRendererComponent() of the class DefaultTreeCellRenderer.

  • Help with final Graduation Project

    I've done with the majority of it, however I need help with the remove method for a B tree. when removing from a non-leaf node, your remove must replace the removed item with the smallest item in the right subtree.
    The code:
    import java.util.Stack;
    public class BTreeG<E extends Comparable< ? super E>> {
        // Each Btree object is a B-tree header.
        // This B-tree is represented as follows: order is the maximum number
        // of children per node, and root is a link to its root node.
        // Each B-tree node is represented as follows: size contains its size; a
        // subarray items[0...size-1] contains its elements; and a subarray
        // childs[0...size] contains links to its child nodes. For each element
        // items, childs[i] is a link to its left child, and childs[i+1] is a
    // link to its right child. In a leaf node, all child links are null.
    // Moreover, for every element x in the left subtree of element y:
    // x.compareTo(y) < 0
    // and for every element z in the right subtree of element y:
    // z.compareTo(y) > 0.
    private final int order;
    private Node root;
    public BTreeG () {
         // Construct an empty B-tree of order 5.
    this(5);
    public BTreeG (int k) {
    // Construct an empty B-tree of order k.
    root = null;
    order = k;
    public E get(E item){
    if (root == null)
    return null;
    Node node = root;
    while (true) {
    int pos = node.searchInNode(item);
    if (item.equals(node.items[pos]))
    return (E)node.items[pos];
    else if (node.isLeaf())
    return null;
    else
    node = node.childs[pos];
    public void insert (E item) {
    // Insert element item into this B-tree.
    if (root == null) {
    root = new Node( item);
    return;
    Stack ancestors = new Stack();
    Node curr = root;
    while (true) {
    int currPos = curr.searchInNode(item);
    if (item.equals(curr.items[currPos]))
    return;
    else if (curr.isLeaf()) {
    curr.insertInNode(item, null, null, currPos);
    if (curr.size == order) // curr has overflowed
    splitNode(curr, ancestors);
    return;
    } else {
    ancestors.push(new Integer(currPos));
    ancestors.push(curr);
    curr = curr.childs[currPos];
    private void splitNode (Node node,
    Stack ancestors) {
    // Split the overflowed node in this B-tree. The stack ancestors contains
    // all ancestors of node, together with the known insertion position
    // in each of these ancestors.
    int medPos = node.size/2;
    E med = (E)node.items[medPos];
    Node leftSib = new Node(
    node.items, node.childs, 0, medPos);
    Node rightSib = new Node(
    node.items, node.childs, medPos+1, node.size);
    if (node == root)
    root = new Node( med, leftSib,
    rightSib);
    else {
    Node parent =
    (Node) ancestors.pop();
    int parentIns = ((Integer)
    ancestors.pop()).intValue();
    parent.insertInNode(med, leftSib, rightSib,
    parentIns);
    if (parent.size == order) // parent has overflowed
    splitNode(parent, ancestors);
    public void remove (E item) {
         // your code goes here
    public void print () {
    // Print a textual representation of this B-tree.
    printSubtree(root, "");
    private void printSubtree (Node top, String indent) {
    // Print a textual representation of the subtree of this B-tree whose
    // topmost node is top, indented by the string of spaces indent.
    if (top == null)
    System.out.println(indent + "o");
    else {
    System.out.println(indent + "o-->");
    boolean isLeaf = top.isLeaf();
    String childIndent = indent + " ";
    for (int i = 0; i < top.size; i++) {
    if (! isLeaf) printSubtree(top.childs[i], childIndent);
    System.out.println(childIndent + top.items[i]);
    if (! isLeaf) printSubtree(top.childs[top.size], childIndent);
    //////////// Inner class ////////////
    private class Node<E extends Comparable< ? super E>>
    // Each Node object is a B-tree node.
    private int size;
    private E[] items;
    private Node[] childs;
         private Node (E item) {
         this (item, null, null);
    private Node (E item, Node left, Node right) {
    // Construct a B-tree node of order k, initially with one element, item,
    // and two children, left and right.
    items = (E[])new Comparable[order];
    childs = new Node[order+1];
    // ... Each array has one extra component, to allow for possible
    // overflow.
    this.size = 1;
    this.items[0] = item;
    this.childs[0] = left;
    this.childs[1] = right;
    private Node ( E[] items, Node[] childs, int l, int r) {
    // Construct a B-tree node of order k, with its elements taken from the
    // subarray items[l...r-1] and its children from the subarray
    // childs[l...r].
    this.items = (E[])new Comparable[order];
    this.childs = new Node[order+1];
    this.size = 0;
    for (int j = l; j < r; j++) {
    this.items[this.size] = items[j];
    this.childs[this.size] = childs[j];
    this.size++;
    this.childs[this.size] = childs[r];
    private boolean isLeaf () {
    // Return true if and only if this node is a leaf.
    return (childs[0] == null);
    private int searchInNode (E item) {
    // Return the index of the leftmost element in this node that is
    // not less than item.
    int l = 0, r = size-1;
    while (l <= r) {
    int m = (l + r)/2;
    int comp = item.compareTo((E)items[m]);
    if (comp == 0)
    return m;
    else if (comp < 0)
    r = m - 1;
    else
    l = m + 1;
    return l;
    private void insertInNode (E item, Node leftChild,
    Node<E> rightChild, int ins) {
    // Insert element item, with children leftChild and rightChild, at
    // position ins in this node.
    for (int i = size; i > ins; i--) {
    items[i] = items[i-1];
    childs[i+1] = childs[i];
    size++;
    items[ins] = item;
    childs[ins] = leftChild;
    childs[ins+1] = rightChild;

    I've done with the majority of it, however I need
    help with the remove method for a B tree. when
    removing from a non-leaf node, your remove must
    replace the removed item with the smallest item in
    the right subtree. It's hard to implement a B tree. That's why you rather use a standard implementation. If not you're basically on your own. Don't expect others to do it for you. Why should they bother? Please tell us when you're finished and where we can download you B-tree implementation -:)

  • Help with httpService returnFormat "object"

    Problem:
    My flex httpservice returns an xml file in the "object"
    resultFormat.
    How could I get the count of all childNodes of an object in
    that returned object tree.
    For example, in the xml file below:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <reporting>
    <series>
    <title>Edge Page Views, in Page Views per
    Second</title>
    <xLabel>startdatetime</xLabel>
    <y1Label>sum(pageviews)</y1Label>
    <data>
    <x>1216233600</x>
    <y1>79.605</y1>
    </data>
    <data>
    <x>1216233900</x>
    <y1>78.076</y1>
    </data>
    </series>
    <series>
    <title>Total Bandwidth, in Mbits per
    Second</title>
    <xLabel>startdatetime</xLabel>
    <y1Label>sum(egress_bytes_mbps)</y1Label>
    <y2Label>combined_midgress_bytes_mbps</y2Label>
    <y3Label>ovh_bytes_mbps</y3Label>
    <y4Label>sum(ingress_bytes_mbps)</y4Label>
    <data>
    <x>1216233600</x>
    <y1>36.160352</y1>
    <y2>66.48362700000001</y2>
    <y3>66.48362700000001</y3>
    <y4>96.01235200000002</y4>
    </data>
    <data>
    <x>1216233900</x>
    <y1>34.260794</y1>
    <y2>62.10649799999999</y2>
    <y3>62.10649799999999</y3>
    <y4>88.902323</y4>
    </data>
    <data>
    <x>1216234200</x>
    <y1>35.329617</y1>
    <y2>62.77339099999999</y2>
    <y3>62.77339099999999</y3>
    <y4>89.30751</y4>
    </data>
    </series>
    </reporting>
    The first series element has 4 children
    I am able to get the number of data elements as:
    "resultObj.reporting.series[0].data.length"
    How do I effectively retreive:
    "resultObj.reporting.series[0].childNodes().length"
    Apparently this does'nt work, I also tried Nodes, children().
    Any documentation or help with this would be awesome
    Thanks a ton
    Pranay

    Can someone please help me understand this error maybe?
    I would appreciate it
    [MessagingError message='Destination 'the destination of an
    xml file' either does not exist or the destination has no channels
    defined (and the application does not define any default
    channels.)']
    what are channels?

  • Help in dynamically changing tree

    Plz help me in fluctuating tree at runtime.
    and i also want to popup a menu when a node is right cliked.
    Thanks.

    1)fluctuating tree...what???
    2) Create a JPopUpMenu or a subclass. Add a mouselistener to the JTree.
    In this listener you handle rightMouseClick.
    When you detect such an mouse action open the popup with popup.show()
    If you need the selected component call JTree.getLastSelectedPathComponent().
    If you want to check if it is null use this: JTree.getSelectionModel().isSelectionEmpty(). So you can prevent nullpointers, cause selection can be empty
    You can write a method for your popup to give it the selected component.
    Then call the .show().
    Tweety

  • Help with ynamic variable evaluation

    Hi guys,
    If someone can point me out to how to evaluate variables as
    part of an expression.
    for ex:
    event.result.reporting.series[0].eval("y"+j+"Label");
    basically how do i write the equivalent of eval in
    flex/actionscript
    Thanks a ton,
    Pranay

    Thanks Greg, saved my day................
    1 more question
    Problem:
    My flex httpservice returns an xml file in the "object"
    resultFormat.
    How could I get the count of all childNodes of an object in
    that returned object tree.
    For example, in the xml file below:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <reporting>
    <series>
    <title>Edge Page Views, in Page Views per
    Second</title>
    <xLabel>startdatetime</xLabel>
    <y1Label>sum(pageviews)</y1Label>
    <data>
    <x>1216233600</x>
    <y1>79.605</y1>
    </data>
    <data>
    <x>1216233900</x>
    <y1>78.076</y1>
    </data>
    </series>
    <series>
    <title>Total Bandwidth, in Mbits per
    Second</title>
    <xLabel>startdatetime</xLabel>
    <y1Label>sum(egress_bytes_mbps)</y1Label>
    <y2Label>combined_midgress_bytes_mbps</y2Label>
    <y3Label>ovh_bytes_mbps</y3Label>
    <y4Label>sum(ingress_bytes_mbps)</y4Label>
    <data>
    <x>1216233600</x>
    <y1>36.160352</y1>
    <y2>66.48362700000001</y2>
    <y3>66.48362700000001</y3>
    <y4>96.01235200000002</y4>
    </data>
    <data>
    <x>1216233900</x>
    <y1>34.260794</y1>
    <y2>62.10649799999999</y2>
    <y3>62.10649799999999</y3>
    <y4>88.902323</y4>
    </data>
    <data>
    <x>1216234200</x>
    <y1>35.329617</y1>
    <y2>62.77339099999999</y2>
    <y3>62.77339099999999</y3>
    <y4>89.30751</y4>
    </data>
    </series>
    </reporting>
    The first series element has 4 children
    I am able to get the number of data elements as:
    "resultObj.reporting.series[0].data.length"
    How do I effectively retreive:
    "resultObj.reporting.series[0].childNodes().length"
    Apparently this does'nt work, I also tried Nodes, children().
    Any documentation or help with this would be awesome
    Thanks a ton
    Pranay

Maybe you are looking for

  • Are my random shutdowns a sign of a bad battery?

    I moved to Brazil a few months back and found that my early model MBA´s battery went flat, though upon checking further, it seems it has run its course in terms of cycles. Now I must have it plugged in to work. The only problem is after a few weeks o

  • How to create a trend line in cfchart?

    I  can create a scatter chart in cfchart - but I do not know how to create  a linear regression trend line in the same chart as a second data  series. Kodemonki provided an answer in a forum discussion a few years  ago (http://forums.adobe.com/messag

  • Problems in mapping a result set into IN operator

    i can't for the life of me figure out how to create the following predicate in a mapping: WHERE table1.cola NOT IN (SELECT table2.cola FROM table2);

  • Could not display output in PDF format from a RDF file

    Hi all, I'm calling a report file (.RDF) from the browser using RWCGI.EXE, and specified the output in PDF format, but it always asking me to download the active-X for the PDF file generated by the report. I have Adobe Acrobat Reader installed on my

  • 8mm cine film 4:3 or widescreen?

    Had some standard 8mm cine film transferred to .avi files in HD 1920 x 1080 (eg: 30 minute reel = approx 13gb). Importing into iMove involved 'optimising' (did that change the resolution?). If I create the project in widescreen I can share to media b