Untitled
unknown
plain_text
4 years ago
1.1 kB
5
Indexable
public void BreadthFirstTraverse(T startID, ref List<T> visited) { LinkedList<T> adj; Queue<T> toVisit = new Queue<T>(); GraphNode<T> current = new GraphNode<T>(startID); toVisit.Enqueue(startID); //puts the first node into ToVisit while (toVisit.Count != 0) //when toVist is not 0 perform the while loop - stoppping condition { startID = toVisit.Dequeue(); current = GetNodeByID(startID); visited.Add(current.ID); //once we are at a node it puts it into visited so we dont output it again foreach (GraphNode<T> n in nodes) { if (!visited.Contains(n.ID) && !toVisit.Contains(n.ID)) { toVisit.Enqueue(n.ID); } } } } private void button4_Click(object sender, EventArgs e) { mygraph.BreadthFirstTraverse(textBox4.Text); }
Editor is loading...