Click here to Skip to main content
15,886,724 members
Articles / Programming Languages / C++

Huffman Compression Program Using C++

Rate me:
Please Sign up or sign in to vote.
3.18/5 (16 votes)
9 Jul 2007CPOL2 min read 67.3K   4.1K   26   8
Compress any type of file using Huffman compression method, used so many teqniques such as template and wrote with OOD

Introduction

This program simply compresses any files with any size using Huffman compression method. To use this program, you can download and modify its code by your own desires.

Background

This program uses a heap for insertion and finding minimum elements and a tree to create each character's Huffman string, then reads characters from a file and puts each character's string into the buffer. Then for each 8 bits (from the buffer), creates a byte and then puts that byte into the file's buffer when the buffer of bits is full. When the file's buffer is full, the program writes all of the characters into the file until the last character of the file is read. To decompress, the file reads counts of character from the zipped file(a signature used for this) and then creates the Huffman tree, then reads each character from the file and decides for each bit how to move over the Huffman's tree. Then when it reaches a leaf, it puts its character into the file's buffer and when the file's buffer is full, the program writes the characters to the file so you can simply use it to compress any file.

Using the Code

I've implemented this program using most of good C++ tools such as STL, Linked List.. a buffer is set to hold the file's characters so the program runs faster.

I've written comments for each line and tried to make it easy for you to use the program.

Hope you guys enjoy it.

History

This is version 1.0 of this program
Update: The earlier version had a problem with some machines, so I had it fixed! If you still have any problem with running this new Huffman.exe file, please let me know by sending email to software.programmin@yahoo.com and I'll be happy to hear your advice ;)

Copyright © 2007. Using this program is allowed just by mentioning my name, something like this:

"Programmed by Alireza Noori"

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Iran (Islamic Republic of) Iran (Islamic Republic of)
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionHuffman in java Pin
p.bajra8-Jul-14 15:52
p.bajra8-Jul-14 15:52 
GeneralMy vote of 5 Pin
aramghaderi7127-Jun-12 7:05
aramghaderi7127-Jun-12 7:05 
دمت گرم آقا علیرضا . منم میخواستم همین برنامه رو که شما نوشتی بنویسم و دموهای مختلفی دانلود کردم ببینم کدوم روش بهتر جواب میده که فقط مال شما درست کار می کرد
Generalhelp me Pin
tdduy_khtn11-Apr-09 16:40
tdduy_khtn11-Apr-09 16:40 
QuestionHuffman code with verilog Pin
elec_engineer16-Feb-09 0:13
elec_engineer16-Feb-09 0:13 
General:o Pin
mahyar mottaghizadeh3-Jan-09 5:04
mahyar mottaghizadeh3-Jan-09 5:04 
GeneralDecompress is broken Pin
Jacob2922-Oct-08 16:52
Jacob2922-Oct-08 16:52 
GeneralExcelent!!!! Very good. Pin
Sammuel1-Dec-07 9:02
Sammuel1-Dec-07 9:02 
GeneralFast Huffman coding Pin
Hatem Mostafa27-Mar-07 21:29
Hatem Mostafa27-Mar-07 21:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.