Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //FETCHER.CS
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- namespace Alg_Huffmana
- {
- class Fetcher
- {
- public static List<KeyValuePair<char, int>> FillDictionary(string path)
- {
- var charDictionary = new Dictionary<char, int>();
- using (StreamReader sr = File.OpenText(path))
- {
- while(!sr.EndOfStream)
- {
- var ch = (char)sr.Read();
- var item = charDictionary.Where(p => p.Key == ch);
- if (item.Count() != 0)
- {
- var itemValue = charDictionary[ch];
- charDictionary[ch] = ++itemValue;
- }
- else
- {
- charDictionary.Add(ch, 1);
- }
- }
- }
- var sortedList = charDictionary.ToList();
- sortedList.Sort((p1, p2) => p1.Value.CompareTo(p2.Value));
- SortedDictionary<char, int> sortedDictionary = new SortedDictionary<char, int>(charDictionary);
- sortedDictionary.OrderBy(p => p.Value);
- return sortedList;
- }
- }
- }
- //Huffman.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using NGenerics.DataStructures.Trees;
- namespace Alg_Huffmana
- {
- public class HuffmanTree : BinaryTree<Node>
- {
- private KeyValuePair<int, int> root;
- public void Add(int key, int value)
- {
- if (this.Count == 0)
- {
- root = new KeyValuePair<int, int>(key, value);
- }
- }
- public string GetCodeFromTree(KeyValuePair<char, int> pair) //PRZESZUKIWANIE
- {
- }
- }
- }
- //Node.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Alg_Huffmana
- {
- public class Node
- {
- public int sumLeftRight { get; set; }
- public KeyValuePair<char, int> pair { get; set; }
- public int Compare(object x, object y)
- {
- if (((Node)x).pair.Value > ((Node)y).pair.Value)
- {
- return 1;
- }
- if (((Node)x).pair.Value < ((Node)y).pair.Value)
- {
- return -1;
- }
- else
- {
- return 0;
- }
- }
- }
- }
- Nuget NGenerics BinnaryTree
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement