數(shù)據(jù)結(jié)構(gòu)驗(yàn)證性實(shí)驗(yàn)指導(dǎo)書.doc_第1頁
數(shù)據(jù)結(jié)構(gòu)驗(yàn)證性實(shí)驗(yàn)指導(dǎo)書.doc_第2頁
數(shù)據(jù)結(jié)構(gòu)驗(yàn)證性實(shí)驗(yàn)指導(dǎo)書.doc_第3頁
數(shù)據(jù)結(jié)構(gòu)驗(yàn)證性實(shí)驗(yàn)指導(dǎo)書.doc_第4頁
數(shù)據(jù)結(jié)構(gòu)驗(yàn)證性實(shí)驗(yàn)指導(dǎo)書.doc_第5頁
已閱讀5頁,還剩24頁未讀, 繼續(xù)免費(fèi)閱讀

VIP免費(fèi)下載

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

文檔簡介

數(shù)據(jù)結(jié)構(gòu)驗(yàn)證性實(shí)驗(yàn)指導(dǎo)書實(shí)驗(yàn)一 線性表的順序存儲(chǔ)實(shí)驗(yàn)一、實(shí)驗(yàn)?zāi)康?、掌握用Visual C+6.0上機(jī)調(diào)試順序表的基本方法2、掌握順序表的基本操作,插入、刪除、查找、以及有序順序表的合并等算法的實(shí)現(xiàn)二、實(shí)驗(yàn)內(nèi)容1、順序表基本操作的實(shí)現(xiàn)問題描述 當(dāng)我們要在順序表的第i個(gè)位置上插入一個(gè)元素時(shí),必須先將順序表中第i個(gè)元素之后的所有元素依次后移一個(gè)位置,以便騰空一個(gè)位置,再把新元素插入到該位置。若是欲刪除第i個(gè)元素時(shí),也必須把第i個(gè)元素之后的所有元素前移一個(gè)位置?;疽?要求生成順序表時(shí),可以鍵盤上讀取元素,用順序存儲(chǔ)結(jié)構(gòu)實(shí)現(xiàn)存儲(chǔ)。實(shí)現(xiàn)提示 要實(shí)現(xiàn)基本操作,可用實(shí)現(xiàn)的基本操作,也可設(shè)計(jì)簡單的算法實(shí)現(xiàn)。程序?qū)崿F(xiàn)#include #include typedef int DataType ;# define maxnum 20typedef structint datamaxnum;int length;SeqList;/*插入函數(shù)*/int insert(SeqList *L , int i , DataType x)/* 將新結(jié)點(diǎn)x插入到順序表L第i個(gè)位置 */ int j ;if( i(*L).length +1) printf( n i 值不合法 ! ); return 0;if(* L).length =maxnum-1) printf( n 表滿不能插入!); return 0; for(j=(*L).length;j=i;j-) (*L).dataj+1=(*L).dataj;(*L).datai = x;(*L).length+;return 1;/*刪除函數(shù)*/int delete( SeqList *L ,int i) /*從順序L中刪除第i個(gè)結(jié)點(diǎn)*/ int j ;if( i(*L).length ) printf( n 刪除位置錯(cuò)誤 ! ) ;return 0;for(j=i+1;j=(*L).length;j+)(*L).dataj-1 =(*L).dataj;(*L).length-;return 1;/*生成順序表*/void creatlist(SeqList * L) int n , i , j ;printf(請(qǐng)輸入順序表 L 的數(shù)據(jù)個(gè)數(shù):n) ;scanf(%d , &n) ;for(i=0 ; in ; i+) printf(data%d = , i) ; scanf(%d,&(*L).datai);(*L).length=n-1;printf(n) ;/*creatlist */*輸出順序表 L*/printout(SeqList * L) int i ;for (i=0 ; i=(* L).length ; i+) printf( data%d=, i) ; printf(%d, (*L).datai);/*printout */printf(n);main() SeqList *L ;char cmd ;int i , t , x;clrscr() ;creatlist(L);doprintf(ni , I - 插入n) ;printf(d , D - 刪除n) ;printf(q , Q - 退出n) ;docmd=getchar() ;while(cmd!=i)&(cmd!=I)&(cmd!=d)&(cmd!=D)&(cmd!=q)&(cmd!=Q);switch(cmd) case i: case I:printf(nPlease input the DATA: );scanf(%d,&x) ;printf(nWhere? );scanf(%d,&i) ;insert(L,i,x) ;printout(L);break ;case d:case D :printf(nWhere to Delete? );scanf(%d,&i);delete(L,i);printout(L);break ;while(cmd!=q)&(cmd!=Q);2、有序順序表的合并問題描述 已知順序表la和lb中的數(shù)據(jù)元素按非遞減有序排列,將la和lb表中的數(shù)據(jù)元素,合并成為一個(gè)新的順序表lc基本要求 lc中的數(shù)據(jù)元素仍按非遞減有序排列,并且不破壞la和lb表程序?qū)崿F(xiàn)# include # define maxnum 20typedef int DataType ;typedef struct DataType datamaxnum ; int length ;SeqList ;int MergeQL(SeqList la , SeqList lb , SeqList *lc) int i , j , k ;if (la.length+1 + lb.length+1maxnum) printf(narray overflow!) ;return 0;i=j=k=0;while(i=la.length & j=lb.length) if (la.dataidatak+=la.datai+ ;else lc-datak+=lb.dataj+;/* 處理剩余部分 */while (idatak+=la.datai+;while (jdatak+=lb.dataj+;lc-length=k-1;return 1;main() SeqList la=3,4,7,12,15,4 ;SeqList lb=2,5,7,15,18,19,5 ;SeqList lc ;int i ;if (MergeQL(la,lb,&lc) printf(n) ;for(i=0;i=lc.length ; i+)printf(%4d,lc.datai); 實(shí)驗(yàn)二 單鏈表實(shí)驗(yàn)一、實(shí)驗(yàn)?zāi)康?、掌握用Visual C+6.0上機(jī)調(diào)試單鏈表的基本方法2、掌握單鏈表的插入、刪除、查找、求表長以及有序單鏈表的合并算法的實(shí)現(xiàn)3、進(jìn)一步掌握循環(huán)單鏈表的插入、刪除、查找算法的實(shí)現(xiàn)二、實(shí)現(xiàn)內(nèi)容1、單鏈表基本操作的實(shí)現(xiàn)問題描述要在帶頭結(jié)點(diǎn)的單鏈表h中第i個(gè)數(shù)據(jù)元素之前插入一個(gè)數(shù)據(jù)元素x ,首先需要在單鏈表中尋找到第i-1個(gè)結(jié)點(diǎn)并用指針p指示,然后申請(qǐng)一個(gè)由指針s 指示的結(jié)點(diǎn)空間,并置x為其數(shù)據(jù)域值,最后修改第i-1個(gè)結(jié)點(diǎn),并使x結(jié)點(diǎn)的指針指向第i個(gè)結(jié)點(diǎn),要在帶頭結(jié)點(diǎn)的單鏈表h中刪除第i個(gè)結(jié)點(diǎn),首先要計(jì)數(shù)尋找到第i個(gè)結(jié)點(diǎn)并使指針p指向其前驅(qū)第i-1個(gè)結(jié)點(diǎn),然后刪除第i個(gè)結(jié)點(diǎn)并釋放被刪除結(jié)點(diǎn)空間?;疽笥面?zhǔn)酱鎯?chǔ)結(jié)構(gòu)實(shí)現(xiàn)存儲(chǔ)實(shí)現(xiàn)提示鏈?zhǔn)酱鎯?chǔ)結(jié)構(gòu)不是隨機(jī)存儲(chǔ)結(jié)構(gòu),即不能直接取到單鏈表中某個(gè)結(jié)點(diǎn),而要從單鏈表的頭結(jié)點(diǎn)開始一個(gè)一個(gè)地計(jì)數(shù)尋找。程序?qū)崿F(xiàn)# include # include typedef char DataType ;typedef struct node DataType data; /*結(jié)點(diǎn)的數(shù)據(jù)域*/ struct node *next; /*結(jié)點(diǎn)的指針域*/ListNode;void Init_List(ListNode *L)(*L)=(ListNode *)malloc(sizeof(ListNode);/*產(chǎn)生頭結(jié)點(diǎn)*/(*L)-next=NULL;int List_Length(ListNode *L )int n=0;ListNode *p=L-next;while(p!=NULL)n+;p=p-next;return n;ListNode* GetNode(ListNode *L,int i) int j; ListNode *p; p=L;j=0; /*從頭結(jié)點(diǎn)開始掃描*/ while(p-next&j!=i) /*順指針向后掃描,直到p-next為NULL或i=j為止*/ p=p-next; j+; if(i=j) return p; /*找到了第i個(gè)結(jié)點(diǎn)*/ else return NULL; /*當(dāng)i0時(shí),找不到第i個(gè)結(jié)點(diǎn)*/ void InsertList(ListNode *L,DataType x,int i) ListNode *p,*s; p=GetNode(L,i-1); /*尋找第i-1個(gè)結(jié)點(diǎn)*/ if (p=NULL) /*in+1時(shí)插入位置i有錯(cuò)*/ printf(position error); return ; s=(ListNode *)malloc(sizeof(ListNode); s-data=x;s-next=p-next;p-next=s; void DeleteList(ListNode *L ,int i)ListNode *p,*r;p=GetNode(L,i-1); /*找到第i-1個(gè)結(jié)點(diǎn)*/if (p=NULL|p-next=NULL) /*in時(shí),刪除位置錯(cuò)*/ printf(position error); return ; r=p-next; /*使r指向被刪除的結(jié)點(diǎn)a*/p-next=r-next; /*將ai從鏈上刪除*/free(r); /*使用頭插法建立帶頭結(jié)點(diǎn)鏈表算法*/ListNode * CreatListF(void)char ch;ListNode *head=(ListNode *)malloc(sizeof(ListNode); /*生成頭結(jié)點(diǎn)*/ListNode *s; /*工作指針*/head-next=NULL; ch=getchar(); /*讀入第1個(gè)字符*/while(ch!=n) s=(ListNode *)malloc(sizeof(ListNode); /*生成新結(jié)點(diǎn)*/ s-data=ch; /*將讀入的數(shù)據(jù)放入新結(jié)點(diǎn)的數(shù)據(jù)域中*/ s-next=head-next; head-next=s; ch=getchar(); /*讀入下一字符*/return head; /*使用尾插法建立帶頭結(jié)點(diǎn)鏈表算法*/ListNode * CreatListR1(void) char ch; ListNode *head=(ListNode *)malloc(sizeof(ListNode); /*生成頭結(jié)點(diǎn)*/ ListNode *s,*r; /*工作指針*/ r=head; /*尾指針初值也指向頭結(jié)點(diǎn)*/ while(ch=getchar()!=n) s=(ListNode *)malloc(sizeof(ListNode); s-data=ch; r-next=s; r=s; r-next=NULL; /*終端結(jié)點(diǎn)的指針域置空,或空表的頭結(jié)點(diǎn)指針域置空*/ return head; /*復(fù)制鏈表A中的內(nèi)容到表B中*/ void copy(ListNode *a, ListNode *b) ListNode *pa=a-next; ListNode *u; ListNode *rb=b; while(pa!=NULL) u=( ListNode *)malloc(sizeof(ListNode); u-data=pa-data; rb-next=u; rb=u; pa=pa-next;rb-next=NULL;/*輸出帶頭結(jié)點(diǎn)的單鏈表*/void DisplaySL(ListNode *la, char *comment) ListNode *p ; p=la-next ; if(p) printf(n%sn , comment) ; while(p)printf(%4c,p-data);p=p-next; printf(n) ;/*主函數(shù)*/main( ) ListNode *la ,*lb,*lc, *p ;int n,x,i;printf(n用頭插法建立鏈表la,請(qǐng)輸入節(jié)點(diǎn)內(nèi)容:);la=CreatListF();DisplaySL(la,新生成鏈la節(jié)點(diǎn)內(nèi)容:); printf(n鏈表la的長度: %2d,List_Length(la);printf(n請(qǐng)輸入要插入的元素: );scanf(%c,&x) ;printf(n請(qǐng)輸入要插入的位置:);scanf(%d,&i) ;InsertList(la,x,i);DisplaySL(la,插入后鏈la節(jié)點(diǎn)內(nèi)容);printf(n請(qǐng)輸入要?jiǎng)h除元素的位置:);scanf(%d,&i);DeleteList(la,i);DisplaySL(la, 刪除后鏈la節(jié)點(diǎn)內(nèi)容);printf(n用尾插法建立鏈表lb,請(qǐng)輸入節(jié)點(diǎn)內(nèi)容:);fflush(stdin);lb=CreatListR1();DisplaySL(lb,新生成鏈lb節(jié)點(diǎn)內(nèi)容:); Init_List(&lc);copy(la,lc);DisplaySL(lc,復(fù)制生成的鏈lc節(jié)點(diǎn)內(nèi)容:); 2、有序單鏈表的合并問題描述 已知單鏈表la和lb中的數(shù)據(jù)元素按非遞減有序排列,將la和lb中的數(shù)據(jù)元素,合并為一個(gè)新的單鏈表lc,lc中的數(shù)據(jù)元素仍按非遞減有序排列?;疽?不破壞la表和lb表的結(jié)構(gòu)。程序?qū)崿F(xiàn)# include #include#define NULL 0typedef int DataType;typedef struct SLNode DataType data; struct SLNode * next; slnodetype;int MergeSL(slnodetype *la,slnodetype *lb,slnodetype *lc);int CreateSL(slnodetype *la,int n);void DisplaySL(slnodetype *la , char * comment);main( ) slnodetype *la, *lb, *lc ,*p;int n,m;la=(slnodetype *)malloc(sizeof(slnodetype);la-next=NULL;lb=(slnodetype *)malloc(sizeof(slnodetype);lb-next=NULL;lc=(slnodetype *)malloc(sizeof(slnodetype);lc-next=NULL;printf(n 輸入鏈la節(jié)點(diǎn)數(shù):);scanf(%d,&n);printf(n 輸入鏈la 節(jié)點(diǎn)內(nèi)容:);CreateSL(la,n);DisplaySL(la,鏈la 節(jié)點(diǎn)內(nèi)容:);printf(n 輸入鏈lb節(jié)點(diǎn)數(shù):);scanf(%d,&m);printf(n 輸入鏈lb節(jié)點(diǎn)內(nèi)容:);CreateSL(lb,m);DisplaySL(lb,鏈lb 節(jié)點(diǎn)內(nèi)容:);if(MergeSL(la,lb,&lc) DisplaySL(lc,合成后的鏈lc:);getchar();int MergeSL(slnodetype * la , slnodetype *lb,slnodetype * *lc) slnodetype * pa, * pb, * pc; lc=(slnodetype *)malloc(sizeof(slnodetype); pa=la-next; pb=lb-next; pc= *lc; while(pa&pb) pc-next=(slnodetype*)malloc(sizeof(slnodetype);pc=pc-next; if(pa-datadata) pc-data=pa-data; pa=pa-next; else pc-data=pb-data; pb=pb-next; while (pa) /*插入la鏈的剩余段 */ pc-next=(slnodetype*)malloc(sizeof(slnodetype); pc=pc-next;pc-data=pa-data; pa=pa-next; /*插入lb鏈的剩余段*/ while(pb) pc-next=(slnodetype*)malloc(sizeof(slnodetype); pc=pc-next;pc-data=pb-data; pb=pb-next; /*生成單鏈表*/int CreateSL(slnodetype *la ,int n) int i ;slnodetype *p , *q ;q=la ;for (i=1 ; idata) ;q-next=p;q=p;q-next=NULL ;return 1 ;/*輸出單鏈表*/void DisplaySL(slnodetype *la, char *comment) slnodetype *p ;p=la-next ;if(p) printf(n%sn , comment) ;while(p) printf(n%3d , p-data);p=p-next ;printf(n) ;3. 約瑟夫環(huán)問題問題描述設(shè)有N個(gè)人圍坐一圈,現(xiàn)從某個(gè)人開始報(bào)數(shù),數(shù)到M的人出列,接著從出列的下一個(gè)人開始重新報(bào)數(shù),數(shù)到M的人以出列,如此下去,直到所有人都出列為此。試設(shè)計(jì)確定他們的出列次序序列的程序。基本要求 選擇單向循環(huán)鏈表作為存儲(chǔ)結(jié)構(gòu)模擬整個(gè)過程,并依次輸出列的各人的編號(hào)。實(shí)現(xiàn)提示 程序運(yùn)行之后,首先要求用戶指定初始報(bào)數(shù)的下限值,可以n=30,此題循環(huán)鏈表可不設(shè)頭節(jié)點(diǎn),而且必須注意空表和非空表的界限。如 n=8, m=4 時(shí),若從第一個(gè)人, 設(shè)每個(gè)人的編號(hào)依次為 1,2,3,開始報(bào)數(shù),則得到的出列次序?yàn)?,8,5,2,1,3,7,6,如下圖所示,內(nèi)層數(shù)字表示人的編號(hào) ,每個(gè)編號(hào)外層的數(shù)字代表人出列的序號(hào)。程序?qū)崿F(xiàn)#include #include typedef struct node int num; struct node *next; linklist;linklist *creat(head,n) /*使n個(gè)人圍成一圈,并給每個(gè)人標(biāo)識(shí)號(hào)數(shù)*/ linklist *head; int n ; linklist *s,*p; int i; s=(linklist * )malloc(sizeof(linklist); head=s; s-num=1; p=s; for(i=2;inum=i; p-next=s; p=s; p-next=head; return(head); /* creat */linklist * select(linklist *head, int m) linklist *p, *q; int i, t; p=head; t=1; q=p; /* q為p的前趨指針*/ p=p-next; do t=t+1 ; /*報(bào)一次數(shù)*/ if(t%m=0) printf(%4d, p-num); q-next=p-next; free(p); p=q-next; else q=p; p=p-next; while(q!=p); head=p; printf(%4d,p-num); return (head); /* select */main( ) int n,m; linklist *head; printf(ninput the total number:n=); scanf(%d, &n); printf(ninput the number to call:m=); scanf(%d, &m); head=creat(head,n); head=select(head,m); printf(nthe last one is :%d, head-num); /* main */思考題:編程實(shí)現(xiàn)兩個(gè)循環(huán)單鏈表的合并。實(shí)驗(yàn)三 棧、隊(duì)列的實(shí)現(xiàn)及應(yīng)用一、實(shí)驗(yàn)?zāi)康?、掌握棧和隊(duì)列的順序存儲(chǔ)結(jié)構(gòu)和鏈?zhǔn)酱鎯?chǔ)結(jié)構(gòu),以便在實(shí)際背景下靈活運(yùn)用。2、掌握棧和隊(duì)列的特點(diǎn),即先進(jìn)后出與先進(jìn)先出的原則。3、掌握棧和隊(duì)列的基本操作實(shí)現(xiàn)方法。二、實(shí)驗(yàn)內(nèi)容1、實(shí)現(xiàn)棧的順序存儲(chǔ)# define MAXSIZE 100 typedef int ElemType;typedef struct ElemType dataMAXSIZE; int top;SeqStack; void InitStack(SeqStack *s) s-top=0; return 1;int StackEmpty(SeqStack *s) if(s-top=0) return 1; else return 0;int StackFull(SeqStack *s) if(s-top=MAXSIZE-1) return 1; else return 0; void Push(SeqStack *s,int x) if (StackFull(s) printf(the stack is overflow!n); return 0; else s-datas-top=x; s-top+; void Display(SeqStack *s) if(s-top=0) printf(the stack is empty!n); else while(s-top!=0) printf(%d-,s-datas-top); s-top=s-top-1; ElemType Pop(SeqStack *s) if(StackEmpty(s) return 0; else return s-data-s-top; ElemType StackTop(SeqStack *s) int i;if(StackEmpty(s) return 0; else i=s-top-1;return s-datai; /*返回棧頂元素的值,但不改變棧頂指針*/ main(SeqStack *p) int n,i,k,h,x1,x2,select; printf(create a empty stack!n); InitStack(p); printf(input a stack length:n); scanf(%d,&n); for(i=0;i%dn,x1); display(p); break; case 4:x2=StackTop(p);printf(x2-%d,x2);break; 2、利用棧實(shí)現(xiàn)數(shù)制轉(zhuǎn)換 # define MAXSIZE 100typedef int ElemType; /*將順序棧的元素定義為整型*/typedef struct ElemType dataMAXSIZE; int top;SeqStack; void InitStack(SeqStack *s) s-top=0; return 1;int StackEmpty(SeqStack *s) if(s-top=0) return 1; else return 0;int StackFull(SeqStack *s) if(s-top=m-1) return 1; else return 0; void Push(SeqStack *s,int x) if (StackFull(s) printf(the stack is overflow!n); return 0; else s-datas-top=x; s-top+; ElemType Pop(SeqStack *s) ElemType y; if(StackEmpty(s) printf(the stack is empty!n); return 0; else y=s-datas-top; s-top=s-top-1; return y; ElemType StackTop(SeqStack *s) if(StackEmpty(s) return 0; else return s-datas-top;void Dec_to_Ocx (int N) /* n是非負(fù)的十進(jìn)制整數(shù),輸出等值的八進(jìn)制數(shù)*/SeqStack *S; /*定義一個(gè)順序棧*/ElemType x; Init_SeqStack(S); /*初始化棧*/if(Nfront=0;p-rear=0;return 1;int enqueue(seqqueue *q, int e) if(q-rear+1)%maxsize=q-front) return 0; else q-dataq-rear=e; q-rear=(q-rear+1)%maxsize; return 1; int dequeue(seqqueue *q) int e;if (q-front=q-rear)return 0;e=q-dataq-front;q-front=(q-front+1)%maxsize;return e;int empty(seqqueue *q) int v; if (q-front=q-rear) v=1; else v=0; return v; int gethead(seqqueue *q) int e; if (q-front=q-rear) e=-1; else e=q-dataq-front; return e; void display(seqqueue *q) int s; s=q-front; printf(the sequeue is display:n); if (q-front=q-rear) printf(the sequeue is empty!); else while(srear) printf(-%d, q-datas);s=(s+1)%maxsize;printf(n); main(seqqueue *head) int n,i,m,x,y,select,xq; printf(create a empty sequeuen); sqinit(head); printf(please input the sequeue length:n); scanf(%d,&n); for (i=0;irear:%dn,head-rear); printf(head-front:%dn,head-front); display(head); printf(select 1 * enqueue() n); printf(select 2 * dequeue() n); printf(select 3 * empty () n); printf(select 4 * gethead() n); printf(select 5 * display() n); printf(please select (1-5):); scanf(%d,&select); switch(select) case 1: printf(please input a value :n ); scanf(%d,&x); enqueue(head,x); display(head); break; case 2: dequeue(head); display(head); break; case 3: if(empty(head) printf(the sequeue is empty); else printf(the sequeue is full); case 4: y=gethead(head); printf(output head value:%dn,y); break; case 5: display(head); break;實(shí)驗(yàn)四 二叉樹的基本操作一、實(shí)驗(yàn)?zāi)康?、進(jìn)一步掌握指針變量、動(dòng)態(tài)變量的含義。2、掌握二叉樹的結(jié)構(gòu)特性,以及各種存儲(chǔ)結(jié)構(gòu)的特點(diǎn)和適用范圍。3、掌握用指針類型描述、訪問和處理二叉樹的運(yùn)算。二、實(shí)驗(yàn)內(nèi)容1、以二叉鏈表作存儲(chǔ)結(jié)構(gòu),試編寫前序、中序、后序及層次順序遍歷二叉樹的算法。#define M 10typedef int DataType;/*元素的數(shù)據(jù)類型*/typedef struct node DataType data; struct node *lchild,*rchild;BitTNode,*BiTree;int front=0,rear=0;BitTNode *que10;BitTNode *creat()BitTNode *t; DataType x; scanf(%d,&x); if(x=0) t=NULL; else t=(BitTNode *)malloc(sizeof(BitTNode); t-data=x; t-lchild=creat(); t-rchild=creat(); return(t);/*creat*/* 前序遍歷二叉樹t */void preorder(BiTree t) if(t!=NULL) printf(%4d,t-data); preorder(t-lchild);preorder(t-rchild); /* 中序遍歷二叉樹t */void inorder(BiTree t) if(t!=NULL) inorder(t-lchild); printf(%4d,t-data); inorder(t-rchild); /* 后序遍歷二叉樹t */void postorder(BiTree t) if(t!=NULL) postorder(t-lchild); postorder(t-rchild); printf(%4d,t-data); void enqueue(BitTNode *t)if (front!=(rear+1)%M) rear=(rear+1)%M; querear=t; /*enqueue*/BitTNode * delqueue() if(front=rear)return NULL; front=(front+1)%M; return (quefront); /*delqueue*/* 按層次遍歷二叉樹t */void levorder(BiTree t) BitTNode *p; if(t!=NULL) enqueue(t); while (front!=rear) p=delqueue(); printf(%4d,p-data); if(p-lchild!=NULL) enqueue(p-lchild); if(p-rchild!=NULL) enqueue(p-rchild); /* levorder */main()BitTNode *root; root=creat();printf(n按先序遍歷次序生成的二叉樹); printf(n前序遍歷二叉樹); preorder(root);printf(n中序遍歷二叉樹); inorder(root);printf(n后序遍歷二叉樹); postorder(ro

溫馨提示

  • 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ì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論