public override int Compare(Node one, Node two) { //most important factor are weights if (one.Weight < two.Weight) { return(-1); } else if (one.Weight > two.Weight) { return(1); } else { //leaves are lighter then inner nodes if (one is Leaf && two is InnerNode) { return(-1); } else if (one is InnerNode && two is Leaf) { return(1); } else if (one is Leaf && two is Leaf) { Leaf first = (Leaf)one; Leaf second = (Leaf)two; //of two leves the one with lower Symbol is lighter if (first.Symbol < second.Symbol) { return(-1); } else if (first.Symbol > second.Symbol) { return(1); } else { return(0); } } else if (one is InnerNode && two is InnerNode) { InnerNode first = (InnerNode)one; InnerNode second = (InnerNode)two; //of two inner nodes, the one that had been created sooner is lighter if (first.TimeOfCreation < second.TimeOfCreation) { return(-1); } else if (first.TimeOfCreation > second.TimeOfCreation) { return(1); } else { return(0); } } else { return(0); } } }