static void Main(string[] args) { Node <Student> root = null; BinaryTree tree = new BinaryTree(); Subscriber subscriber = new Subscriber(); tree.promoterAdded += subscriber.SpeakerAddition; tree.promoterDelete += subscriber.SpeakerRemoval; Student[] students = new Student[] { new Student { Name = "Tolik", TestResult = 150, TestTitle = "Science", Data = new DateTime(2018, 10, 15) }, new Student { Name = "Andrey", TestResult = 160, TestTitle = "Tech science", Data = new DateTime(2018, 9, 4) }, new Student { Name = "Slava", TestResult = 195, TestTitle = "Electronic", Data = new DateTime(2018, 10, 3) } }; root = tree.AddItems(root, students); //use Sort array whith help implement IComparable<T> tree.DisplaySortedStudents(); //we can use "foreach" loop foreach (Node <Student> item in tree) { Console.WriteLine("name: {0}", item.Student.Name); } DFS dfs = new DFS(); dfs.DepthFirstSearch(root); BFS bfs = new BFS(); bfs.AcrossFirstSearch(root); tree.RemoveTree(ref root); //Task_2 //NamedIterator int[] testArray = new int[] { 1, 2, 3, 4, 5, 6 }; ArrayWithAnyRangeIndex <int> MyArray = new ArrayWithAnyRangeIndex <int>(testArray); foreach (var item in MyArray.GetArrayBySetRange(2, 4)) { Console.WriteLine(item + " "); } Console.ReadKey(); }
private static void RunDFS() { Graph <char> myGraph = new Graph <char>(); GraphNode <char> nodeA = new GraphNode <char>('A'); GraphNode <char> nodeB = new GraphNode <char>('B'); GraphNode <char> nodeC = new GraphNode <char>('C'); GraphNode <char> nodeD = new GraphNode <char>('D'); GraphNode <char> nodeE = new GraphNode <char>('E'); GraphNode <char> nodeF = new GraphNode <char>('F'); GraphNode <char> nodeG = new GraphNode <char>('G'); GraphNode <char> nodeP = new GraphNode <char>('P'); GraphNode <char> nodeQ = new GraphNode <char>('Q'); myGraph.AddVertex(nodeA); myGraph.AddVertex(nodeB); myGraph.AddVertex(nodeC); myGraph.AddVertex(nodeP); myGraph.AddVertex(nodeQ); myGraph.AddVertex(nodeD); myGraph.AddVertex(nodeE); myGraph.AddVertex(nodeF); myGraph.AddVertex(nodeG); myGraph.AddEdge(nodeA, nodeG, 1, true); myGraph.AddEdge(nodeA, nodeD, 2, true); myGraph.AddEdge(nodeA, nodeC, 3, true); myGraph.AddEdge(nodeG, nodeF, 4, true); myGraph.AddEdge(nodeC, nodeE, 1, true); myGraph.AddEdge(nodeC, nodeD, 2, true); myGraph.AddEdge(nodeD, nodeB, 3, true); myGraph.AddEdge(nodeE, nodeB, 4, true); myGraph.AddEdge(nodeP, nodeQ, 1, true); DFS <char> .DepthFirstSearch(myGraph.VertexList); }