public Graph(LinkedList<LinkedList<string>> table) { tohm = new Dictionary<string, LinkedList<GFlight>>(); foreach (LinkedList<string> row in table) { GFlight f = new GFlight(row); if (tohm.ContainsKey(f.from)) { foreach (GFlight flight in tohm[f.from]) { flight.addNeighbour(f); } } if (!tohm.ContainsKey(f.to)) { tohm[f.to] = new LinkedList<GFlight>(); } tohm[f.to].AddLast(f); } }
public void addNeighbour(GFlight f) { if (!this.apendable(f)) return; neighbours.AddLast(f); }
public bool apendable(GFlight f2) { if (this.end().CompareTo(f2.at) < 0) return true; return false; }
public LinkedList<string> unionFind(GFlight current, Dictionary<string, bool> ci, Dictionary<GFlight, bool> fl) { LinkedList<string> result = new LinkedList<string>(); if (!fl.ContainsKey(current)) { if (!ci.ContainsKey(current.to)) { result.AddLast(current.to); ci[current.to] = true; } fl[current] = true; foreach (GFlight child in current.neighbours) { foreach (string s in unionFind(child, ci, fl)) { result.AddLast(s); } } } return result; }