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 For now, I hardly coded node User click which says addendNode (): This function is creating a new impetus matrix with updated sizes (extra node When I click on < Div class = "post -text" itemprop = "text"> This is probably wrong you want Instead? X for parent
h :
X Custom input will be allowed for this later
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);}});
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; }
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)
adjmatrixCopy [newSize] [col] = 1;
adjmatrixcopy [newSize - 1] [cola] = 1;
No comments:
Post a Comment