This project showcases the implementation of Huffman encoding in C++ to compress and decompress text files using Huffman coding techniques. The code provided demonstrates a basic Huffman encoding and decoding process.
fileIO.h
: Header file containing functions to read from and write to files.Queue.h
: Header file for the Queue data structure implementation.Tree.h
: Header file for the Tree data structure implementation.fileIO.cpp
: Implementation file defining file input/output functionalities.Queue.cpp
: Implementation file for the Queue data structure.Tree.cpp
: Implementation file for the Tree data structure.main.cpp
: The main code file containing the Huffman encoding and decoding logic.
iostream
: Standard input-output library in C++.string
: C++ library for string manipulation.- Custom user-defined header files for file I/O, Queue, and Tree implementations.
The main()
function in the main.cpp
file represents the driver function for the Huffman encoding process. It performs the following steps:
- Reads text data from a file named "Text".
- Constructs a Huffman tree using the provided data.
- Encodes the text data using the constructed Huffman tree.
- Writes the Huffman tree and the encoded binary string to a file.
- Reads the Huffman tree and the encoded data from the generated files.
- Decodes the encoded data to retrieve the original text using the Huffman tree.
The implementation involves creating a Huffman tree from the given text data. This tree is then used to encode the text into binary data, followed by writing the encoded data and tree structure into separate files. Upon decoding, the original text is retrieved from the compressed binary data using the Huffman tree.
To use this code, follow these steps:
- Compile the code using a C++ compiler.
- Ensure that the text file named "Text" exists and contains the text to be encoded.
- Run the compiled program.
Documented by ChatGPT