当前位置: 首页>>代码示例>>C++>>正文


C++ HuffmanTree::compress方法代码示例

本文整理汇总了C++中HuffmanTree::compress方法的典型用法代码示例。如果您正苦于以下问题:C++ HuffmanTree::compress方法的具体用法?C++ HuffmanTree::compress怎么用?C++ HuffmanTree::compress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HuffmanTree的用法示例。


在下文中一共展示了HuffmanTree::compress方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char* argv[]) {
    using namespace ptlmuh006;

    if(argc != 4){
        std::cout << "Incorrect usage." << std::endl;
        std::cout << "Please use huffencode as follows:" << std::endl;
        std::cout << "huffencode <option> <inputFilename> <outputFilename>" << std::endl;
        std::cout << "\t___options:___" << std::endl;
        std::cout << "\t -c compress data from inputFilename to outputFilename" << std::endl;
        std::cout << "\t -x extract compressed data from inputFilename to outputFilename" << std::endl;

    }else{
        HuffmanTree* huff = new HuffmanTree;

        std::string option = argv[1];
        if(option == "-c"){
            huff->compress(argv[2], argv[3]);
            std::cout << "Compressed " << argv[2] << " into " << argv[3] << "." << std::endl;

        }else if(option == "-x"){
            huff->extract(argv[2], argv[3]);
            std::cout << "Extracted from " << argv[2] << " into " << argv[3] << "." << std::endl;
        }

        delete huff;
    }
    return 0;
}
开发者ID:muhummadPatel,项目名称:cs3022a3,代码行数:28,代码来源:driver.cpp

示例2: main

int main(){
	ifstream file;
	file.open("Amazon_EC2.txt");
	if(!file.is_open()) cout << "File not found";

	//Create a vector of freqs
	//256 for ascii values initialized to 0
	vector<int> freq(256,0);

	int c;
	int count = 0;
	while(file.good()){
		count++;
		c = file.get();
		//End of file
		if(c < 0) continue;
		freq[c] = freq[c] + 1;
	}
	file.close();

	/*
	for(int i = 0; i < freq.size(); i++){
		if(freq[i] != 0){
			double ratio = ((double)freq[i]/(double)count)*100;
			cout << (char)i <<  " " << ratio << endl;
		}
	}
	*/

	//Instantiate tree
	HuffmanTree tree;
	//Call create to make the tree 
	tree.create(freq);

	//Create output file stream
	ofstream outputFile("compressedFile.txt",ios::out);	
	stream out(outputFile);

	//Open file to get letters to compress with path
	ifstream file2;
	file2.open("Amazon_EC2.txt");

	//Call compress to write bits of each letter to the file
	char z;
	while(file2.good()){
		z = (char)file2.get();	
		tree.compress(z, out);
	}

	file2.close();
	outputFile.close();
	cout << endl << "Outputfile Created: compressedFile.txt" << endl << endl;
	return 0;	
}
开发者ID:nayrk,项目名称:CS165,代码行数:54,代码来源:huffman.cpp


注:本文中的HuffmanTree::compress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。