Hi,
So I have a class ClassMate:
public class ClassMate { public Guid Id { get; set; } public List<Guid> Depends { get; set; }
public ClassMate()
{
Id = Guid.NewGuid();
Depends = new List<Guid>();
} }
I fill a list of ClassMates like this:
var mate1 = new ClassMate();
var mate2 = new ClassMate(); var mate3 = new ClassMate();
var mate4 = new ClassMate();
mate2.Depends.Add(mate4.Id);mate3.Depends.Add(mate2.Id);
mate1.Depends.Add(mate3.Id);
mate1.Depends.Add(mate4.Id);var list = new List<ClassMate>(); list.Add(mate1); list.Add(mate2); list.Add(mate3); list.Add(mate4);
Now I need to order them in a new list, so that no mate's index is lower than one of its dependant. In other words, what I want is a list that looks like this:
list[0] = mate4
list[1] = mate2
list[2] = mate3
list[3] = mate1
Can you suggest an elegant way to sort like this?
--
Werner