You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add Huffman in C#.
* Rename EncodeResult to EncodingResult. Remove lines left over from debugging. Add mention.
* Replace children array with left and right child. Write the count of the readableBitString to console. Have Node implement IComparable<Node> and improve the code according to that. Improve the creation of the initial list of nodes. Refactor NodePriorityList. Improve Node creation.
* Use a string instead of a List<bool>. Also add comments explaining why we're not using something like a BitArray. Change the name of the enumerator "boolean" to "bit". Fix the Pop method by using "this.nodes[0]" instead of "this.nodes.First()". Improve the way to find out, if a Node is a Leaf.
* Make dictionary creation recursive.
* Make HuffmanCoding non-static. Fix Add method. Change input to "bibbity bobbity". Remove unnecessary braces.
* Use new mention template.
// Create a List of all characters and their count in input by putting them into nodes.
114
+
varnodes=input
115
+
.GroupBy(c =>c)
116
+
.Select(n =>Node.CreateLeaf(n.Key,n.Count()))
117
+
.ToList();
118
+
119
+
// Convert list of nodes to a NodePriorityList.
120
+
varnodePriorityList=newNodePriorityList(nodes);
121
+
122
+
// Create Tree.
123
+
while(nodePriorityList.Count>1)
124
+
{
125
+
// Pop the two nodes with the smallest weights from the nodePriorityList and create a parentNode with the CreateBranch method. (This method adds the keys and weights of the childs together.)
// We're using a string right here. While no compression is achieved with a string, it's the easiest way to display what the compressed result looks like. Also this is just an educational example.
0 commit comments