public void Reset(int value, int weight) { this.value = value; this.weight = weight; next = null; previous = null; parent = null; child = null; }
public void InsertAfter(HuffmanItem item, HuffmanItem newItem) { newItem.Next = item.Next; newItem.Previous = item; if (item.Next != null) { item.Next.Previous = newItem; } else if (item == tail) { tail = newItem; } item.Next = newItem; }
public void InsertBefore(HuffmanItem item, HuffmanItem newItem) { newItem.Next = item; newItem.Previous = item.Previous; if (item.Previous != null) { item.Previous.Next = newItem; } else if (item == head) { head = newItem; } item.Previous = newItem; }
public void Remove(HuffmanItem item) { if (item == tail) { tail = item.Previous; } if (item == head) { head = item.Next; } if (item.Previous != null) { item.Previous.Next = item.Next; } if (item.Next != null) { item.Next.Previous = item.Previous; } item.Next = item.Previous = null; }
HuffmanItem GetNewItem(int value, int weight) { HuffmanItem item; if (usedItemCount < itemCount) { item = itemArray[usedItemCount++]; } else if (itemCount < itemArray.Length) { item = itemArray[itemCount++] = new HuffmanItem(); usedItemCount++; } else { throw new Exception("No more items"); } item.Reset(value, weight); return(item); }
public void InsertWeighted(HuffmanItem item) { HuffmanItem current; // If tail is null then head is null too if (tail == null) { tail = head = item; return; } current = tail; while (current != null && current.Weight < item.Weight) { current = current.Previous; } if (current != null) { item.Previous = current; item.Next = current.Next; current.Next.Previous = item; current.Next = item; if (item.Next == null) { tail = item; } } else { item.Previous = null; item.Next = head; current.Previous = item; } }
public void Clear() { head = null; tail = null; }
void Reset() { root = null; itemList.Clear(); usedItemCount = 0; }
public void InsertWeighted(HuffmanItem item) { HuffmanItem current; // If tail is null then head is null too if (tail == null) { tail = head = item; return; } current = tail; while (current != null && current.Weight < item.Weight) current = current.Previous; if (current != null) { item.Previous = current; item.Next = current.Next; current.Next.Previous = item; current.Next = item; if (item.Next == null) tail = item; } else { item.Previous = null; item.Next = head; current.Previous = item; } }
public void Remove(HuffmanItem item) { if (item == tail) tail = item.Previous; if (item == head) head = item.Next; if (item.Previous != null) item.Previous.Next = item.Next; if (item.Next != null) item.Next.Previous = item.Previous; item.Next = item.Previous = null; }
public void InsertBefore(HuffmanItem item, HuffmanItem newItem) { newItem.Next = item; newItem.Previous = item.Previous; if (item.Previous != null) item.Previous.Next = newItem; else if (item == head) head = newItem; item.Previous = newItem; }
public void InsertAfter(HuffmanItem item, HuffmanItem newItem) { newItem.Next = item.Next; newItem.Previous = item; if (item.Next != null) item.Next.Previous = newItem; else if (item == tail) tail = newItem; item.Next = newItem; }
HuffmanItem GetNewItem(int value, int weight) { HuffmanItem item; if (usedItemCount < itemCount) item = itemArray[usedItemCount++]; else if (itemCount < itemArray.Length) { item = itemArray[itemCount++] = new HuffmanItem(); usedItemCount++; } else throw new Exception("No more items"); item.Reset(value, weight); return item; }