private bool IsParentCyclic(int parentID) { if (parentID != -1) { GraphDirected graph = LabelList.CreateParentGraph(); graph.Add(ID, parentID); return(graph.IsCyclic(ID)); } return(false); }
static public GraphDirected CreateParentGraph() { GraphDirected graph = new GraphDirected(); DBInterface.CommandText = "SELECT * FROM sellcontroller.label"; DataTable tab = DBInterface.ExecuteSelection(); foreach (DataRow row in tab.Rows) { if (!(row["idParent"] is DBNull)) { graph.Add(Convert.ToInt32(row["idLabel"]), Convert.ToInt32(row["idParent"])); } } return(graph); }
static void Main(string[] args) { Console.WriteLine("Graph implementation"); GraphDirected gh = new GraphDirected(); //gh.CreateDefault(); //gh.DisplayEdges(); gh.AddEdge(0, 2); gh.AddEdge(2, 1); gh.AddEdge(3, 1); gh.AddEdge(3, 2); //gh.DisplayEdges(); //gh.RemoveEdge(0, 1); gh.AddEdge(4, 0); gh.AddEdge(4, 2); gh.AddEdge(4, 3); gh.DisplayEdges(); gh.NodeTraversal(); Console.WriteLine($"Mother Vertex: {gh.FindMotherVertex()}"); Console.ReadLine(); }