blob: 779c8f34799a20cb64fc23ecab20cb35e97e1487 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
using System;
using System.Collections;
using System.Collections.Generic;
using PriorityQueue;
namespace Huffman
{
public class HuffmanNode<TElement, TPriority> : INode<TPriority>, IComparable<INode<TPriority>>
where TPriority : IComparable<TPriority>
{
public HuffmanNode<TElement, TPriority> Left { get; set; }
public HuffmanNode<TElement, TPriority> Right { get; set; }
public TElement Element { get; set; }
public TPriority Key { get; set; }
public HuffmanNode(TPriority key) =>
Key = key;
public HuffmanNode(TPriority key, TElement element) : this(key) =>
Element = element;
public int CompareTo(INode<TPriority> node) =>
Key.CompareTo(node.Key);
public static implicit operator HuffmanNode<TElement, TPriority>(DictionaryEntry item) =>
new HuffmanNode<TElement, TPriority>((TPriority)item.Value, (TElement)item.Key);
}
}
|