Thread: LZW Compression (C++ Programming)

  1. #1
    Registered User
    Join Date
    Mar 2002

    Question LZW Compression (C++ Programming)

    I'm tyring to write a simple LZW compression program the goal is to compress 20 repeats of ABBA. I've run into trouble when it comes to implementing the algorithm in C++.

    My problem is comparing a string called CODE (which contains some of the characters from the input ABBA) with another character or string K which looks at the next letter from the input string. I need to merge these CODE and K and compare these with the entries in the dictionary to see if they exist. The example below should make it clearer


    Initialize dictionary 0:A 1:B 2:C 3

    1.K=A in dictionary? Yes
    2.CODE <-K
    is AB ([CODE]K) in dictionary? No
    add [CODE]K to dictionary 4:AB
    output the numerical representation of code to output stream (1 (for B))
    3.Code now becomes B (CODE<-K)
    K=next char (B)
    is BB in dictionary N etc...

    If anyone has an idea of how i can implement code and K such that i can compare them as above then I would be eternally grateful.


  2. #2
    Registered User
    Join Date
    Mar 2002
    I'm sure you could STFW or search the C++ Programming Board that is also included within this site. If that's a homework problem (which I assume it is) make sure you read the sticky post about that issue.

  3. #3
    Join Date
    Aug 2001
    Groningen (NL)
    Here's a lot of info about datacompression and also sources.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple compression algorithm?
    By cyberfish in forum Tech Board
    Replies: 8
    Last Post: 05-02-2008, 09:10 AM
  2. Data Compression
    By Ezerhorden in forum C++ Programming
    Replies: 5
    Last Post: 02-11-2006, 10:19 AM
  3. compression
    By X PaYnE X in forum C Programming
    Replies: 20
    Last Post: 01-11-2005, 05:14 PM
  4. efficient compression algorithm pls
    By gooddevil in forum C Programming
    Replies: 7
    Last Post: 05-08-2004, 03:33 AM
  5. File Compression
    By Gr3g in forum C++ Programming
    Replies: 1
    Last Post: 04-16-2002, 04:59 PM