數(shù)據(jù)結(jié)構(gòu)與算法實(shí)驗(yàn)指導(dǎo)書(shū)_第1頁(yè)
數(shù)據(jù)結(jié)構(gòu)與算法實(shí)驗(yàn)指導(dǎo)書(shū)_第2頁(yè)
數(shù)據(jù)結(jié)構(gòu)與算法實(shí)驗(yàn)指導(dǎo)書(shū)_第3頁(yè)
已閱讀5頁(yè),還剩45頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、數(shù)據(jù)結(jié)構(gòu)與算法實(shí)驗(yàn)報(bào)告綦娜娜 編哈爾濱理工大學(xué)榮成學(xué)院實(shí)驗(yàn)一順序表的實(shí)現(xiàn)和應(yīng)用一、實(shí)驗(yàn)?zāi)康?、 掌握順序表的定義;2、 掌握順序表的基本操作,如查找、插入、刪除及排序等。二、實(shí)驗(yàn)內(nèi)容1、 編寫(xiě)函數(shù),實(shí)現(xiàn)在順序表中查找值為x的元素的位置的簡(jiǎn)單順序查找算法,編寫(xiě)主函數(shù)驗(yàn)證此算法,并分析算法的時(shí)間復(fù)雜度2、 編寫(xiě)函數(shù),實(shí)現(xiàn)在順序表中刪除第i個(gè)位置上的元素,編寫(xiě)主函數(shù)驗(yàn)證此算法,并 分析算法的時(shí)間復(fù)雜度3、 編寫(xiě)函數(shù),實(shí)現(xiàn)在順序表中第i個(gè)位置上插入值為x的元素,編寫(xiě)主函數(shù)驗(yàn)證此算法,并分析算法的時(shí)間復(fù)雜度4、 編寫(xiě)函數(shù),實(shí)現(xiàn)在順序表中將所有偶數(shù)排在所有奇數(shù)前面,編寫(xiě)主函數(shù)驗(yàn)證此算 法,并分析算法的時(shí)間

2、復(fù)雜度三、實(shí)驗(yàn)提示1、#inelude <stdio.h>#define MAXSIZE 20typedef structint dataMAXSIZE;int last;list;/*編寫(xiě)函數(shù),實(shí)現(xiàn)在順序表中查找值為x的元素的位置的簡(jiǎn)單順序查找算法,編寫(xiě)主函數(shù)驗(yàn)證此算法,并分析算法的時(shí)間復(fù)雜度*/in t locate(list *l,i nt x)/代碼int i;for(i=0;i<l_>last;i+) if(l->datai=x)return i+1;return -1;main ()list b;int x,i,p;b.last=10;for(i=0;

3、i<b.last;i+)b.datai=i+2;printf("請(qǐng)輸入x的值:”);scan f("%d",& x);p=locate(&b,x);if(p=-1)prin tf(" no!");elseprin tf("positi on=%dn",p);請(qǐng)蒯人藍(lán)的值:5position4Press any key to contintue請(qǐng)輸人藍(lán)的值:100;no! Press any key to continue.時(shí)間復(fù)雜度T(n)=O(n);2、#inelude<stdio.h>#

4、define MAXSIZE 20typedef structint dataMAXSIZE;int last;list;/*編寫(xiě)函數(shù),實(shí)現(xiàn)在順序表中刪除第 i個(gè)位置上的元素,編寫(xiě)主函數(shù)驗(yàn)證此算法,并分析算法的時(shí)間復(fù)雜度*/int delete(list *l,int i)int j,k,p;II定義一個(gè)用來(lái)保存被刪原素;if(i>=0&&i<l->last)II只接受有效輸入for( j=O;j<l->last;j+)/ 遍歷數(shù)組if(j=i-1)/ 匹配p=l->dataj; II保存被刪原素;for(k=j;k<l->las

5、t;k+) II 前進(jìn)一位;l->datak=l->datak+1;break;II退出循環(huán)l->last=l->last-1;return p;II對(duì)于此題來(lái)說(shuō)可以輸出p;return 0;main ()list b;int x,i;b.last=10;for(i=0;i<b.last;i+)b.datai=i+2;printf("請(qǐng)輸入x的值:”); scan f("%d",& x);if(delete(&b,x)!=O)for(i=0;i<b .l ast;i+)prin tf("%3d"

6、;,b.datai);elseprin tf("Error!");幘嶽心的庫(kù)52345789 10 UPress any key to can ti nue/時(shí)間復(fù)雜度T(n)=O(n);3、#include<stdio.h>#defi ne MAXSIZE 20 typedef structint dataMAXSIZE;int last;list;/*編寫(xiě)函數(shù),實(shí)現(xiàn)在順序表中第i個(gè)位置上插入值為x的元素,編寫(xiě)主函數(shù)驗(yàn)證此算法,并分析算法的時(shí)間復(fù)雜度*/int in sert(list *l,i nt x,i nt i)int j,k;if(i<=l-&

7、gt;last+1 &&i>0)if(i=l->last+1)/特殊值last+1要插入到整個(gè)數(shù)組之后l->datal->last=x;elsefor( j=0;j<l->last;j+)if(j=i-1)/ 匹配for(k=l->last;k>j;k-)/將所選插入位置之后原素后移l->datak=l->datak-1;l->data j=x;/把x賦值給所選位置break;l->last=l->last+1;/ 數(shù)值長(zhǎng)度加一return 1;return 0;/無(wú)效位置main ()list b;

8、int x,i;b.last=10;for(i=0;i<b.l ast;i+)b.datai=i+2;printf("請(qǐng)輸入x的值:”);scan f("%d",& x);if(in sert(&b,66,x)!=0)for(i=0;i<b .l ast;i+)prin tf("%3d",b.datai); elseprin tf("Error!");請(qǐng)輸入丫的值=52 3 4 5 66 6 789 10 llPress any key to continue/時(shí)間復(fù)雜度T(n)=O(n);#in

9、 elude<stdio.h>#defi ne MAXSIZE 20typedef structint dataMAXSIZE;int last;list;/*編寫(xiě)函數(shù),實(shí)現(xiàn)在順序表中將所有偶數(shù)排在所有奇數(shù)前面,編寫(xiě)主函數(shù)驗(yàn)證此算法并分析算法的時(shí)間復(fù)雜度*/void fun( list *l)/這個(gè)代碼有點(diǎn)晦澀,但空間時(shí)間復(fù)雜度是雞兒低int i,ou=0,temp;/i計(jì)數(shù),ou代表偶數(shù)個(gè)數(shù)OUfor(i=0;i<l_>last;i+)if(l->datai%2=0)個(gè)位置的原素交換位置temp=l->dataou;l->dataou=l->d

10、atai;l->datai=temp;ou+=1;/循環(huán)/判斷是不是偶數(shù),如果:偶數(shù)的話和當(dāng)前第/偶數(shù)個(gè)數(shù)加一printf("當(dāng)前數(shù)組中偶數(shù)有%d個(gè),奇數(shù)有%d個(gè):n",ou,l->last-ou);main () list b;int i=0,m=0;b.last=10;printf("請(qǐng)輸入數(shù)組元素的值:n");for(i=0;i<b.l ast;i+)prin tf("b.data%d=",i);scan f("%d", &b.datai);fun(&b);for(i=0;i

11、<b.last;i+)prin tf("%3d",b.datai);N青輸人數(shù)組兀素的荷:L, datab, dataib, data2b. data3=4ba dnt良4=5b- data5=6b. data=7b. dataT=Sb. data8=9b. datag=10二Hi 駅:且中偶數(shù)有5個(gè),奇數(shù)有5個(gè):2 468 103 719 SPres旦 any key to】 continue/時(shí)間復(fù)雜度為T(mén)(n)=0(n);四、實(shí)驗(yàn)報(bào)告要求1、撰寫(xiě)實(shí)驗(yàn)報(bào)告;2、對(duì)實(shí)驗(yàn)中出現(xiàn)的問(wèn)題和結(jié)果進(jìn)行總結(jié)實(shí)驗(yàn)二 鏈表的實(shí)現(xiàn)和應(yīng)用一、實(shí)驗(yàn)?zāi)康?、掌握鏈表的定義;2、 掌握鏈表的

12、基本操作,如查找、插入、刪除、排序等。二、實(shí)驗(yàn)內(nèi)容1、單鏈表的創(chuàng)建2、單鏈表的查找3、單鏈表的排序4、單鏈表的刪除5、鏈表的應(yīng)用-約瑟夫環(huán)問(wèn)題三、實(shí)驗(yàn)提示1、/創(chuàng)建單鏈表,要求:結(jié)點(diǎn)個(gè)數(shù)為n個(gè),每個(gè)節(jié)點(diǎn)數(shù)據(jù)域的值必須小于m。編輯主函數(shù)驗(yàn)證之。#i nclude <stdio.h>#i nclude <stdlib.h>typedef struct aa int data;struct aa *n ext; NODE;NODE *Creatli nk(i ntn, i nt m)int i;NODE *tou,*p;tou 頭結(jié)點(diǎn)tou=(NODE*)malloc(siz

13、eof(NODE);/ 創(chuàng)建并初始化頭結(jié)點(diǎn)tou-> next=NULL;tou->data=n;printf("請(qǐng)輸入%d個(gè)小魚(yú)%d的數(shù),中間用空格隔開(kāi):n",n,m);for(i=0;i<n;i+)/ 頭插法p=(NODE*)malloc(sizeof(NODE);scan f("%d",& p->data);if(p->data>=m)printf("輸入的第%d個(gè)數(shù)據(jù)大于 %d,GGn",i+1,m);好像是在頭文件exit(0);/程序強(qiáng)制中斷,stdlib.h 里p->n

14、ext=tou->n ext; tou->n ext=p;return tou;outli nk(NODE *h) NODE *p;p=h->n ext;prin tf("nn THELIST :nnHEAD ”);while(p) prin tf("->%d ”,p->data); p=p->n ext;prin tf("n ”);main () NODE *head;head=Creatli nk(8,22);outl in k(head);1 2345678pHE LIST :HEAD ->8 ->7 ->

15、;6 ->5 ->4 ->3 ->2 ->1 Press any key to uontinu匚1 2 3 100 5 6 7 8綁入的第4個(gè)數(shù)據(jù)大于22:GGPress any ksy to continue2、/查找值為ch的節(jié)點(diǎn)在鏈表中是否出現(xiàn),如果存在,返回在鏈表中位序,如果不存 在返回0<stdio.h><stdlib.h>#in clude#in clude#defi neN 8typedef struct list int data;struct list*n ext; SLIST;SLIST *creatlist(char

16、*);void outlist(SLIST *);int fun( SLIST *h, char ch)int i;SLIST *p;p=h->next;/p賦值為壽元節(jié)點(diǎn)for(i=0;i<N;i+)if(p->data=ch)return i+1;p=p->n ext;return 0;main () SLIST *head;int k;char ch;char aN='m','p','g','a','w','x','r','d'head=

17、creatlist(a);outlist(head);prin tf("E nter a letter:");scan f("%c",&ch);k=fu n( head,ch);if (k=0)prin tf("nNot fou nd!n");elseprin tf("The seque nee nu mber is :%dn ”,k);SLIST *creatlist(char *a)int i;SLIST *tou,*p;tou=(SLIST*)malloc(sizeof(SLIST); / 創(chuàng)建并初始化頭結(jié)點(diǎn)

18、tou->data=N;tou-> next=NULL;for(i=0;i<N;i+)/ 前叉法p=(SLIST*)malloc(sizeof(SLIST);p_>data=ai;p->n ext=tou->n ext;tou->n ext=p;return tou;void outlist(SLIST *h) SLIST *p;p=h->n ext;if (p=NULL) prin tf("nThe list is NULL!'n ”); else prin tf("nH ead");p=p->n e

19、xt;do prin tf("->%c",p->data);while(p!=NULL); prin tf("->E ndin ”);Headj>dj>r->x->w->a->g->p->m->End a lmtter :gThe sequence nuiriber is :6Prsss any key to continue.五代丑a letter:zNot found!prems 技ny key t口 c口ntinu白3、/去偶操作,鏈表中各節(jié)點(diǎn)按數(shù)據(jù)域遞增有序鏈接,函數(shù)fun的功能是,刪

20、除鏈表中 數(shù)據(jù)域值相同的節(jié)點(diǎn),使之只保留一個(gè)#in clude<stdio.h>#in clude<stdlib.h>#defi neN8typedefstruct list intdata;struct list*n ext; SLIST;void fun( SLIST *h)SLIST *p,*sha nchu;/用于遍歷的指針 p,用于刪除的指針shanchup=h->n ext;/p為壽元節(jié)點(diǎn)while(p-> next!=NULL)/終止條件if(p->data=p->n ext->data)/判斷是否有重復(fù)原素sha nchu=

21、p->n ext;p->n ext=sha nchu->n ext; free(sha nchu); elsep=p->n ext;SLIST *creatlist(i nt *a) SLIST *h,*p,*q;int i;h=p=(SLIST *)malloc(sizeof(SLIST);for(i=0; i<N; i+) q=(SLIST *)malloc(sizeof(SLIST); q->data=ai;p_>n ext=q;p=q;p_>n ext=0;return h;void outlist(SLIST *h) SLIST *p;

22、p=h->n ext;if (p=NULL)prin tf("nThe list is NULL!'n ”);else prin tf("nHead");p=p->n ext; while(p!=NULL);do prin tf("->%d",p->data);prin tf("->E nd'n");mai n()SLIST *head;int aN=1,2,2,3,4,4,4,5;head=creatlist(a);printf("nThe list before d

23、eleting :n");outlist(head);fun( head);printf("nThe list after deleting :n");outlist(head);4、/在ma in函數(shù)中多次調(diào)用fun函數(shù),每調(diào)用一次fun函數(shù),輸出鏈表尾部節(jié)點(diǎn)中的 數(shù)據(jù),并釋放該節(jié)點(diǎn),使得鏈表縮短。#i nclude<stdio.h>#i nclude<stdlib.h>#define N 8typedef struct list int data;struct list *n ext; SLIST;void fun( SLIST *p)

24、SLIST *bianli,*shanchu;/ 遍歷,刪除bia nli=p;while(bia nl i-> next-next!=NULL)bia nli=bia nli->n ext;/輸出/釋放prin tf("%d",bia nl i-> next->data);sha nchu=bia nl i->n ext;free(sha nchu);bia nli-> next=NULL;SLIST *creatlist(i nt*a) SLIST *h,*p,*q;int i;h=p=(SLIST *)malloc(sizeof(S

25、LIST); for(i=0; i<N; i+) q=(SLIST *)malloc(sizeof(SLIST); q->data=ai; p_>n ext=q; p=q;p_>n ext=0;return h;void outlist(SLIST *h) SLIST *p;p=h->n ext;if (p=NULL) prin tf("nThe list is NULL!'n ”);else prin tf("nHead");do prin tf("->%d",p->data);p=p->

26、; next; while(p!=NULL);prin tf("->E ndn");main () SLIST *head;int aN=11,12,15,18,19,22,25,29;head=creatlist(a);prin tf("nO utput from head:' n");outlist(head);prin tf("nO utput from tail: n ”);while (head-> next != NULL)fun( head);prin tf("nn");prin tf(&q

27、uot;nO utput from head aga in :n");outlist(head);Output from head:Head->ll->12->15->18->19->22->25->29->EndOutput froBn t®il:29Output from head 也刖in :Hlsad->11->12->15-> 18-> 19->22->25->End25Output froon head again :Head->11->12->

28、;15->18->19->22->End22Output from h呂宣日 again :Head->11->12->15->18->19->Bnd19Output from head iftgain :Head->ll->12->15->18->RndISOutput from head again :Hyad->ll->12->15->End15Ou.tj>ut from head aigain :|Hgid->ll->L2->EndOutput fr

29、om head again :Read->U->12->End12Output from head again :Head->K->End11Output from head again :The list is NULL!Press any key to continue,5、實(shí)現(xiàn)約瑟夫環(huán)函數(shù)(選做)#in elude<stdio.h>#in elude<stdlib.h>typedef struct list int data;struct list*n ext; SLIST;SLIST *creatlist(int m)int i;S

30、LIST *tou,*p,*wei;/頭指針 生成節(jié)點(diǎn)指針 尾指針tou=(SLIST*)malloc(sizeof(SLIST); / 頭節(jié)點(diǎn)wei=tou;printf("請(qǐng)輸入%d個(gè)數(shù)用空格隔開(kāi):n”,m);for(i=0;i<m;i+)/ 尾插法p=(SLIST*)malloc(sizeof(SLIST);scan f("%d",& p->data);wei->n ext=p;wei=p;wei->next=tou->next;/令最后一個(gè)原素指向首元結(jié)點(diǎn)成環(huán)return tou;void outlist(SLIST

31、*h,i nt m,i nt c)int i;SLIST *p,*shanchu;/用于遍歷的指針p,用于刪除的指針shanchup=h->n ext;while(p!=p-> next)for(i=1;i<c-1;i+)p=p->n ext;sha nchu=p->n ext;printf("%d ",shanchu->data); p->n ext=sha nchu->n ext; free(sha nchu);p=p->n ext;prin tf("%d",p->data);free(p)

32、;free(h);mai n() SLIST *head;int m,c;printf("請(qǐng)分別輸入 m和c的值/p指向首元結(jié)點(diǎn)/當(dāng)環(huán)中只剩下一個(gè)原素時(shí)結(jié)束/根據(jù)輸入的c剔除節(jié)點(diǎn)/sha nchu指向當(dāng)前要剔除的節(jié)點(diǎn)II將shanchu指針指向的節(jié)點(diǎn)出環(huán)/輸出最后的一個(gè)節(jié)點(diǎn)的內(nèi)容");scan f("%d,%d",&m,&c);head=creatlist(m);outlist(head,m,c);四、實(shí)驗(yàn)報(bào)告要求1、撰寫(xiě)實(shí)驗(yàn)報(bào)告;2、對(duì)實(shí)驗(yàn)中出現(xiàn)的問(wèn)題和結(jié)果進(jìn)行總結(jié)實(shí)驗(yàn)三 棧的實(shí)現(xiàn)和應(yīng)用一、實(shí)驗(yàn)?zāi)康?、掌握棧的建立方法;2、掌握棧的基本

33、操作,如入棧、出棧、判斷空棧等;3、棧的應(yīng)用。二、實(shí)驗(yàn)內(nèi)容1、順序棧的初始化2、判斷棧是否為空3、順序棧出棧4、順序棧入棧5、棧的應(yīng)用-漢諾塔三、實(shí)驗(yàn)提示1、棧的基本操作,按提示將函數(shù)補(bǔ)充完整 #i nclude <stdio.h>#i nclude <stdlib.h>#defi ne STACK_MAX 100typedef structint top;int dataSTACK_MAX; stack;void init(stack *st) /*初始化順序棧 */st->top=0;int Empty(stack *st)/*if(st_>top=0)

34、return 0;elsereturn 1;判斷棧是否為空*/空0/非空1int pop(stack *st)/* 出棧 */retur n st->data-st->top; void push(stack *st,int data) /* 入棧 */ st->datast->top+=data;int main( void)stack st;init(&st);push(&st,5);push(&st,6);prin tf("%d",pop(&st);return 0;6Press any key to conti

35、nue2、#inelude <stdio.h>void mai n()void hanoi(int n, char on e,ehar two,ehar three);/*對(duì)hanoi函數(shù)的聲明 */int m;prin tf("i nput the nu mber of diskes:");scan f("%d", &m);prin tf("The step to move ing %d diskes:n",m);han oi(m,'A','B','C');void

36、 hanoi(int n, char on e,char two,char three)/* 定義hanoi函數(shù)將n個(gè)盤(pán)從one座借助two座,移到three座*/static k=1;II疋義靜態(tài)變量k用來(lái)標(biāo)明走了多少步void move(char x,char y);II因?yàn)閙ove函數(shù)定義在該函數(shù)的后邊且之前咩有聲明在此需要提前聲明才能使用if(n=1)II當(dāng)?shù)谝粋€(gè)座上僅剩一個(gè)盤(pán)的時(shí)候?qū)⒋吮P(pán)移到第三個(gè)上printf(” 第 %d 步:",k+);move(on e,three);elsehanoi(n-1, on e,three,two);座當(dāng)橋梁printf("第

37、%d 步:",k+);move(on e,three);hanoi(n-1,two ,on e,three);上,第一個(gè)盤(pán)當(dāng)橋梁/輸出是第多少步/移動(dòng)II將前n-1個(gè)盤(pán)從第一個(gè)座移到二個(gè)座上,第三個(gè)/將上邊轉(zhuǎn)移到第二個(gè)座上的盤(pán)轉(zhuǎn)移到第三個(gè)盤(pán)I*定義move函數(shù)*Ivoid move(char x,char y)prin tf("%c->%c n",x,y);input the number of diskes:4第1步 義車(chē) 第4步 筆5步 裁參 第了步The step to moveing 4 diskes: A>BA>CB>CA>

38、B C>AC>BA>BA>C步:A>B :A->C :B>C_ BX 第 16 步:B>A 第11 步:C>A 第>CPress any key to continue四、實(shí)驗(yàn)報(bào)告要求1、撰寫(xiě)實(shí)驗(yàn)報(bào)告;2、對(duì)實(shí)驗(yàn)中出現(xiàn)的問(wèn)題和結(jié)果進(jìn)行總結(jié)實(shí)驗(yàn)四隊(duì)列的實(shí)現(xiàn)和應(yīng)用一、實(shí)驗(yàn)?zāi)康?、掌握隊(duì)列的建立方法;2、 掌握隊(duì)列的基本操作,如出隊(duì)、入隊(duì)、判斷隊(duì)空等;3、隊(duì)列的應(yīng)用。二、實(shí)驗(yàn)內(nèi)容1、順序隊(duì)列的初始化2、判斷隊(duì)列是否為空3、順序隊(duì)列出隊(duì)4、順序隊(duì)列入隊(duì)5、隊(duì)列的應(yīng)用-回文判斷三、實(shí)驗(yàn)提示1、/隊(duì)列的基本操作,按提示將函數(shù)補(bǔ)充完整#i nclu

39、de <stdio.h>#i nclude <stdlib.h>#defi ne STACK_MAX 100 typedef structint front, rear;int data1STACK_MAX; Queue;void initQueue (Queue *q) /*初始化隊(duì)列 */q_>fron t=q_>rear=O;int EmptyQueue(Queue *q)/* 判斷隊(duì)列空 */if(q->fron t=q->rear)return 1;/1 代表空elsereturn 0;/0代表非空int DeQueue(Queue *

40、q)/* 出隊(duì)列 */if(q->rear=q->fr ont)/判斷需要出隊(duì)時(shí)隊(duì)列是否為空printf("當(dāng)前隊(duì)列已經(jīng)空了 。");exit(O);elsereturn q->data1q->front+;/將隊(duì)頭原素出列然后隊(duì)頭指針加一void InQueue(Queue *q,int data)/* 入隊(duì)列 */if(q->rear=STACK_MAX)/判斷需要入隊(duì)時(shí)隊(duì)列是否已滿(mǎn)printf(”當(dāng)前隊(duì)列空間已滿(mǎn)。");exit(O);elseq->data1q->rear=data;/ 入隊(duì)q->rear+;

41、int mai n()Queue q;in itQueue( &q);In Queue(&q,1);In Queue(&q,2);In Queue(&q,3);prin tf("%dn",DeQueue(&q);prin tf("%dn",DeQueue( &q);prin tf("%dn",DeQueue(&q);i:ress any key to continue2、/判斷給定的字符序列是否是回文(提示:將一半字符入棧)#i nclude <stdio.h>#i

42、nclude <stdlib.h>#defi ne STACK_MAX 100typedef structint top;int dataSTACK_MAX; stack;typedef structint front, rear;int data1STACK_MAX; Queue;void in it(stack *st) /*st->top=0;int Empty(stack *st)/*if(st_>top=0) return 1;elsereturn 0;int pop(stack *st)if(st->top=0)else初始化順序棧*/判斷棧空*/*出

43、棧*/printf("棧已空!");exit(0);char c;c=st_>data_st_>top;return(int) c;void push(stack *st,int data) /* 入棧 */if(st->top=STACK_MAX-1)printf("棧已空!");exit(O);elsest->datast->top+=data;void initQueue (Queue *q) /*初始化隊(duì)列 */q_>fron t=q_>rear=O;int EmptyQueue(Queue *q)/*判

44、斷隊(duì)列空 */if(q->fron t=q_>rear)return 1;elsereturn 0;int DeQueue(Queue *q)/* 出隊(duì)列 */retur n (in t)q->data1q->fr on t+;void InQueue(Queue *q,int data) /* 入隊(duì)列 */q_>data1q_>rear+=data;int IsHuiWe n(stack *st,Queue *q,char * a)int i,zhan,dui,k=0;/i計(jì)數(shù),zhan代表應(yīng)往棧里邊傳幾個(gè)原素,dui代表應(yīng)從第幾個(gè)原素開(kāi)始往隊(duì)列傳值,k計(jì)算數(shù)組a中有多少原素while(ak!='0')k+;if(k%2=0)zha n=k/2;dui=k/2+1;if(k%2=1)zha n=k/2;dui=k/2+2;for(i=0;i<zha n;i+)push(st,ai);for(i=zha n;i<k;i+)In Queue(q,

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論