数据结构实验报告_图的基本运算及飞机换乘次数最少问题
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。
实验报告 实验名称:二叉树的根本操作及哈夫曼编码译码系统的实现 一、问题描述 1.实验目的和要求 a.创立一棵二叉树,实现先序、中序和后序遍历一棵二叉树,计算二叉树结点个数等操作。 b.哈夫曼编码/译码系统。 2.实验任务: 能成功演示二叉树的有关运算,运算完毕后能成功释放二叉树所有结点占用的系统内存 3. 实验内容: a.①创立一棵二叉树;②先序、中序和后序遍历这棵二叉树;③计算二叉树结点个数 b.哈夫曼编码译码系统 二 程序设计 三 .程序代码 主函数: #include"CreateHfmTree.h" #include #include using namespace std; void main() { cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
System>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"<
Coding
cout<<"'M'------Show this menu."<
cout<<"'B'------Build up tree: read character set and frequency of each character, build up hfm tree."<
cout<<"'T'------Trace the tree: PreOrder and InOrder the BTree."<
cout<<"'E'------Generate code: According to the builded up hfm tree, generate the codes for all character."<
cout<<"'C'------Encode: Input arbitary string formed by characters which have been generated code, utilize the codes to ecode and print the result of encoding.(end with '#')"<
cout<<"'D'------Translate: read codefile.txt, utilize the exisiting hfm tree to translate code and restore code Into hardware file result.txt."<
cout<<"'P'------Print: Print the contents of file: textfile.txt, codefile.txt, result.txt on the screen."<
cout<<"'X'------Exit: Exit this system."<
cout<<"'-'------Delete: Delete character set, character frequencies, codes and HfmTree if they are exist."<
int w[100]; char data[100]; int n; char choice; int i,j; HfmTree hfm; HfmNode* ht; HfmCode* hc; char s[1000]; repeat1:
cout<
cout<<"Please input your chioce: "; cin>>choice; cout<
if(choice=='b' || choice=='B') {
cout<<"Please input the number of elementary code: "; cin>>n; cout<<"---------------------------------------------------------------"< cout<<"Allocating the memory..."< cout<<"Allocating the complete."<
cout<<"---------------------------------------------------------------"< cout<<"Please input all the elementary codes: "<
for(int i=0;i cin>>data[i];
cout<<"Please input all the Frenquencies: "<
for(i=0;i cin>>w[i];
hfm=CreateHfmTree(w,data,4); goto repeat1; }
if(choice=='t' || choice=='T') {
cout<<"hfm"; hfm.PreOrder(Visit);
cout<<"hfm"; hfm.InOrder(Visit); goto repeat1; }
if(choice=='e' || choice=='E') {
cout<<"Generating code..."< ht=new HfmNode[2*n-1]; hc=new HfmCode[n];
hfm.Grcode(w,data,n,ht,hc); for( i=0;i {
cout<<"'"< for( j=hc[i].start+1;j cout< cout< }
cout<<"Code Generate complete."< goto repeat1; }
if(choice=='c' || choice=='C') { cout<<"Please input the article that you want to code: "< char ch; int i=0; while(1) { cin>>ch; s[i++]=ch; if(ch=='#') break; } int length=i;
ofstream outf("testfile.txt"); if(!outf) { cout<<"Can't Open the file!"; return; } i=0;
本文来源:https://www.wddqw.com/doc/9155c072f31dc281e53a580216fc700abb6852fe.html