I have a program that you have attached and remove nodes from a graph, then make BFS and DFS run traversals I'm trying to
So I basically read Add and
connect nodes on runtime ... Then I want to hit users with a
add parent to the parent button which will allow a child to Appropriately connects
AddButton.addActionListener (New ActionListener) {Public Zero actionPerformed (ActionEvent E) {nodes nx = new nodes ("x", nodeX, nodeY, nodeWidth, nodeHeight); appendNode (rootNode, Nx);}}); } When I try to attach a new node, write it over the current proximity matrix and replace it with a single new node x Sounds as A .
I think I I know that is doing that ... because my appendNode () function tries to update proximity matrix by making a new one with the old overwritten and new nodeList size: Add new node X to the public zero attachment (nodes guardian, node child) {// node list add-node (child); // Loop to connect again via all the nodes, plus a new ... then create new adjmatrix system.out.println (nodeList.size ()); Size = node list. (Size); Adjmatrix = null; Adjmatrix = new int [size] [size]; Int fromNode = nodeList.indexOf (original); Int toNode = nodlist.indexoff (hair); Adjmatrix [node] [toNode] = 1; Adjmatrix [toNode] [node] = 0; } Public Zero addNode (nodes n) {nodeList.add (n);
But what do I want to achieve without overwriting it? / P> >
FYI, here is the connecting node method:
if the public is zero connectNode (from nodes, nodes) {// matrix is empty. (AdjMatrix = = null) {// Set matrix [row] [color] Size list size for size of node size = nodelist. Size (); // Set Matrix set dimension ... (6x6 nodes list) adjmatrix = new int [size] [size]; } Int fromNode = nodeList.indexOf (to); Int toNode = nodeList.indexOf (to); // Connect node A to B and B to A, set that I, j position = 1 adjmatrix [fromNode] [toNode] = 1; Adjmatrix [toNode] [node] = 0; } Edit: Add / add x node list adnode (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); Adjmatrixcopy [node] [toNode] = 1; Adjmatrixcopy [toNode] [fromNode] = 0; // 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]; }} // now need to add new addition node / adjmatrix = null; }
by eliminating the adjacency matrix and changing it with a new one with the updated size All cells will be zero (from, from) and (from, to), you need to create a new adjacent matrix with the new size, copy the data from the old, and then only overwrite the old.
No comments:
Post a Comment