Ejemplo n.º 1
0
        private static LinkedNode BuildList(byte[] PrimeData)
        {
            var root = new LinkedNode(256, 1);

            root = root.Insert(new LinkedNode(257, 1));

            for (int i = 0; i < PrimeData.Length; i++)
            {
                if (PrimeData[i] != 0)
                {
                    root = root.Insert(new LinkedNode(i, PrimeData[i]));
                }
            }
            return(root);
        }
Ejemplo n.º 2
0
 // 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);
 }
Ejemplo n.º 3
0
        private static LinkedNode BuildTree(LinkedNode Tail)
        {
            LinkedNode current = Tail;

            while (current != null)
            {
                LinkedNode child0 = current;
                LinkedNode child1 = current.Prev;
                if (child1 == null)
                {
                    break;
                }

                LinkedNode parent = new LinkedNode(0, child0.Weight + child1.Weight);
                parent.Child0 = child0;
                child0.Parent = parent;
                child1.Parent = parent;

                current.Insert(parent);
                current = current.Prev.Prev;
            }
            return(current);
        }
Ejemplo n.º 4
0
		private static LinkedNode BuildList(byte[] PrimeData)
		{
		    var root = new LinkedNode(256, 1);
			root = root.Insert(new LinkedNode(257, 1));

			for(int i = 0; i < PrimeData.Length; i++)
			{
				if (PrimeData[i] != 0) 
					root = root.Insert(new LinkedNode(i, PrimeData[i]));
			}
			return root;
		}