示例#1
0
        static void LinkedList()
        {
            System.Console.WriteLine("\n=====   MyLinkedList   =====\n");

            IMyLinkedList <string> lst = DSBuilder.CreateMyLinkedList();

            lst.AddFirst("1");
            lst.AddFirst("2");
            lst.AddFirst("3");
            lst.Insert(0, "0");

            Console.WriteLine(lst.ToString());

            MyLinkedList <string> ll = new MyLinkedList <string>();

            System.Console.WriteLine(ll);
            ll.AddFirst("a");
            ll.AddFirst("b");
            ll.AddFirst("c");
            ll.Insert(2, "x");
            System.Console.WriteLine(ll);
            try
            {
                ll.Insert(4, "kan niet");
            }
            catch (MyLinkedListIndexOutOfRangeException e)
            {
                System.Console.WriteLine(e.Message);
            }

            ll.Clear();
            ll.AddFirst("a");
            ll.AddFirst("b");
            System.Console.WriteLine(ll.GetFirst());
            ll.RemoveFirst();
            System.Console.WriteLine(ll);
            ll.RemoveFirst();
            System.Console.WriteLine(ll);
        }
示例#2
0
        public static void Graph()
        {
            System.Console.WriteLine("\n=====   Graph   =====\n");

            // Figuur 14.1 uit boek.
            Graph graph = DSBuilder.CreateGraph14_1();

            graph.Unweighted("V0");

            System.Console.WriteLine($"Unweighted\n{graph}\n");

            graph.Dijkstra("V0");

            System.Console.WriteLine($"Dijkstra\n{graph}\n");
            Console.WriteLine($"IsConnected: {graph.IsConnected()}");

            IGraph connectedGraph = DSBuilder.ConnectedGraph();

            connectedGraph.Dijkstra("V0");

            System.Console.WriteLine($"\nDijkstra\n{connectedGraph}\n");
            Console.WriteLine($"IsConnected: {connectedGraph.IsConnected()}");
        }