数据结构作业Word下载.docx
- 文档编号:4757650
- 上传时间:2023-05-04
- 格式:DOCX
- 页数:16
- 大小:196.72KB
数据结构作业Word下载.docx
《数据结构作业Word下载.docx》由会员分享,可在线阅读,更多相关《数据结构作业Word下载.docx(16页珍藏版)》请在冰点文库上搜索。
BTrees[10];
inttop;
}St;
intCreate_Pre(BTree&
T);
BTreePop(St*&
S);
BTreePush(St*&
BTreegetTop(St*&
BTreeexchange(BTree&
boolcheck(char*&
input);
/**非递归前序遍历***/
boolTraPre(BTree&
/***非递归中序遍历**/
boolTraMid(BTree&
/**非递归后序遍历***/
boolTraPost(BTree&
/***递归前序遍历**/
voidTraPre_re(BTree&
/**递归中序遍历***/
voidTraMid_re(BTree&
/**递归后序遍历***/
voidTraPost_re(BTree&
TraPre_re(t);
\nMiddleTraverse\n"
TraMid(t);
\nPostTraverse\n"
TraPost_re(t);
S){
if(S->
top==0)
returnNULL;
returnS->
s[S->
top-1];
input){
intpause=0,ch=0;
inti=0;
while(input[i]){
i++;
if(input[i]=='
@'
){
pause++;
continue;
}
ch++;
if(ch!
=pause)
returnfalse;
returntrue;
s[--S->
top];
S,BTreee){
top++]=e;
T){
St*st;
char*str=(char*)malloc(sizeof(char)*40);
inti=1;
boolisCreateR=false;
BTreepop,temp;
st=(St*)calloc(sizeof(St),1);
st->
top=0;
Inputastringwithpreorder(endwith'
*'
):
\n"
gets(str);
//check()函数检查输入的数据是否正确
check(str)){
ERROR!
!
return0;
if(str[0]=='
&
st->
top==0){
T=NULL;
T=(BTree)calloc(sizeof(treeNode),1);
T->
E=str[0];
Push(st,T);
while(str[i]!
='
if(str[i]=='
//终端节点=度为2的节点+1
if(st->
top==0){
creatingsuccess!
"
return1;
pop=Pop(st);
isCreateR=true;
//st->
s[--st->
top]->
Lchild==NULL;
}else{
temp=(BTree)calloc(sizeof(treeNode),1);
temp->
E=str[i];
if(isCreateR){
pop->
Rchild=temp;
Push(st,temp);
isCreateR=false;
s[st->
top-1]->
Lchild=temp;
error!
St*st=(St*)malloc(sizeof(St));
BTreepop=T;
while(pop){
%c\t"
pop->
E);
if(pop->
Rchild)
Push(st,pop->
Rchild);
Lchild)
pop=pop->
Lchild;
else{
pop=Pop(st);
T)
while(pop||st->
top){
Push(st,pop);
Rchild;
boolisOut=false;
if(isOut){
isOut=false;
getTop(st))
break;
if(pop==getTop(st)->
isOut=true;
else
pop=getTop(st)->
if(pop){
pop){
/*
递归交换左右子树
*/
BTreetemp=NULL;
if(T->
Lchild||T->
Rchild){
Lchild){
temp=T->
Rchild=exchange(T->
Lchild);
if(temp){
Lchild=exchange(temp);
Lchild=NULL;
returnT;
if(T){
T->
TraPre_re(T->
TraMid_re(T->
TraPost_re(T->
过程:
stack"
#defineMAX32000
typedefstructhtNode{
intweight;
intLchild,Rchild,parent;
}HtNode,*HT;
boolHuffmanCoding(HT&
H);
intInput(HT&
h);
HTh;
HuffmanCoding(h);
int**Traverse(intn,HT&
h){
inti,j,q,l;
intnum=0;
int**t=(int**)malloc(sizeof(int*)*n);
for(i=0;
i<
n;
i++)
t[i]=(int*)calloc(sizeof(int),(n+1));
i++){
//printf("
%c\t------:
h[i].E);
j=i;
q=1;
num=0;
while(h[j].parent!
=0){
if(h[h[j].parent].Lchild==j)
t[i][q++]=1;
t[i][q++]=2;
j=h[j].parent;
num++;
t[i][0]=num;
returnt;
intn,i;
inputthenumberofdata:
scanf("
%d"
&
n);
Element\tWeight\n"
h=(HtNode*)calloc(sizeof(HtNode),(2*n-1));
getchar();
%c,%d"
h[i].E,&
h[i].weight);
h[i].Lchild=-1;
//printf("
%d\n"
i);
returnn;
H){
intMinb,Mins,i,j=0;
intsum,s=0,b=0;
intn=Input(H);
int**T;
for(i=n;
2*n-1;
Mins=MAX,s=i-1;
Minb=MAX,b=i-1;
j=0;
while(j<
i){
if(Mins>
=H[j].weight&
H[j].parent==0)
Mins=H[j].weight,s=j;
j++;
H[i].Lchild=s;
H[s].parent=i;
if(Minb>
Minb=H[j].weight,b=j;
sum=Mins+Minb;
H[i].weight=sum;
H[i].Rchild=b;
H[b].parent=i;
T=Traverse(n,H);
inttemp,h;
j=T[i][0];
for(temp=1;
temp<
=j/2;
temp++){
h=T[i][temp];
T[i][temp]=T[i][j-temp+1];
T[i][j-temp+1]=h;
前缀编码是:
j=1;
%c:
\t"
H[i].E);
while(T[i][j]==1||T[i][j]==2)
%d\t"
T[i][j]-1),j++;
结果:
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 作业