Пример #1
0
        static void Main(string[] args)
        {
            graph a = new graph();

            // Untuk Read File
            string[] lines = System.IO.File.ReadAllLines(@"C:\Users\Jeremy\Documents\Backup Jeremy 5 Sep 20\Kuliah\Semester 4\Strategi Algoritma\Tubes2\Tubes2STIMA\src\tes.txt");
            foreach (string line in lines)
            {
                string[] y = line.Split(" ");
                if (!a.contain(y[0]))
                {
                    node temp = new node(y[0]);
                    a.addNode(temp);
                    if (!a.contain(y[1]))
                    {
                        node temp1 = new node(y[1]);
                        a.addNode(temp1);
                        temp.addAdj(temp1);
                    }
                    else
                    {
                        foreach (node i in a.nodes)
                        {
                            if (i.vertex == y[1])
                            {
                                temp.addAdj(i);
                            }
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < a.nodes.Count; i++)
                    {
                        if (a.nodes[i].vertex == y[0])
                        {
                            if (!a.contain(y[1]))
                            {
                                node temp1 = new node(y[1]);
                                a.addNode(temp1);
                                a.nodes[i].addAdj(temp1);
                            }
                            else
                            {
                                foreach (node j in a.nodes)
                                {
                                    if (j.vertex == y[1])
                                    {
                                        a.nodes[i].addAdj(j);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // a.AllInfo();
            // Console.Write("This is the nodes in graph.\n");

            // a.AllVertex();
            // string vawal = "G";
            // string vtujuan = "H";
            // graph x = a.bfs(vawal,vtujuan);
            // Console.Write("This is the BFS from {0} to {1}\n" ,vawal,vtujuan);
            // x.AllVertex();

            // int dist = 3;
            // Console.Write("This is the BFS from {0} to {1} node away from it\n",vawal,dist);
            // graph b = a.bfs("G", dist);
            // b.AllVertex();

            // graph empty = new graph();
            // graph w = a;
            // w.friendRecommendation("G","BFS");
            // w.friendExplore("A","G","BFS");
            a.nodes.Sort((x, y) => x.vertex.CompareTo(y.vertex));
            foreach (node i in a.nodes)
            {
                i.adjacent.Sort((x, y) => x.vertex.CompareTo(y.vertex));
            }
            a.AllVertexWithArrow();
            graph g = a.dfs("A", "G");

            g.AllVertexWithArrow();

            //graph g = a.dfs("A","G");
            //udah ke sort semua, jadi ngga bingung tentang alphabetical order dalam search
        }