static void Main(string[] args) { Graphs graph = new Graphs(); Node testV1 = new Node("Test1"); Node testV2 = new Node("Test2"); graph.AddNode(testV1); graph.AddNode(testV2); graph.AddEdge(testV1, testV2, 4); List <Node> ordered = graph.BreadFirst(testV1); foreach (Node item in ordered) { Console.Write($"{item.Value} => "); } DGraph dictGraph = new DGraph(); NodeD node1 = new NodeD("Sea"); NodeD node2 = new NodeD("Chi"); dictGraph.AddNode(node1); dictGraph.AddNode(node2); dictGraph.AddEdge(node1, node2, 150); List <DEdge> edges = dictGraph.GetNeighbors(node1); foreach (DEdge item in edges) { Console.Write($"{item} => "); } Console.ReadLine(); }
void Obr() { if (AddNodeBtn.Checked) { PictureBox pictureBox = graph1PB; Graphs gr = graph1; MouseEventArgs mouseEventArgs = FirstClick1; gr.AddNode(mouseEventArgs.X, mouseEventArgs.Y); gr.Draw(pictureBox.CreateGraphics(), selectionNode); } else if (DeleteNodeBtn.Checked) { Graphs gr = graph1; PictureBox pictureBox = graph1PB; MouseEventArgs mouseEventArgs = FirstClick1; Node nodeGrathic = gr.FindNode(mouseEventArgs.Location); if (nodeGrathic != null) { gr.Delete(nodeGrathic); } gr.Draw(pictureBox.CreateGraphics(), selectionNode); } else if (GetEdgeBtn.Checked) { Graphs gr = graph1; PictureBox pictureBox = graph1PB; MouseEventArgs mouseEventArgs1 = FirstClick1; MouseEventArgs mouseEventArgs2 = SecondClick1; Node nodeGrathic1 = gr.FindNode(mouseEventArgs1.Location); Node nodeGrathic2 = gr.FindNode(mouseEventArgs2.Location); if (nodeGrathic1 != null && nodeGrathic2 != null && nodeGrathic1 != nodeGrathic2) { gr.AddEdge(nodeGrathic1, nodeGrathic2); } gr.Draw(pictureBox.CreateGraphics(), selectionNode); } else if (SelectionNodeBtn.Checked) { Node node = graph1.FindNode(FirstClick1.Location); if (node != null) { if (selectionNode.IndexOf(node) != -1) { selectionNode.Remove(node); } else { selectionNode.Add(node); } } graph1.Draw(graph1PB.CreateGraphics(), selectionNode); } }
public static void GraphBuilder() { Node nodeOne = new Node("nodeOne"); Node nodeTwo = new Node("nodeTwo"); Node nodeThree = new Node("nodeThree"); Node nodeFour = new Node("nodeFour"); Node nodeFive = new Node("nodeFive"); Graphs myGraph = new Graphs(nodeOne); myGraph.AddEdge(nodeOne, new Tuple <Node, int>(nodeTwo, 5)); myGraph.AddEdge(nodeTwo, new Tuple <Node, int>(nodeThree, 10)); myGraph.AddEdge(nodeThree, new Tuple <Node, int>(nodeFour, 15)); myGraph.AddEdge(nodeFour, new Tuple <Node, int>(nodeFive, 20)); myGraph.AddEdge(nodeFive, new Tuple <Node, int>(nodeOne, 25)); myGraph.AddEdge(nodeTwo, new Tuple <Node, int>(nodeFour, 17)); Console.WriteLine($"Graph size: {myGraph.Size()}"); Console.WriteLine("Graph nodes:"); foreach (var item in myGraph.GetNodes()) { Console.WriteLine(item.Value); } Console.WriteLine("Graph neighbors for nodeOne:"); foreach (var item in myGraph.GetNeighbors(nodeOne)) { Console.WriteLine(item.Value); } Console.WriteLine("Graph neighbors for nodeTwo:"); foreach (var item in myGraph.GetNeighbors(nodeTwo)) { Console.WriteLine(item.Value); } Console.WriteLine("Graph neighbors for nodeThree:"); foreach (var item in myGraph.GetNeighbors(nodeThree)) { Console.WriteLine(item.Value); } Console.WriteLine("Graph neighbors for nodeFour:"); foreach (var item in myGraph.GetNeighbors(nodeFour)) { Console.WriteLine(item.Value); } Console.WriteLine("Graph neighbors for nodeFive:"); foreach (var item in myGraph.GetNeighbors(nodeFive)) { Console.WriteLine(item.Value); } }