private void dfs_btn(object sender, RoutedEventArgs e) { Parser p = new Parser(); List <List <string> > graphdetails = p.Parse(this.FileField.Text); if (graphdetails != null) { graphdetails = graphdetails.OrderBy(x => x[0]).ToList(); DFSSorter DFSResult = new DFSSorter(); DFSSorter.init_topoSort(graphdetails); DFSSorter.sort_semester(); string output = ""; int maxSem = DFSSorter.Semester.Max <int>(); Debug.WriteLine($"maxSem = {maxSem}"); for (int k = 0; k < DFSSorter.Semester.Count(); k++) { Debug.WriteLine($"{graphdetails[k][0]} start {DFSSorter.Timestamp_Start[k]} stop {DFSSorter.Timestamp[k]} semester {DFSSorter.Semester[k]}"); } foreach (List <string> L in graphdetails) { output += $"Mata Kuliah: {L[0]}\n"; for (int i = 1; i < L.Count; i++) { output += $"\tPrequisite: {L[i]}\n"; } } GraphInfo.Text = output; string outputRes = ""; for (int j = 1; j <= maxSem; j++) { outputRes += $"Semester {j}: "; while (DFSSorter.Semester.Contains(j)) { int idxCurrentMK = DFSSorter.Semester.IndexOf(j); string currentMK = graphdetails[idxCurrentMK][0]; outputRes += $"{currentMK}"; DFSSorter.Semester[idxCurrentMK] = 0; if (DFSSorter.Semester.Contains(j)) { outputRes += " ,"; } } outputRes += "\n"; } GraphResult.Text = outputRes; GraphAnimation.viewDFS(DFSResult, graphdetails); } }
private void bfs_btn(object sender, RoutedEventArgs e) { Parser p = new Parser(); List <List <string> > graphdetails = p.Parse(this.FileField.Text); if (graphdetails != null) { graphdetails = graphdetails.OrderBy(x => x[0]).ToList(); Queue <Tuple <String, int> > BFSResult = BFSSorter.topoSortBFS(graphdetails); // print Mata Kuliah dan Prerequsitenya. string output = ""; foreach (List <string> L in graphdetails) { output += $"Mata Kuliah: {L[0]}\n"; for (int i = 1; i < L.Count; i++) { output += $"\tPrequisite: {L[i]}\n"; } } GraphInfo.Text = output; // print urutan pengambilan semesteran string resultOut = ""; int sem = 0; Queue <Tuple <String, int> > copyRes = new Queue <Tuple <string, int> >(BFSResult); while (copyRes.Count() > 0) { sem++; resultOut += $"Semester {sem}: "; while (copyRes.Count() > 0 && copyRes.Peek().Item2 == sem) { Tuple <String, int> currTuple = copyRes.Dequeue(); resultOut += $"{currTuple.Item1}"; if (copyRes.Count() > 0 && copyRes.Peek().Item2 == sem) { resultOut += ", "; } } resultOut += "\n"; } GraphResult.Text = resultOut; // buat form baru untuk animasi BFS GraphAnimation.viewBFS(BFSResult, graphdetails); } }