[問題] huffman decode/encode 無法順利進行

看板C_and_CPP (C/C++)作者 (Qimat)時間13年前 (2013/06/03 20:51), 編輯推噓1(104)
留言5則, 2人參與, 最新討論串1/1
大家好,不好意思初次發文請教問題, 這是一個程式作業 主要是在撰寫huffman decode 與 encode 編碼及解碼都可以順利把文章轉換過來 但是似乎還有錯誤的存在 可是我完全找不到錯誤啊QQ 問題(Question): 助教給我的錯誤訊息是codebookE中的huffman code長度錯誤 符號錯誤(但我找過好多次 應該都是正確的啊QQ) 餵入的資料(Input): article 1 = http://pastie.org/8000265 article 2 = http://pastie.org/8000267 預期的正確結果(Expected Output): article 1結果 = codebookE.txt 是各個字元編碼結果 http://pastie.org/8000284 codebookD.txt 則是tree的結果 以postorder輸出 http://pastie.org/8000295 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版) 建立huffman tree 及輸出codebook E與D 的程式碼: http://pastie.org/8000301 encode(將codebookE.txt與article為input 照著英文字母輸出一長串編碼) : http://pastie.org/8000304 decode(將一長串編碼與codebookD輸出至restore) http://pastie.org/8000317 restore.txt的結果會跟article.txt一樣 補充說明(Supplement): 主要是huffman tree的地方 codebookE.txt (也就是各個字元的編碼) 是不是有那裡錯誤了 還是建立tree的時候就錯了呢?? 那錯的時候 為什麼還可以還原的回來 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.114.202.216

06/04 09:13, , 1F
下中斷點不然就是單步執行
06/04 09:13, 1F

06/05 02:11, , 2F
測試article=aabbbccddddddddd, segmentation fault
06/05 02:11, 2F

06/05 02:39, , 3F
再測試article=aabbbccddddddd, 你的結果: 97 110, 98 10
06/05 02:39, 3F

06/05 02:41, , 4F
99 111, 100 0, 我覺得答案要的是 97 000, 98 01, 99 001
06/05 02:41, 4F

06/05 02:41, , 5F
100 1
06/05 02:41, 5F
文章代碼(AID): #1Hh94tuJ (C_and_CPP)
文章代碼(AID): #1Hh94tuJ (C_and_CPP)