public void friendExplore(string namaNodeAwal, string namaNodeTujuan, string method) { graph ExploreResult = new graph(); if (method == "BFS") { graph dummy = this.bfs(namaNodeAwal, namaNodeTujuan, ExploreResult); } else if (method == "DFS") { ExploreResult = this.dfs(namaNodeAwal, namaNodeTujuan); } Console.WriteLine("Nama akun: {0} dan {1}", namaNodeAwal, namaNodeTujuan); if (ExploreResult.nodes.Count <= 2) { Console.WriteLine("Tidak ada jalur koneksi yang tersedia"); Console.WriteLine("Anda harus memulai koneksi baru itu sendiri."); } else { Console.Write("{0}", ExploreResult.nodes.Count - 2); if (ExploreResult.nodes.Count - 2 == 1) { Console.Write("st"); } else if (ExploreResult.nodes.Count - 2 == 2) { Console.Write("nd"); } else if (ExploreResult.nodes.Count - 2 == 3) { Console.Write("rd"); } else { Console.Write("th"); } Console.Write("-degree connection\n"); ExploreResult.AllVertexWithArrow(); } }
public void friendExplore(string namaNodeAwal, string namaNodeTujuan, string method, RichTextBox rtb) { graph ExploreResult = new graph(); if (method == "BFS") { graph dummy = this.bfs(namaNodeAwal, namaNodeTujuan, ExploreResult); } else if (method == "DFS") { ExploreResult = this.dfs(namaNodeAwal, namaNodeTujuan); } rtb.AppendText("Nama akun: " + namaNodeAwal + " dan " + namaNodeTujuan + "\n"); if (!ExploreResult.contain(namaNodeTujuan)) { rtb.AppendText("Tidak ada jalur koneksi yang tersedia\n"); rtb.AppendText("Anda harus memulai koneksi baru itu sendiri.\n"); } else { rtb.AppendText((ExploreResult.nodes.Count - 2).ToString()); if (ExploreResult.nodes.Count - 2 == 1) { rtb.AppendText("st"); } else if (ExploreResult.nodes.Count - 2 == 2) { rtb.AppendText("nd"); } else if (ExploreResult.nodes.Count - 2 == 3) { rtb.AppendText("rd"); } else { rtb.AppendText("th"); } rtb.AppendText("-degree connection\n"); ExploreResult.AllVertexWithArrow(rtb); } }
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 }