c# - Dependency Graph using Dictionaries and Lists -


i'm in middle of working on dependency graph, , i'm having trouble adding dependents , dependees.

i have set like:

private list<tuple<string, string>> dg; private dictionary<string, list<string>> dependants; private dictionary<string, list<string>> dependees; 

and i'm trying add dictionaries like:

for (int = 0; < dg.count; i++) {     dependants.add(dg[i].item1, new list<string>().add(dg[i].item2); } 

it gives me error "argument2: cannot convert void system.collections.generic.list" try add new list in second parameter. think know why i'm getting errors, having trouble thinking of alternative way correctly add dictionaries.

my goal this:

//dg = {("a", "b"), ("a", "c"), ("b", "d"), ("d", "d")} //     dependents("a") = {"b", "c"} //     dependents("b") = {"d"} //     dependents("c") = {} //     dependents("d") = {"d"} //     dependees("a") = {} //     dependees("b") = {"a"} //     dependees("c") = {"a"} //     dependees("d") = {"b", "d"} 

so ("a", "b") means "b" dependent of "a" , "a" dependee of "b"

its little longer code, might need:

for (int = 0; < dg.count; i++) {     if (!dependants.containskey(dg[i].item1))      {         list<string> temp = new list<string>();         temp.add(dg[i].item2);          dependants.add(dg[i].item1, temp);     }     else         dependants[dg[i].item1].add(dg[i].item2); } 

hopefully longer code helps understand flow. making dependants. also, missing bracket close in original code:

dependants.add(dg[i].item1, new list<string>().add(dg[i].item2); 

should be

dependants.add(dg[i].item1, new list<string>().add(dg[i].item2)); 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -