![數(shù)據(jù)結(jié)構(gòu)經(jīng)典題目c語言代碼_第1頁](http://file4.renrendoc.com/view/4f0938897cf53205cc57c2e6b52336cc/4f0938897cf53205cc57c2e6b52336cc1.gif)
![數(shù)據(jù)結(jié)構(gòu)經(jīng)典題目c語言代碼_第2頁](http://file4.renrendoc.com/view/4f0938897cf53205cc57c2e6b52336cc/4f0938897cf53205cc57c2e6b52336cc2.gif)
![數(shù)據(jù)結(jié)構(gòu)經(jīng)典題目c語言代碼_第3頁](http://file4.renrendoc.com/view/4f0938897cf53205cc57c2e6b52336cc/4f0938897cf53205cc57c2e6b52336cc3.gif)
![數(shù)據(jù)結(jié)構(gòu)經(jīng)典題目c語言代碼_第4頁](http://file4.renrendoc.com/view/4f0938897cf53205cc57c2e6b52336cc/4f0938897cf53205cc57c2e6b52336cc4.gif)
![數(shù)據(jù)結(jié)構(gòu)經(jīng)典題目c語言代碼_第5頁](http://file4.renrendoc.com/view/4f0938897cf53205cc57c2e6b52336cc/4f0938897cf53205cc57c2e6b52336cc5.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
千里之行,始于足下讓知識(shí)帶有溫度。第第2頁/共2頁精品文檔推薦數(shù)據(jù)結(jié)構(gòu)經(jīng)典題目c語言代碼《數(shù)據(jù)結(jié)構(gòu)》課程設(shè)計(jì)題目
(程序?qū)崿F(xiàn)采納C語言)
題目1:猴子選王(學(xué)時(shí):3)
一堆猴子都有編號(hào),編號(hào)是1,2,3...m,這群猴子(m個(gè))根據(jù)1-m的挨次圍坐一圈,從第1開頭數(shù),每數(shù)到第n個(gè),該猴子就要離開此圈,這樣依次下來,直到圈中只剩下最后一只猴子,則該猴子為大王。
要求:m及n要求從鍵盤輸入,存儲(chǔ)方式采納向量及鏈表兩種方式實(shí)現(xiàn)該問題求解。
//鏈表
#include
#include
//鏈表節(jié)點(diǎn)
typedefstruct_RingNode
{
intpos;
struct_RingNode*next;
}RingNode,*RingNodePtr;
//創(chuàng)建約瑟夫環(huán),pHead:鏈表頭指針,count:鏈表元素個(gè)數(shù)
voidCreateRing(RingNodePtrpHead,intcount)
{
RingNodePtrpCurr=NULL,pPrev=NULL;
inti=1;
pPrev=pHead;
while(--count>0)
{
pCurr=(RingNodePtr)malloc(sizeof(RingNode));
i++;
pCurr->pos=i;
pPrev->next=pCurr;
pPrev=pCurr;
}
pCurr->next=pHead;//構(gòu)成環(huán)狀鏈表
}
voidKickFromRing(RingNodePtrpHead,intn)
{
RingNodePtrpCurr,pPrev;
inti=1;//計(jì)數(shù)
pCurr=pPrev=pHead;
while(pCurr!=NULL)
{
if(i==n)
{
//踢出環(huán)
printf("\n%d",pCurr->pos);//顯示出圈循序
pPrev->next=pCurr->next;
free(pCurr);
pCurr=pPrev->next;
i=1;
}
pPrev=pCurr;
pCurr=pCurr->next;
if(pPrev==pCurr)
{
//最后一個(gè)
printf("\nKingis%d",pCurr->pos);//顯示出圈循序
free(pCurr);
break;
}
i++;
}
}
intmain()
{
intn=0,m=0;
RingNodePtrpHead=NULL;
printf("M(personcount)=");
scanf("%d",
printf("N(outnumber)=");
scanf("%d",
if(mpos=1;
pHead->next=NULL;
CreateRing(pHead,m);
//開頭出圈
printf("\nKickOrder:");
KickFromRing(pHead,n);
printf("\n");
system("pause");
return0;
}
//數(shù)組做:
#include
#include
#include
voidSelectKing(intMonkeyNum,intCallNum);
voidmain()
{
intMonkeyNum;
intCallNum;
/*輸入猴子的個(gè)數(shù)*/
printf("MonkeyNum=");
scanf("%d",
/*輸入M的值*/
printf("CallNum=");
scanf("%d",
SelectKing(MonkeyNum,CallNum);
}
voidSelectKing(intMonkeyNum,intCallNum)
{
int*Monkeys;//申請(qǐng)一個(gè)數(shù)組,表示全部的猴子;
intcounter=0;//計(jì)數(shù),當(dāng)計(jì)數(shù)為猴子個(gè)數(shù)時(shí)表示選到最后一個(gè)猴子了;
intposition=0;//位置,數(shù)組的下標(biāo),輪番遍歷數(shù)組舉行報(bào)數(shù);
inttoken=0;//令牌,將報(bào)數(shù)時(shí)數(shù)到M的猴子砍掉;
//申請(qǐng)猴子個(gè)數(shù)大小的數(shù)組,把桌子擺上。
Monkeys=(int*)malloc(sizeof(int)*MonkeyNum);
if(NULL==Monkeys)
{
printf("Somanymonkeys,systemerror.\n");
return;
}
//將數(shù)組的全部內(nèi)容初始化為0,被砍掉的猴子設(shè)置為1
memset(Monkeys,0,sizeof(int)*MonkeyNum);
//循環(huán),直到選中大王
while(counter!=MonkeyNum)
{
//假如這個(gè)位置的猴子之前沒有砍掉,那么報(bào)數(shù)有效
if(Monkeys[position]==0)
{
token++;//勝利報(bào)數(shù)一個(gè),令牌+1,繼續(xù)報(bào)數(shù)直到等于M
//假如報(bào)數(shù)到M,那么將這個(gè)猴子砍去
if(token==CallNum)
{
Monkeys[position]=1;//設(shè)置為1,表示砍去
counter++;//計(jì)數(shù)增強(qiáng)
token=0;//設(shè)置為0,下次重新報(bào)數(shù)
//假如是最后一個(gè)猴子,把它的位置打印,這個(gè)就是大王了
if(counter==MonkeyNum)
{
printf("Thekingisthe%dmonkey.\n",position+1);
}
}
}
//下一個(gè)猴子報(bào)數(shù)
position=(position+1)%MonkeyNum;
}
//釋放內(nèi)存,開始為全部猴子創(chuàng)建的桌子
free(Monkeys);
return;
}
題目2:字符逆轉(zhuǎn)(學(xué)時(shí):3)
從鍵盤讀入一個(gè)字符串,把它存入一個(gè)鏈表(每個(gè)結(jié)點(diǎn)存儲(chǔ)1個(gè)字符),并按相反的次序?qū)⒆址敵龅斤@示屏。
#include
#include
structnode
{
structnode*prev;
charc;
structnode*next;
};
structnode*input(structnode*top);
intmain(void)
{
structnodeT,*top=
T.prev=NULL;
T.next=NULL;
T.c='\0';
bottom=input(top);
p=bottom->prev;
while(p!=NULL)
{
printf("%c",p->c);
p=p->prev;
}
return0;
}
structnode*input(structnode*top)
{
structnode*t;
charx;
while((x=getchar())!='\n')
{
top->c=x;
t=(structnode*)malloc(sizeof(structnode));
top->next=t;
t->prev=top;
t->next=NULL;
t->c='\0';
top=top->next;
}
returntop;
}
題目3:工資核算(學(xué)時(shí):3)
設(shè)有一個(gè)單位的人員工資有如下信息:name、department、basepay、allowance、total?,F(xiàn)從鍵盤輸入一組人員工資數(shù)據(jù)并將它們存儲(chǔ)到名為paydata的文件中;再從paydata取出工資數(shù)據(jù)并給每個(gè)人的basepay增強(qiáng)100元,增強(qiáng)后將工資數(shù)據(jù)顯示于屏幕(每行1人)。
#include
#include
#defineSIZE2
#defineLENTHsizeof(structstuff)
structstuff
{
charname[100];
chardepartment[100];
intbasepay;
intallowance;
inttotal;
}stuff[SIZE];
main()
{
FILE*fp;
inti;
printf("Pleaseenternamedepartmentbasepayallowance:\n");
for(i=0;i
voidmain()
{
inta[7],b[5],c[6],d[7];
inti,j,k,t,m;
printf("\nPleaseenter7numbersofA:");
for(i=0;ia[i+1])
{t=a[i];a[i]=a[i+1];a[i+1]=t;}
printf("thesortednumbers:\n");
for(i=0;ib[i+1])
{t=b[i];b[i]=b[i+1];b[i+1]=t;}
printf("thesortednumbers:\n");
for(i=0;ic[i+1])
{t=c[i];c[i]=c[i+1];c[i+1]=t;}
printf("thesortednumbers:\n");
for(i=0;i
structPolynode
{
intcoef;
intexp;
Polynode*next;
}Polynode,*Polylist;
voidPolycreate(Polylisthead)
{
Polynode*rear,*s;
intc,e;
rear=head;printf("請(qǐng)輸入多項(xiàng)式的系數(shù)項(xiàng)和指數(shù)項(xiàng)");
scanf("%d,%d",
while(c!=0)
{
s=(Polynode*)malloc(sizeof(Polynode));
s->coef=c;
s->exp=e;
rear->next=s;
rear=s;
scanf("%d,%d",
}
rear->next=NULL;
}
voidPolyadd(Polylistpolya,Polylistpolyb)
{
Polynode*p,*q,*tail,*temp;
intsum;
p=polya->next;
q=polyb->next;
tail=polya;
while(p!=NULL
tail=p;
p=p->next;
}
elseif(p->exp=q->exp)
{
sum=p->coef+q->coef;
if(sum!=0)
{
p->coef=sum;
tail->next=p;
tail=p;
p=p->next;
temp=q;
q=q->next;
free(temp);
}
else
{
temp=p;
p=p->next;
free(temp);
q=q->next;
free(temp);
}
}
else
{
tail->next=q;
tail=q;
q=q->next;
}
}
if(p!=NULL)
tail->next=p;
else
tail->next=q;
}
voidPolysubstract(Polylistpolya,Polylistpolyb){
Polylisth=polyb;
Polylistp=pb->next;
Polylistpd;
while(p)
{p->coef*=-1;
p=p->next;
}
pd=Polyadd(pa,h);
for(p=h->next;p;p=p->next)
p->coef*=-1;
returnpd;
}
voidPrintPolyn(PolynP)
voidprintfPolyn(Polynode*head){
Polynode*p=head->next;
while(p)
{printf("%dx^%d",p->coef,p->exp);if(p->next)
printf("+");p=p->next;}
}
intmain()
{
Polynode*La,Lb;
La=Polycreate();
Lb=Polycreate();
PrintPolyn(La);
printf("/n");
PrintPolyn(Lb);
printf("/n");
Polyadd(polya,polyb);
printPolyn(polya);
return0;
}
題目6:床位分配(學(xué)時(shí):6)
某客店有N個(gè)等級(jí)的房間,第k級(jí)客房有A(k)個(gè),每個(gè)房間有B(k)個(gè)單人床,以菜單調(diào)用方式設(shè)計(jì)為單身旅客分配床位以及離店時(shí)收回床位的程序。要求分配勝利時(shí),印出旅客姓名、年齡、性別、到達(dá)日期、客房等級(jí)、房間號(hào)及床位號(hào);分配不勝利時(shí),允許更改房間等級(jí),若不更改等級(jí),印出“滿客”提醒。
#include
#include
#include
#include
#defineN3
typedefstructRoom
{
introomlevel;
introomnum;
intbednum;
intpeoplenum;
intbed[N];
intsex;
charname[10];
structRoom*next;
}Room;
Room*creat(introomlevel,introom[],intbed[])
{
Room*head,*p,*q;
inti=1,j,h,num=1;
head=(Room*)malloc(sizeof(Room));
head->peoplenum=0;
q=head;
while(iroomlevel=i;p->roomnum=num++;p->peoplenum=0;
p->sex=-1;
for(h=0;hbed[h]=0;
q->next=p;
q=p;
}
i++;
}
p->next=NULL;
return(head);
}
voidInit(Room*head)
{
Room*p;
inti;
p=head;
while(p!=NULL)
{
p->peoplenum=0;
p->sex=-1;
for(i=0;ibed[i]=0;
p=p->next;
}
printf("\n\n操作勝利\n");}
voidGetin(Room*head)
{
Room*p;
inti,s,lev,age;
charname[10];
intnumber=0;
intbednumber=0;
printf("\n\n歡迎使用訂房系統(tǒng)\n\n");
printf("請(qǐng)輸入性別(1為男,2為女):");
scanf("%d",
printf("\n\n請(qǐng)輸入想入住的房間等級(jí):");
scanf("%d",
p=head->next;
while(p!=NULL)
{
if((p->roomlevel==lev)ibed[i]==0)
{
number=p->roomnum;
bednumber=i+1;
p->bed[i]=1;
p->sex=s;
p->peoplenum++;
break;
}
if(number!=0)break;
}
p=p->next;
}
if(number==0
else
{
head->peoplenum++;
printf("\n訂單已下,請(qǐng)輸入客人信息:\n");
printf("名字:\n");scanf("%s",name);
printf("年齡:\n");scanf("%d",
printf("您的訂單3:\n");
printf("名字年齡性別到達(dá)時(shí)光房間等級(jí)房間號(hào)床位號(hào)\n");
if(s==1)
printf("%s%dmale11-19%d%d%d\n",name,age,p->roomlevel,p->roomnum,bednumber);
else
printf("%s%dformale11-19%d%d%d\n",name,age,p->roomlevel,p->roomnum,bednumber);
printf("\n");
}
}
voidCheckout(Room*head)
{
Room*p;
intnumber,bednumber,i,s;
printf("歡迎使用退房系統(tǒng):");
printf("\n\n請(qǐng)輸入房間號(hào):");
scanf("%d",
printf("\n\n請(qǐng)輸入性別(1為男,0為女):");
scanf("%d",
printf("請(qǐng)輸入床位號(hào):");
scanf("%d",
p=head->next;
while(p!=NULL)
{
if(p->roomnum==number)
for(i=0;iroomlevel;i++)
if(i+1==bednumber)
{
p->bed[i]=0;
p->peoplenum--;
if(p->peoplenumpeoplenum=0;
if(p->peoplenum==0)
p->sex=-1;
printf("您已退房,歡迎下次光臨");
break;
}
p=p->next;
}
}
voidDisplay(Room*head)
{
Room*p;
inti=0;
p=head->next;
printf("\n\n已訂房間查詢");
if(head->peoplenum==NULL)
{
printf("全部等級(jí)房間空房");
return;
}
while(p->peoplenum!=NULL)
{
if(p->sex==1)
printf("\n房間號(hào):%d,房間等級(jí):%d,已住人數(shù):%d,住房人性別:男",p->roomnum,p->roomlevel,p->peoplenum);
else
printf("\n房間號(hào):%d,房間等級(jí):%d,已住人數(shù):%d,住房人性別:女",p->roomnum,p->roomlevel,p->peoplenum);
while(ipeoplenum)
if(p->bed[i]==1)
{
printf(",已住床位號(hào):%d",i+1);
i++;
}
printf("\n");
p=p->next;
}
}
voidmain()
{
intn,k=1,i,roomlevel,room[10],bed[10],sum=0;
Room*head;
printf("請(qǐng)輸入房間等級(jí)數(shù):\n");
printf("Roomlevel:");scanf("%d",
for(i=1;i
#include
#include
typedefstructStringWord
{
charch[100];
}SW;
voidCreatTextFile()
{
charfilename[10],ch;
FILE*fp;
printf("請(qǐng)輸入所用的文件名:");
scanf("\n%s",filename);
fp=fopen(filename,"w");
printf("請(qǐng)輸入一段文字,以$號(hào)結(jié)束:\n");
scanf("%s",
while(ch!='$')
{
fwrite(
scanf("%c",
}
fclose(fp);
}
voidCountWord()
{
FILE*fp;
SWS,T;
charch;
charfilename[10];
inti=0,number=0;
printf("輸入文本文件名:");
scanf("%s",filename);
fp=fopen(filename,"r");
printf("輸入要統(tǒng)計(jì)計(jì)數(shù)的單詞:");
scanf("%s",T.ch);
while(!feof(fp))
{
ch=fgetc(fp);
if(ch=='')
{
if(i!=0)
{
S.ch[i]='\0';
i=0;
if(strcmp(S.ch,T.ch)==0)
number++;
}
}
elseif(ch=='\n')
{
if(i!=0)
{
S.ch[i]='\0';
i=0;
if(strcmp(S.ch,T.ch)==0)
number++;
}
}
else
{
S.ch[i]=ch;i++;
}
}
if(number==0)
printf("單詞不在文本中\(zhòng)n");
else
printf("單詞%s在文件%s中共浮現(xiàn)了%d次:",T.ch,filename,number);
fclose(fp);
}
voidSearchWord()
{
FILE*fp;
SWS,T;
charfilename[10];
inti,i_r,line,flag=0;
charch;
printf("\n輸入文本文件名:");
scanf("%s",filename);
fp=fopen(filename,"r");
printf("輸入要統(tǒng)計(jì)計(jì)數(shù)的單詞:");
scanf("%s",T.ch);
i=i_r=0;
line=1;
while(!feof(fp))
{
ch=fgetc(fp);
if(ch=='')
{
if(i!=0)
{
i_r++;S.ch[i]='\0';
i=0;
if(strcmp(T.ch,S.ch)==0)
{
printf("%s單詞第一次浮現(xiàn)是在%d行,%d列\(zhòng)n",T.ch,line,i_r);
flag=1;
break;
}
}
}
elseif(ch=='\n')
{
if(i!=0)
{
i_r++;S.ch[i]='\0';
if(strcmp(T.ch,S.ch)==0)
{
printf("%s單詞第一次浮現(xiàn)是在%d行,%d列\(zhòng)n",T.ch,line,i_r);
flag=1;
break;
}
i=0;i_r=0;line++;
}
else
{
line++;i_r=0;
}
}
else
{
S.ch[i]=ch;i++;}
}
if(flag==0)
printf("%s單詞不在文本中\(zhòng)n",T.ch);
fclose(fp);
}
intmain()
{
CreatTextFile();
CountWord();
SearchWord();
}
題目8:二叉樹的遍歷(學(xué)時(shí):6)
二叉樹以lson-rson鏈接方式存儲(chǔ),以菜單方式設(shè)計(jì)并完勝利能任務(wù):建立并存儲(chǔ)樹、輸出前序遍歷結(jié)果、輸出中序遍歷結(jié)果、輸出后序遍歷結(jié)果、交換左右子樹、統(tǒng)計(jì)高度,其中對(duì)于中序、后序的遍歷運(yùn)算要求采納非遞歸方式。
#include
#include
#defineM100
typedefstructnode//定義二叉樹結(jié)點(diǎn)
{
chardata;
structnode*lchild,*rchild;
}BTNode;
BTNode*CreatBTree()//創(chuàng)建二叉樹(先序遞歸)
{
charch;
BTNode*b;
scanf("%c",
if(ch=='#')//遞歸結(jié)束控制符
b=NULL;
else
{
b=(BTNode*)malloc(sizeof(BTNode));
b->data=ch;
b->lchild=CreatBTree();//遞歸先序建立左子樹
b->rchild=CreatBTree();//遞歸先序建立右子樹}
returnb;
}
voidPreOrder(BTNode*b)//遞歸先序遍歷二叉樹函數(shù)
{
if(b!=NULL)
{
printf("%c",b->data);
PreOrder(b->lchild);
PreOrder(b->rchild);
}
}
voidInOrder(BTNode*b)//非遞歸中序遍歷二叉樹函數(shù){
BTNode*stack[M],*p;
inttop=-1;
if(b!=NULL)
{
p=b;
while(top>-1||p!=NULL)
{
while(p!=NULL)//掃描p的全部左結(jié)點(diǎn)并入棧
{
top++;
stack[top]=p;
p=p->lchild;
}
if(top>-1)
{
p=stack[top];//出棧拜訪結(jié)點(diǎn)
top--;
printf("%c",p->data);
p=p->rchild;//掃描p的右結(jié)點(diǎn)
}
}
printf("\n");
}
}
voidPostOrder(BTNode*b)//非遞歸后序遍歷二叉樹函數(shù)
{
BTNode*stack[M],*p;
intsign,top=-1;
if(b!=NULL)
{
do
{
while(b!=NULL)//b全部左結(jié)點(diǎn)入棧
{
top++;
stack[top]=b;
b=b->lchild;
}
p=NULL;//p指向棧頂前一個(gè)已拜訪結(jié)點(diǎn)
sign=1;//置b為已拜訪
while(top!=-1//取出棧頂結(jié)點(diǎn)
if(b->rchild==p)//右孩子不存在或右孩子已拜訪則拜訪b
{
printf("%c",b->data);
top--;
p=b;//p指向被拜訪的結(jié)點(diǎn)
}
else
{
b=b->rchild;//b指向右孩子結(jié)點(diǎn)
sign=0;//置未拜訪標(biāo)記
}
}
}while(top!=-1);
printf("\n");
}
}
voidchange(BTNode*b)//左右子樹交換(遞歸)
{
BTNode*r;
r=(BTNode*)malloc(sizeof(BTNode));
intf1=0,f2=0;
if(b==0)return;//樹為空時(shí),跳出
if(b->lchild)
{
change(b->lchild);
r->lchild=b->lchild;
f1++;//有左子樹,符號(hào)位不為空}
if(b->rchild)
{
change(b->rchild);
r->rchild=b->rchild;
f2++;//有右子樹,符號(hào)位不為空}
if(f1==0)r->lchild=NULL;//否則,給中間變量賦空值if(f2==0)r->rchild=NULL;
if(f1||f2)
{
b->rchild=r->lchild;//左右子樹交換
b->lchild=r->rchild;
}
}
intmax(intm,intn)
{
if(m>n)
returnm;
elsereturnn;
}
intcount(BTNode*b)//計(jì)算樹高(遞歸)
{
if(b==NULL)
return0;
elsereturn(1+max(count(b->lchild),count(b->rchild)));
}
intmain()
{
BTNode*root=NULL;
printf("二叉樹的遍歷\n\n");
printf("請(qǐng)按先序遞歸挨次創(chuàng)建二叉樹(結(jié)束符#):\n");
root=CreatBTree();
printf("\n遞歸先序遍歷結(jié)果:\n");
PreOrder(root);
printf("\n非遞歸中序遍歷結(jié)果:\n");
InOrder(root);
printf("非遞歸后序遍歷結(jié)果:\n");
PostOrder(root);
printf("\n樹高:%d\n",count(root));
printf("\n左右子樹交換位置:");
change(root);
printf("\n遞歸先序遍歷結(jié)果:\n");
PreOrder(root);
printf("\n非遞歸中序遍歷結(jié)果:\n");
InOrder(root);
printf("非遞歸后序遍歷結(jié)果:\n");
PostOrder(root);
return0;
題目9:創(chuàng)建二叉排序樹(學(xué)時(shí):3)
二叉排序樹以lson-rson鏈接方式存儲(chǔ),編寫能夠通過鍵盤輸入建立二叉排序樹,并在建立完立刻在屏幕顯示中序遍歷結(jié)果的程序。
#include
#include
typedefstructnode
{
intdata;
structnode*lchild,*rchild;
}BSTNode,*BSTTree;
//二叉排序樹的插入(遞歸算法)
voidInsertBST(BSTTree*BST,intkey)
{
if((*BST)==NULL)
{
(*BST)=(BSTNode*)malloc(sizeof(BSTNode));
(*BST)->data=key;
(*BST)->lchild=NULL;
(*BST)->rchild=NULL;
}
elseif((*BST)->data>key)//假如待插入的元素比根結(jié)點(diǎn)元素值小InsertBST(//插入在根結(jié)點(diǎn)的左子樹else
InsertBST(//插入在根結(jié)點(diǎn)的右子樹上}
//創(chuàng)建一棵二叉排序樹
BSTTreeCreateBSTTree()
{
BSTTreebst=NULL;
intx;
while(1)
{
scanf("%d",
if(x==00)break;
InsertBST(
}
returnbst;
}
//中序遍歷
voidInOrder(BSTTreeBST)
{
if(BST!=NULL)
{
InOrder(BST->lchild);
printf("%5d",BST->data);
InOrder(BST->rchild);
}
}
voidmain()
{
BSTTreeBST;
printf("建立二叉排序樹,請(qǐng)輸入序列:\n");
BST=CreateBSTTree();
printf("中序遍歷后輸出的該序列為:");
InOrder(BST);
printf("\n");
}
題目10:霍夫曼編碼應(yīng)用(學(xué)時(shí):3)
假設(shè)一串由大寫字母構(gòu)成的電文,采納霍夫曼規(guī)章對(duì)其舉行編碼,以菜單方式設(shè)計(jì)并完勝利能任務(wù):建立霍夫曼樹、霍夫曼編碼生成、編碼文件譯碼。
#include
#include
#include
#definen100
#definem2*n-1
typedefstruct
{
intweight;
charch;
intparent,lchild,rchild;
}HTNode;
typedefstruct{
charch;
charbits[n+1];
}CodeNode;
typedefstruct
{
charcha;
intnumber;
}COUNTER;
intInit(HTNodeht[])//初始化函數(shù),為每一個(gè)字母信息賦權(quán)值{
inti,s=1;
COUNTERcounter[27];
charch;
printf("請(qǐng)輸入字符:\n");
scanf("%c",
counter[1].cha='A';
counter[2].cha='B';
counter[3].cha='C';
counter[4].cha='D';
counter[5].cha='E';
counter[6].cha='F';
counter[7].cha='G';counter[8].cha='H';counter[9].cha='I';counter[10].cha='J';counter[11].cha='K';counter[12].cha='L';counter[13].cha='M';counter[14].cha='N';counter[15].cha='O';counter[16].cha='P';counter[17].cha='Q';counter[18].cha='R';counter[19].cha='S';counter[20].cha='T';counter[21].cha='U';counter[22].cha='V';counter[23].cha='W';counter[24].cha='X';counter[25].cha='Y';counter[26].cha='Z';
for(i=1;iy)
{
*p1=y;
*p2=x;
}
else
{
*p1=x;
*p2=y;
}
}
voidhuffman_setup(HTNodeht[],ints){
inti,a;
intp1,p2;
a=2*s-1;
for(i=1;i%s\n",hc[i].ch,hc[i].bits);
}
while(flag)
{
printf("請(qǐng)輸入您想要舉行的操作:\n1編碼\n2解碼\n3退出\n");
fflush(stdin);
scanf("%d",
switch(choice)
{
case1:
huffman_code(hc);
printf("\n");
break;
case2:
huffman_read(ht,s);
printf("\n");
break;
case3:
flag=0;
}
}
return0;
}
題目11:關(guān)鍵路徑尋覓(學(xué)時(shí):6)
對(duì)于給定的一個(gè)工程施工圖,該圖以邊為單位從鍵盤輸入,編寫能夠找出該圖的關(guān)鍵路徑的程序。
#include
#include
structNode//鄰接點(diǎn)
{
intvex;//頂點(diǎn)信息
intweight;//權(quán)值
structNode*next;
};
structHnode//頭結(jié)點(diǎn)
{
intvex2;
intid;//入度
structNode*link;
}A[20];
voidcreate(structHnodeA[20],intn,inte){
inti,j,k,l;
structNode*p;
for(i=1;ivex=j;
p->weight=l;
p->next=A[i].link;
A[i].link=p;
}
for(i=1;ivex;
A[k].id=A[k].id+1;
p=p->next;
}
}
}
voidfind(structHnodeA[20],intn)
{
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 日文版勞動(dòng)合同
- 游戲開發(fā)引擎授權(quán)使用及技術(shù)支持服務(wù)協(xié)議
- 三字經(jīng)學(xué)習(xí)感悟
- Oleic-acid-Standard-生命科學(xué)試劑-MCE
- 小學(xué)生經(jīng)典國學(xué)啟蒙讀后感
- 2-2-Dibutylpropane-1-3-diol-生命科學(xué)試劑-MCE
- 年終團(tuán)隊(duì)建設(shè)活動(dòng)安排
- 年度銷售部門工作總結(jié)報(bào)告新趨勢(shì)與成效分析
- 公司融資計(jì)劃及投資策略分析
- 試用期員工勞動(dòng)合同
- 2025年工貿(mào)企業(yè)春節(jié)復(fù)工復(fù)產(chǎn)方案
- 【道法】歷久彌新的思想理念課件 2024-2025學(xué)年統(tǒng)編版道德與法治七年級(jí)下冊(cè)
- 民辦中學(xué)班主任工作考核細(xì)則
- 2024年初三數(shù)學(xué)競(jìng)賽考試試題
- 物業(yè)保潔員培訓(xùn)專業(yè)課件
- 飲品店操作流程圖
- 風(fēng)居住的街道鋼琴二胡合奏譜
- 六年級(jí)《我的夢(mèng)想》作文指導(dǎo)(課堂PPT)
- PADS元件封裝制作規(guī)范要點(diǎn)
- 膠水行業(yè)中最常用的英文術(shù)語
- citrix桌面虛擬化平臺(tái)健康檢查指南10
評(píng)論
0/150
提交評(píng)論