From dd009b50a37d17b21d4510874563dafa77cc2c5e Mon Sep 17 00:00:00 2001 From: Eduardo Machado <emm14@inf.ufpr.br> Date: Mon, 16 Nov 2015 13:46:48 -0200 Subject: [PATCH] =?UTF-8?q?convers=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/lzw.h | 2 +- src/lzw.cpp | 30 ++++++++++++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/include/lzw.h b/include/lzw.h index a878020..e45e614 100644 --- a/include/lzw.h +++ b/include/lzw.h @@ -3,6 +3,6 @@ class LZW{ public: - string pack(string &input); + int* pack(string &input); string unpack(int input[]); }; \ No newline at end of file diff --git a/src/lzw.cpp b/src/lzw.cpp index 4177540..885f21b 100644 --- a/src/lzw.cpp +++ b/src/lzw.cpp @@ -5,11 +5,13 @@ using namespace std; -string LZW::pack(string &input){ +int* LZW::pack(string &input){ map<string, int> dictionary; string output = ""; string nextChar, currentChar = ""; - int i, cont=0, dictionarySize = 256; + int i, temp, n, lastI, cont=0, dictionarySize = 256; + int *intOutput; + intOutput = new int[dictionarySize-1]; //inicializa o dicionĂ¡rio for(i = 0; i < 256; i++){ @@ -31,25 +33,25 @@ string LZW::pack(string &input){ output += dictionary[currentChar] + " "; cont++; - /* CONVERSAO - int *intOutput; - int temp = n = 0; - intOutput = new int[dictionarySize-1]; + // --------------------- CONVERSAO -------------------------- - for(i = 0; i < cont; i++){ - if(output[i] != " "){ + do{ + if(output[i] != ' ' && output[i] != '\0'){ temp++; } else { - for (j = temp-1; j >= 0; j--){ - intOutput[n] += output[j] * pow(10,j); + for (j = lastI; j < i; j++){ + intOutput[n] += (output[j] - '0') * pow(10,temp-1); + temp--; } n++; - temp = 0; + lastI = i+1; } - } - */ + i++; + }while (output[i-1] != '\0'); + + //----------------------------------------------------------- - return intOutput; + return &intOutput; } string LZW::unpack(int input[]){ -- GitLab