77范文网 - 专业文章范例文档资料分享平台

哈夫曼编、译码器(6)

来源:网络收集 时间:2019-01-10 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

数据结构课程设计报告

//队列类

#pragma once

template//模板队列类 class Queue { private : T num[MAX];//队列中的数据元素 int front,rear;//队首,队尾的标志 public:

Queue(void);//构造函数 ~Queue(void);//析构函数 void EnQueue(T p);//入队操作 T DeQueue();//出队操作

bool IsEmpty();//判断队列是否为空 bool IsFull();//判断队列是否已满 void Clear();//清空队列

};

template Queue::Queue() { this->front=-1;//将标记初始化为-1 this->rear=-1;

}

template

Queue::~Queue() //析构函数的实现 { }

template

void Queue::EnQueue(T p) //入队函数的实现 { if(this->IsFull())//如果队列已满,则退出程序 { cout<<\<

}

else//如果没有满,则将元素入队 {

rear=(rear+1)%MAX; 2

5 数据结构课程设计报告

num[rear]=p;

}

}

template

T Queue::DeQueue()//出队的函数实现 { if(this->IsEmpty())//如果队列为空则返回NULL { cout<<\<

else//如果队列不为空,则将队首元素出对 { front=(front+1)%MAX; T p=num[front]; return p;

}

}

template

bool Queue::IsEmpty()//判断队列是否为空的函数实现 { if(front==rear) return true;

else

return false; }

template

bool Queue::IsFull()//判断队列是否已满的函数实现 { if((rear+1)%MAX==front) return true; else

return false; }

template void Queue::Clear() { front=rear=-1;

}

2

6 数据结构课程设计报告

//哈夫曼结点类

#pragma once #include #include using namespace std;

template//模板哈夫曼结点类 class HuaffmanTreeNode { private : };

template

HuaffmanTreeNode::HuaffmanTreeNode() // {

int Key;//该字符出现的次数; Type Data;// 输入的字符元素;

HuaffmanTreeNode *parent;//双亲结点指针; HuaffmanTreeNode *lchild;//左孩子结点指针; HuaffmanTreeNode *rchild;//右孩子结点指针;

int Tag;//记录该结点是双亲的左右孩子,左孩子为,有孩子为; HuaffmanTreeNode *next;//下一个结点,用于链表 bool Flag;//标记该结点是否已经计入哈弗曼树 HuaffmanTreeNode(void);//默认构造函数; HuaffmanTreeNode(int

k,Type

d,int

t,HuaffmanTreeNode

public:

*p=NULL,HuaffmanTreeNode*l=NULL,HuaffmanTreeNode *r=NULL);//构造函数

~HuaffmanTreeNode(void);//默认析构函数; int GetKey();//得到该结点在正文中出现的次数 void SetKey(int key);//设置关键字的次数 Type GetData();//得到该结点对应的文字编码 void SetData(Type data);//设置结点的文字编码

HuaffmanTreeNode *GetParent();//得到该结点的双亲结点 void SetParent(HuaffmanTreeNode *p);//设置双亲结点 HuaffmanTreeNode *GetLchild();//得到左孩子结点 void SetLchild(HuaffmanTreeNode *p);//设置左孩子结点 HuaffmanTreeNode *GetRchild();//得到右孩子结点 void SetRchild(HuaffmanTreeNode *p);//设置右孩子结点 int GetTag();//得到标记 void SetTag(int t);//设置标记

HuaffmanTreeNode *GetNext();//得到下一个结点 void SetNext(HuaffmanTreeNode *p);//设置下一个结点 bool GetFlag(){ return Flag;} void SetFlag(bool tag){Flag=tag;}

27

数据结构课程设计报告

this->next =NULL; }

template

HuaffmanTreeNode::HuaffmanTreeNode(int k, Type d,int t, HuaffmanTreeNode *p = 0, this->lchild =NULL; this->rchild=NULL; this->parent =NULL; this->Flag =false;

HuaffmanTreeNode *l = 0, HuaffmanTreeNode *r = 0) { this->next =NULL; this->Key =k; this->Data =d; this->parent =p; this->lchild =l; this->rchild =r; this->Tag =t; this->Flag =false; }

template

HuaffmanTreeNode::~HuaffmanTreeNode() { }

template

int HuaffmanTreeNode::GetKey() { return this->Key ; }

template

void HuaffmanTreeNode::SetKey (int key) { this->Key =key; }

2

8 数据结构课程设计报告

template

Type HuaffmanTreeNode::GetData() { return this->Data ;

}

template

void HuaffmanTreeNode::SetData (Type data) { this->Data =data; }

template

HuaffmanTreeNode *HuaffmanTreeNode::GetParent() { return this->parent ; }

template

void HuaffmanTreeNode::SetParent(HuaffmanTreeNode *p) { this->parent =p; }

template

HuaffmanTreeNode *HuaffmanTreeNode::GetLchild() { return this->lchild ; }

template

void HuaffmanTreeNode::SetLchild(HuaffmanTreeNode *p) { this->lchild =p; }

2

9

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库哈夫曼编、译码器(6)在线全文阅读。

哈夫曼编、译码器(6).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/419863.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: