freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

課程設(shè)計(jì)-赫夫曼編碼系統(tǒng)設(shè)計(jì)-文庫(kù)吧

2024-12-29 18:45 本頁(yè)面


【正文】 內(nèi)存不足, 操作失敗!\n)。exit(0)。} 8 / 32ptrdata = ch。ptrnumber = 1。ptrnext = 。 = ptr。++typeNumber。}else{while ((current != NULL) amp。amp。 (currentdata != ch)){previous = current。current = currentnext。}if (current != NULL){++(currentnumber)。++characterNumber。}else{if ((ptr = (Data *)malloc(sizeof(Data))) == NULL){printf( 內(nèi)存不足, 操作失敗!\n)。exit(0)。}ptrdata = ch。ptrnumber = 1。ptrnext = current。previousnext = ptr。++typeNumber。++characterNumber。}}}fclose(fp)。codeSize = typeNumber。info = (Static *)malloc(sizeof(Static) * codeSize)。 9 / 32current = 。//將統(tǒng)計(jì)好的字符權(quán)重信息存入權(quán)重文件中for (int i=0。 icodeSize。 ++i){info[i].data = currentdata。info[i].weight = (int)(currentnumber * / characterNumber)。current = currentnext。}}. 字符解碼//此代碼用于比較查找赫夫曼編碼bool CompareData(char *tempCode, int amp。position){for (position = 0。 position codeSize。 ++position){if (strcmp(tempCode, code[position]) == 0){return true。}}return false。}void DisplayContext(){InportCharacterWeight()。CreatHuffmanTree(list, info, codeSize)。CreatHuffmanCode(list, code, codeSize)。InportFileCoding()。FILE *fp。int position。int end。char *tempCode。char ch。fp = fopen(fileName, rb)。 10 / 32if ((tempCode = (char *)malloc(sizeof(char) * codeSize)) == NULL){printf( 內(nèi)存不足, 操作失敗!\n)。exit(0)。}end = 0。/******************************此部分為解碼過(guò)程************************/printf(\n 文件內(nèi)容為:\n\n )。while ((ch = fgetc(fp)) != EOF){tempCode[end] = ch。++end。tempCode[end] = 39。\039。if (CompareData(tempCode, position)){printf(%c, info[position].data)。end = 0。}}printf(\n\n 按任意鍵結(jié)束!)。getch()。}6. 實(shí)驗(yàn)結(jié)果經(jīng)過(guò)多次對(duì)本程序的實(shí)驗(yàn),此次編譯完成的程序可以對(duì)簡(jiǎn)單的文本文件進(jìn)行加密和解密,因?yàn)橄抻趯?duì)文件的基本操作不是太完全清楚,只是匆匆查閱了一些關(guān)于 C 語(yǔ)言文件操作部分的資料,所以這也是文件操作方面的一個(gè)瑕疵。所以綜上,次此的程序只能進(jìn)行簡(jiǎn)單的加密與解密操作。 11 / 32(圖 1:赫夫曼加密程序主體窗口)(圖 2:赫夫曼文件編碼程序窗口)(圖 3:用于測(cè)試的文本 原始文本內(nèi)內(nèi)容)(圖 4:導(dǎo)出文件編碼后,在創(chuàng)建的編碼文件中生成的二進(jìn)制數(shù)) 12 / 32(圖 5:導(dǎo)出的文本密鑰(即字符權(quán)重) )(圖 6:赫夫曼文件譯碼程序窗口)(圖 7:將之前生成的編碼文件與密鑰導(dǎo)入進(jìn)來(lái)后顯示出原來(lái)的文本內(nèi)容)7. 設(shè)計(jì)體會(huì)進(jìn)過(guò)此次的實(shí)驗(yàn),讓我對(duì)樹(shù)結(jié)構(gòu)及最優(yōu)二叉樹(shù)概念與操作的理解。在此次選擇赫夫曼編碼操作的時(shí)候,本打算用赫夫曼編碼的程序?qū)ξ募M(jìn)行壓縮存儲(chǔ),可是限于不知道怎樣將生成的赫夫曼編碼進(jìn)行 bit 級(jí)別的存儲(chǔ)(只知道進(jìn)行 Byte 級(jí)別的存儲(chǔ)) ,所以壓縮存儲(chǔ)的想法失敗了,之后根據(jù)赫夫曼編碼的結(jié)構(gòu)及生成的文件,不得不讓我想到了文件的加密與解密,于是按著這個(gè)思路來(lái)設(shè)計(jì)了本文件加密解密系統(tǒng)。在設(shè)計(jì)的時(shí)候,曾準(zhǔn)備根據(jù)網(wǎng)上之前對(duì) 26 個(gè)英文字符的使用統(tǒng)計(jì)來(lái)事先對(duì)字符權(quán)重進(jìn)行分配(這樣加密的文件可解密性增加了) ,而且考慮到文件中不僅有 26 個(gè)英文字母,如果對(duì)各種字符的使用頻率進(jìn)行統(tǒng)計(jì),這個(gè)事先工作的負(fù)擔(dān)會(huì)很重,所以之后編寫(xiě)了自動(dòng)統(tǒng)計(jì)文本字符的頻率程序,這樣工作量會(huì)減小很多(而且文件的可解密性大大減小,但是也帶來(lái)了記錄密鑰的不方便) 。 13 / 32總體感覺(jué)程序還行,就是代碼的簡(jiǎn)潔性還是有點(diǎn)差,條理還是不那么清晰。8. 參考文獻(xiàn)[1]嚴(yán)蔚敏、[2]Thomas 、Charles .9. 附:程序代碼includeincludeincludeinclude//赫夫曼樹(shù)結(jié)構(gòu)typedef struct{ char data。 int weight。 int parent, lchild, rchild。}HuffmanTree。 //字符權(quán)重結(jié)構(gòu)typedef struct{char data。int weight。}Static。//統(tǒng)計(jì)字符時(shí)所用到的鏈表結(jié)構(gòu)typedef struct node{char data。int number。struct node *next。}Data。//赫夫曼代碼結(jié)構(gòu)typedef char** HuffmanCode。 14 / 32//創(chuàng)建赫夫曼樹(shù)void CreatHuffmanTree(HuffmanTree *amp。list, Static *info, int codeSize)。//創(chuàng)建赫夫曼代碼void CreatHuffmanCode(HuffmanTree *list, HuffmanCode amp。code, int codeSize)。//從文件中讀取數(shù)據(jù)并計(jì)算各字符出現(xiàn)頻率void DataCount(Static *amp。info)。//文件編碼程序void FileEncoding()。//創(chuàng)建文件編碼void CreatFileCoding()。//導(dǎo)出編碼后文件void ExportFileEncoding(HuffmanTree *list, HuffmanCode code, int codeSize)。//導(dǎo)出文件中字符權(quán)重void ExportCharacterWeight()。//文件譯碼程序void FileDecoding()。//導(dǎo)入編碼后的文件void InportFileCoding()。//導(dǎo)入文件中字符權(quán)重void InportCharacterWeight()。//顯示譯碼后的文件內(nèi)容void DisplayContext()。bool CompareData(char *tempCode, int amp。position)。void Bound(char character, int size)。//赫夫曼樹(shù)HuffmanTree *list。//赫夫曼代碼HuffmanCode code。//字符權(quán)重信息Static *info。//字符種數(shù)int codeSize。//文件名char fileName[30]。int main(){char choice。 15 / 32while (true){system(CLS)。printf( 赫夫曼編碼加密程序\n)。Bound(39。39。, 25)。printf( 1. 文 件 編 碼 \n)。printf( 2. 文 件 譯 碼 \n)。printf( 0. 退 出 程 序 \n)。Bound(39。39。, 25)。printf( 請(qǐng)選擇: )。fflush(stdin)。choice = getchar()。switch (choice){case 39。139。:FileEncoding()。break。case 39。239。:FileDecoding()。break。case 39。039。:printf(\n)。system(PAUSE)。return 0。break。default:printf(\n 您的輸入有誤, 按任意鍵后請(qǐng)從新輸入!)。getch()。break。}}}void CreatHuffmanTree(HuffmanTree *amp。list, Static *info, int codeSize){int i, j, limit。 int lnode, rnode。 int value1, value2。HuffmanTree *ptr。 16 / 32limit = codeSize * 2 1。if ((list = (HuffmanTree *)malloc(sizeof(HuffmanTree) * limit)) == NULL){printf( 內(nèi)存不足, 操作失敗!\n)。exit(0)。} for(i=0, ptr=list。 icodeSize。 ++i, ++ptr){ptrdata = info[i].data。ptrweight = info[i].weight。ptrparent = ptrlchild = ptrrchild = 1。}for(。 ilimit。 ++i, ++ptr){ptrdata = 39。039。ptrweight = 0。ptrparent = ptrlchild = ptrrchild = 1。} for(i=codeSize。 ilimit。 ++i){ value1 = value2 = 32767。 lnode = rnode = 1。 for(j=0。 ji。 ++j) {if (list[j].parent == 1){ if (list[j].weight value1){ value2 = value1。rnode = lnode。 value1 = list[j].weight。lnode = j。} else if (list[j].weight value2){
點(diǎn)擊復(fù)制文檔內(nèi)容
環(huán)評(píng)公示相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1