Je
BAN USERpublic static List<MyGroup> FindMembers(Dictionary<string, HashSet<string>> groupMembers)
{
Dictionary<string, MyGroup> groups = new Dictionary<string, MyGroup>();
List<KeyValuePair<string, string>> map = new List<KeyValuePair<string, string>>();
foreach (var groupName in groupMembers.Keys)
{
groups.Add(groupName, new MyGroup(groupName));
foreach (var memberName in groupMembers[groupName])
{
map.Add(new KeyValuePair<string, string>(groupName, memberName));
}
}
foreach (var pair in map)
{
var parent = groups[pair.Key];
if (groups.ContainsKey(pair.Value))
{
var child = groups[pair.Value];
parent.Members.Add(pair.Value, child);
child.MemberOf.Add(pair.Key, parent);
}
else
{
parent.Users.Add(pair.Value);
}
}
return groups.Values.ToList();
}
Create a new max heap.
- Je August 30, 2015rank = 0
Add max from the original heap to new heap.
repeat
1. pop from new heap, rank++;
2. if rank == k, return the element from 1. otherwise proceed to 3.
3. find children of the element from the original heap
4. add them to new heap, heapify