c# - Problem with Queue -


I am trying to create a program using the BFS algorithm so that I put each node in one line and once Q at every level I'm starting to compare it with other nodes to see if they are equal or not, but the problem is that the elements in my line are being modified, when I do Diku I never got any answers and I Stack overflow is happening.

I'm not sure which part of my code had a problem, because I have stack overflow all over the place, but I'm queuing and decuting

Yes, basically the other After the loop, it all messes up, it connects more than 1 "B" to my matrix and it modifies my line elements.

  Private Zero BFS (nodo & lectum; string [,]> node) {Array.Copy (nodo .get ea), ditos 5, 9); Temp = null; Temp2 = Faucet; Temp = null; Temp4 = Faucet; Array.Copy (Ditos 5, Ditos, 9); // If and if someone else does this, then I just post one (Ditos [1, 0]. Excel ("B")) {Array.Copy (Datasus, Ditos 2, 9); Array.Copy (Datasus, Ditos 3, 9); Cont3 = 3; // 1.0 to 0,0 data from UP [1, 0] = data [0, 0]; Datos [0, 0] = "b"; Temp = new node & lt; String [,] & gt; (Datos); Temp.setCamino ("U"); Temp.setPadre (Nodo); Myq.Enqueue (temporary); Temp = null; // properly 1,0 a 1,1 datos2 [1, 0] = datos2 [1, 1]; Datos2 [1, 1] = "b"; Temp2 = new node & lt; String [,] & gt; (Datos2); Temp2.setCamino ("R"); Temp2.setPadre (Nodo); Myq.Enqueue (temp2); Temp = null; // 1.0 from a 2.0 ditos 3 [1, 0] = ditos 3 [2, 0]; Datos3 [2, 0] = "b"; Temp = new node & lt; String [,] & gt; (Datos3); Temp3.setCamino ('D'); Temp3.setPadre (Nodo); Myq.Enqueue (temp3); Fila (); }  

}

  Private zeros file () {node> String [,] & gt; Temp5; For (int i = 0; i  string [,]> gt; myq.Dequeue (); If ((! Flag2) {boxResultado.AppendText ("problem solved"); Flag2 = true; breakdown;} and {brake;}} Else {if flag!} {BFS (temp5) );} And {brake;}}}} private bull ozetivio (nodo and left; string [,]> gt; p, node> string [,]> gt; n) node 1 = null; node 2 = Null; bug flag; false; nodo1 = p.getEA (); nodo2 = e.getEA (); {for (ii, f)} {if (nodo1 [i, f]! = Nodo2 [i, f]) { Flag = (i, f;)} {for (int i = 0; i & lt; 3; i ++) {for (int f = 0; f <3; f ++) true; }}} If (flag) {return false; } And {return true; }}  

I know my code is terrible but I am trying to understand that problem for the last 5 hours or more so I am amending it here and I am trying to find out the problem, but I am very disappointed so I decided to ask for help here.

First of all, you do not have Specify what the node class does, however, BFS is very easy. Ill tell you the general algorithm. Suppose you have an NXN analysis matrix in the graph, then you will have node size N array. The initial code will

  class graph {// matrix [i, j] is true if there is a node i bool [,] matrix; Private Zero BFS (int startNode) {int n = matrix.GetLength (0); Bull [] mark = new bull [N]; From queue & lt; Integer & gt; Node = new line (); Nodes.Enqueue (startNode); While (! Nodes.free ()) {int node = nodes.Dequeue (); // Set the set mark [node] = true; & Lt; Integer & gt; Adjs = GetAdyacents (node); Forchha (adjacent in the xc) (if (! Symbol (adjacent) nodes. Enque (adjacent);} console. Light line ("visiting {0}", node);}}}  

GetAdjacent () method depends on whether you are using representation with matrix or incompatibility list. It is also easy, if you want to know how to do them, then give me a message.

< P> I have not tested the code, but I'm sure it works (any text Sorry for any issues of trust!)

hope that I can give good luck! DVD


Comments