LZW Compression (C++ Programming)

This is a discussion on LZW Compression (C++ Programming) within the C++ Programming forums, part of the General Programming Boards category; I'm tyring to write a simple LZW compression program the goal is to compress 20 repeats of ABBA. I've run ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    1

    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

    ABBA

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

    1.K=A in dictionary? Yes
    2.CODE <-K
    K=B
    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.

    Thanks

  2. #2
    Nit
    Nit is offline
    Registered User
    Join Date
    Mar 2002
    Posts
    42
    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.
    http://www.KBeutler.com

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

    http://www.data-compression.com

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, 09:19 AM
  3. compression
    By X PaYnE X in forum C Programming
    Replies: 20
    Last Post: 01-11-2005, 04: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21