// TODO: This would be more efficient as a member of the other class // ie avoid the recursion public LinkedNode Insert(LinkedNode other) { // 'Next' should have a lower weight // we should return the lower weight if (other.Weight <= Weight) { // insert before if (Next != null) { Next.Prev = other; other.Next = Next; } Next = other; other.Prev = this; return(other); } else { if (Prev == null) { // Insert after other.Prev = null; Prev = other; other.Next = this; } else { Prev.Insert(other); } } return(this); }
private static LinkedNode BuildList(byte[] primeData) { LinkedNode root; root = new LinkedNode(256, 1); root = root.Insert(new LinkedNode(257, 1)); for (var i = 0; i < primeData.Length; i++) { if (primeData[i] != 0) { root = root.Insert(new LinkedNode(i, primeData[i])); } } return(root); }