Ask AI on The Internet
//*********************************************************** // G_node.java // // Sergey Brenov // April 15, 2009 // © Serg V. Zhdanovskih 2009 //*********************************************************** public class G_node { public int Index; public int Deg; public G_node[] Neighbours; public G_node(int ind) { Index = ind; Deg = 0; Neighbours = null; } public final void addNeighbour(G_node nd) { G_node[] nb = new G_node[Deg + 1]; if (Deg > 0) { System.arraycopy(Neighbours, 0, nb, 0, Deg); } nb[Deg] = nd; Neighbours = nb; Deg++; } public final void removeNeighbour(G_node nd) { if (Deg > 0) { int dex = -1; for (int i = 0; i < Deg; i++) { if (Neighbours[i] == nd) { dex = i; break; } } if (dex != -1) { G_node[] nb = new G_node[Deg - 1]; if (Deg > 1) { if (dex > 0) { System.arraycopy(Neighbours, 0, nb, 0, dex); } if (dex < Deg - 1) { System.arraycopy(Neighbours, dex + 1, nb, dex, Deg - dex - 1); } } Neighbours = nb; Deg--; } } } }
Hello! How can I help you today? If you have any questions or need advice, feel free to ask, and I'll do my best to assist you.
A new large language model has been made available since this question was asked.
To generate an updated answer from the new model, click the button below.
Think your answer is better than the AI's? Post it below.
Question Tags
If you want your question answered by an AI, click here.
Post your own comment: