Thursday 15 May 2014

java - Tree Traversal - Append node to adjacency matrix after runtime -


I am creating a tree's translucent program that allows users to run BFS and DFS traversal, as well as Adds and removes nodes.

I am adding nodes due to problems that expand the attack matrix. For this example, I add a new child node X for parent h :

 Enter the image details here

For now, I hardly coded node X Custom input will be allowed for this later

User click Add node button:

  / Create a node through button and Creating and Connecting AddButton.addActionListener (New Executioner ( } {Public Zero Workflow (Action EVE) {nodes nx = new nodes ("x", nodex, node, node width, node high); edenode (rottenod, nx);}});   

which says addendNode (): This function is creating a new impetus matrix with updated sizes (extra node X ) ... copy old Data from the matrix adjmatrix , then adding an additional slot to the new node X

  public zero attachments (nodes guardian, nodes child) { // Add new node X to node list add-node (child); // Loop to connect again through all the nodes, plus a new ... then create new adjmatrix int newsize = nodeList.size (); // Create a new Ady matrix of new shape ... int [] [] adjmatrixcopy = new int [newSize] [newSize]; Int fromNode = nodeList.indexOf (original); Int toNode = nodlist.indexoff (hair); // Copy the new matrix for adjmatrix data ... (int i = 0; i & lt; adjmatrix.length; i ++) {for (int j = 0; j & lt; adjmatrix [i] length ; J ++) {adjmatrixcopy [i] [j] = xmatics [i] [j]; }} For (int col = 0; col & lt; newSize; col ++) {adjmatrixCopy [newSize] [col] = 1; } // now need to add the newly added node / / adjmatrixcopy [fromNode] [toNode] = 1; // adjmatrixcopy [toNode] [fromNode] = 0; // adjmatrix = null; }   

When I click on addendNode , it throws an error:

  exception in thread "AWT-EventQueue -0 "java .lang.ArrayIndexOutOfBoundsException: Article 12 in Graph.appendNode (Graph.java:306) at $ 3.actionPerformed (Graph.java:141)    

< Div class = "post -text" itemprop = "text">

  adjmatrixCopy [newSize] [col] = 1;   

This is probably wrong you want

  adjmatrixcopy [newSize - 1] [cola] = 1;   

Instead?

No comments:

Post a Comment