Кодирование информации методом Хаффмана
Автор: Igor666 • Июнь 12, 2019 • Лабораторная работа • 490 Слов (2 Страниц) • 412 Просмотры
Листинг:
MainForm:
using System;
using System.Collections;
using System.Windows.Forms;
namespace Coding
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
HuffmanTree huffmanTree = new HuffmanTree();
BitArray encoded;
private void btnEncode_Click(object sender, EventArgs e)
{
string input = txtBoxSource.Text;
huffmanTree.Build(input);
encoded = huffmanTree.Encode(input);
foreach (bool bit in encoded)
{
txtBoxResult.Text = txtBoxResult.Text + (bit ? 1 : 0);
}
}
private void btnDecode_Click(object sender, EventArgs e)
{
string decoded = huffmanTree.Decode(encoded);
txtBoxResult.Text = "Decoded: " + decoded;
}
}
}
using System.Linq;
using System.Collections;
using System.Collections.Generic;
namespace Coding
{
public class Tree
{
private List<Node> nodes = new List<Node>();
public Node Root { get; set; }
public Dictionary<char, int> Frequencies = new Dictionary<char, int>();
List<bool> encodedSource;
public void Build(string source)
...