版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
《數(shù)據(jù)結(jié)構(gòu)》實驗指導(dǎo)2013/2014學(xué)年第學(xué)期姓名:學(xué)號:班級:指導(dǎo)教師:濰坊學(xué)院計算機(jī)工程學(xué)院2014預(yù)備實驗C語言的函數(shù)數(shù)組指針結(jié)構(gòu)體知識一、實驗?zāi)康?、復(fù)習(xí)C語言中函數(shù)、數(shù)組、指針和結(jié)構(gòu)體的概念。2、熟悉利用C語言進(jìn)行程序設(shè)計的一般方法。二、實驗內(nèi)容和要求1、調(diào)試程序:輸出100以內(nèi)所有的素數(shù)(用函數(shù)實現(xiàn))。#include<stdio.h>/*判斷一個數(shù)是否為素數(shù)*/intisprime(intn)(for(intm=2;m*m<=n;m++){if(n%m==0)return0;return1;}/*輸出100以內(nèi)所有素數(shù)*/intmain(){inti;for(i=2;i<100;i++)if(isprime(i)==1)printf("%4d'',i);return0;}運(yùn)行結(jié)果:?357111317192329JI3741434753(.171737?S3WMyIt叫coctntLmie.2、調(diào)試程序:對一維數(shù)組中的元素進(jìn)行逆序排列。#include<stdio.h>#defineN10intmain(){inta[N]={0,1,2,3,4,5,6,7,8,9},i,temp;printf(“theoriginalArrayis:\n”);for(i=0;i<N;i++)printf("%4d”,a[i]);for(i=0;i<N/2;i++){/*交換數(shù)組元素使之逆序*/temp=a[i];a[i]=a[N-i-1];a[N-i-1]=temp;}printf(“\nthechangedArrayis:\n”);for(i=0;i<N;i++)printf("%4d”,a[i]);return0;}運(yùn)行結(jié)果:theorigina]f;Iw曹!icT字OPIf&gs司ny加gnHnu冏3、調(diào)試程序:在二維數(shù)組中,若某一位置上的元素在該行中最大,而在該列中最小,則該元素即為該二維數(shù)組的一個鞍點(diǎn)。要求從鍵盤上輸入一個二維數(shù)組,當(dāng)鞍點(diǎn)存在時,把鞍點(diǎn)找出來。#include<stdio.h>#defineM3#defineN4intmain()(inta[M][N],i,j,k;printf(“請輸入二維數(shù)組的數(shù)據(jù):\n”)for(i=0;i<M;i++)for(j=0;j<N;j++)scanH“%d”,&a[i][j])for(i=0;i<M;i++){/*輸出矩陣*/for(j=0;j<N;j++)printH"%4d”,a[i][j])printH"\n”)}for(i=0;i<M;i++){k=0;for(j=1;j<N;j++)/*找出第i行的最大值*/if(a[i][j]>a[i][k])k=j;for(j=0;j<M;j++)/*判斷第i行的最大值是否為該列的最小值*/if(a[j][k]<a[i][k])break;if(j==M)/*在第i行找到鞍點(diǎn)*/printH“%d,%d,%d\n”),a[i][k],i,k)}return0;運(yùn)行結(jié)果:4、調(diào)試程序:利用指針輸出二維數(shù)組的元素。#include<stdio.h>intmain()(inta[3][4]={1,3,5,7,9,11,13,15,17,19,21,23};int*p;for(p=a[0];p<a[0]+12;p++){if((p-a[0])%4==0)printf("\n'');printf(%4d'',*p);}return0;}運(yùn)行結(jié)果:5、調(diào)試程序:輸入10個學(xué)生的成績,每個學(xué)生成績包括學(xué)號、姓名和三門課的成績。要求打印出三門課的平均成績及成績最高者的姓名和成績。#include<stdio.h>#defineN10;structstudent{charnum[6];/*學(xué)號*/charname[8];/*姓名*/intscore[3];/*成績*/floatavr;/*平均成績*/}stu[N];intmain(){inti,j,max,maxi,sum;floataverage;for(i=0;i<N;i++){/*輸入10個學(xué)生的成績信息*/printf(“\n請輸入第%d學(xué)生的成績:\n”,i+1);printf(“學(xué)號:”);scanf("%s”,stu[i].num);printf(“姓名”);scanf("%s”,stu[i].name);for(j=0;j<3;j++){printf(“成績%d”,j+1);scanf("%d”,&stu[i].score[j]);}}average=0;max=0;maxi=0;for(i=0;i<N;i++){/*計算平均成績,找出成績最高的學(xué)生*/sum=0;for(j=0;j<3;j++)sum+=stu[i].score[j];stu[i].avr=sum/3.0;average+=stu[i].avr;if(sum>max){max=sum;maxi=i;}}average/=10;printf(“學(xué)號姓名成績1成績2成績3平均分^);for(i=0;i<10;i++){printf("%8s%10s”,stu[i].num,stu[i].name);for(j=0;j<3;j++)printf("%7d”,stu[i].score[j]);printf("%6.2f\n'',stu[i].avr);}printf(“平均成績是:%5.2f\n”,average);printf(“最好成績的學(xué)生是:%s,總分是%d”,stu[maxi].name,max);return0;}運(yùn)行結(jié)果
.蛾#平荊分!■?w&L/lhJa^&Efessywr-dX'J姓芝就痕44tocontijnu£l1007!:2ff■::■-±rtL7t■.蛾#平荊分!■?w&L/lhJa^&Efessywr-dX'J姓芝就痕44tocontijnu£l1007!:2ff■::■-±rtL7t■■>03r9nTidi1£L31A-3sipjrsPSIPS■lib.T¥:■/I-:CU3391成的71VWV:BfA-J4"'1-1l:vmI■g45&P#*0B000vufc82.17學(xué)?生是Ipuan.總分是27『心皿四、教師評語實驗一順序表與鏈表一、實驗?zāi)康?、掌握線性表中元素的前驅(qū)、后續(xù)的概念。2、掌握順序表與鏈表的建立、插入元素、刪除表中某元素的算法。3、對線性表相應(yīng)算法的時間復(fù)雜度進(jìn)行分析。4、理解順序表、鏈表數(shù)據(jù)結(jié)構(gòu)的特點(diǎn)(優(yōu)缺點(diǎn))。二、實驗內(nèi)容和要求1、閱讀下面程序,在橫線處填寫函數(shù)的基本功能。并運(yùn)行程序,寫出結(jié)果。#include<stdio.h>#include<malloc.h>#defineERROR0#defineOK1#defineINIT_SIZE5#defineINCREM#defineINIT_SIZE5#defineINCREM5typedefintElemType;typedefstructSqlist{ElemType*slist;intlength;intlistsize;}Sqlist;/*存儲空間的基地址*//*順序表的當(dāng)前長度*//*當(dāng)前分配的存儲空間*/TOC\o"1-5"\h\zintInitList_sq(Sqlist*L);/*/intCreateList_sq(Sqlist*L,intn);/**/intListInsert_sq(Sqlist*L,inti,ElemTypee);/*在順序線性表L中第i個元素之前插入新的元素£*/intPrintList_sq(Sqlist*L);/*輸出順序表的元素*/intListDelete_sq(Sqlist*L,inti);/*刪除第i個元素*/intListLocate(Sqlist*L,ElemTypee);/*查找值為e的元素*/intInitList_sq(Sqlist*L){L->slist=(ElemType*)malloc(INIT_SIZE*sizeof(ElemType));if(!L->slist)returnERROR;L->length=0;L->listsize=INIT_SIZE;returnOK;}/*InitList*/intCreateList_sq(Sqlist*L,intn){ElemTypee;inti;for(i=0;i<n;i++){printf("inputdata%d",i+1);scanf(〃%d〃,&e);if(!ListInsert_sq(L,i+1,e))returnERROR;}returnOK;}/*CreateList*//*輸出順序表中的元素*/intPrintList_sq(Sqlist*L){inti;for(i=1;i<=L->length;i++)printf(〃%5d〃,L->slist[iT]);returnOK;}/*PrintList*/intListInsert_sq(Sqlist*L,inti,ElemTypee){intk;if(i<1||i>L->length+1)returnERROR;if(L->length>=L->listsize){L->slist=(ElemType*)realloc(L->slist,(INIT_SIZE+INCREM)*sizeof(ElemType));if(!L->slist)returnERROR;L->listsize+=INCREM;}for(k=L->length-1;k>=i-1;k--){L->slist[k+1]=k;}L->slist[i-1]=e;L->length++;returnOK;}/*ListInsert*//*在順序表中刪除第i個元素*/intListDelete_sq(Sqlist*L,inti){if((i<1)||(i>L->length))returnERROR;for(p=i-1;p<->length-1;p++)L->slist[p]=L->slist[p+1];L->length—;returnOK;}/*在順序表中查找指定值元素,返回其序號*/intListLocate(Sqlist*L,ElemTypee){}intmain(){Sqlistsl;intn;printf("pleaseinputn:〃);/*輸入順序表的元素個數(shù)*/scanf(〃%d〃,&n);if(n>0){printf("\n1-CreateSqlist:\n〃);InitList_sq(&sl);CreateList_sq(&sl,n);printf("\n2-PrintSqlist:\n〃);PrintList_sq(&sl);}elseprintf(〃ERROR〃);return0;}算法分析與運(yùn)行結(jié)果pleaseinputn:5CreateSqlist:inputdata10inputdata25inputdata38inputdata43inputdata56PrintSqlist:05836Pressanykeytocontinueleas1!?in-nutn=5CmAteSqliet:i-npui^A訊*巳10Inuul;data藝5£hputflata網(wǎng)inputdata43inputdL^itaStO&B9tPt*aceanyke^-to£=ontInne2、為第1題補(bǔ)充刪除和查找功能函數(shù),并在主函數(shù)中補(bǔ)充代碼驗證算法的正確性。算法代碼:intListDelete_sq(Sqlist*L,inti){intp;if((i<1)||(i>L->length))returnERROR;for(p=i-1;p<L->length-1;p++){L->slist[p]=L->slist[p+1];}L->length—;returnOK;}/*在順序表中查找指定值元素,返回其序號*/intListLocate(Sqlist*L,ElemTypee){inti=0;while((i<=L->length)&&(L->slist[i]!=e))i++;if(i<=L->length)return(i+1);elsereturn(-1);}3、閱讀下面程序,在橫線處填寫函數(shù)的基本功能。并運(yùn)行程序,寫出結(jié)果。#include<stdio.h>#include<malloc.h>#defineERROR0#defineOK1typedefintElemType;/淀義表元素的類型大/typedefstructLNode{/*線性表的單鏈表存儲大/ElemTypedata;structLNode*next;}LNode,*LinkList;LinkListCreateList(intn);/構(gòu)誥順序表的長度*/
voidPrintList(LinkListL);/大輸出帶頭結(jié)點(diǎn)單鏈表的所有元素*/intGetElem(LinkListL,inti,ElemType*e);/*在順序線性表L中,當(dāng)?shù)趇個元素存在時,將其賦值為e*/voidPrintList(LinkListL){LinkListCreateList(intn){LNodeLinkListCreateList(intn){LNode*p,*q,*head;inti;head=(LinkList)malloc(sizeof(LNode));p=head;for(i=0;i<n;i++){q=(LinkList)malloc(sizeof(LNode));data%i:",i+1);scanf("%d”,&q->data);q->next=NULL;p->next=q;p=q;}returnhead;}/*CreateList*/head->next=NULL;輸入元素值大/結(jié)點(diǎn)指針域置空大/新結(jié)點(diǎn)連在表末尾大/printf("inputLNode*p;p=L->next;/大甘旨向單鏈表的第1個元素大/while(p!=NULL){printf("%5d”,p->data);p=p->next;}}/*PrintList*/intGetElem(LinkListL,inti,ElemType*e){LNode*p;intj=1;p=L->next;while(p&&j<i){p=p->next;j++;}if(!p||j>i)returnERROR;*e=p->data;returnOK;}/*GetElem*/intmain(){intn,i;ElemTypee;LinkListL=NULL;定義指向單鏈表的指針大/printf("pleaseinputn:");/輸入單鏈表的元素個數(shù)*/scanf("%d”,&n);if(n>0){printf("\n1-CreateLinkList:\n");L=CreateList(n);printf("\n2-PrintLinkList:\n");PrintList(L);printf("\n3-GetElemfromLinkList:\n");printf("inputi=");scanf("%d”,&i);if(GetElem(L,i,&e))printf("No%iis%d”,i,e);elseprintf("notexists");}elseprintf("ERROR");return0;}算法分析與運(yùn)行結(jié)果pleaseinputn:5CreateLinkList:inputdata1:8inputdata2:6inputdata3:3inputdata4:5inputdata5:4PrintLinkList:86354GetElemfromLinkList:inputi=2No2is6Pressanykeytocontinue■pleASftinputinputd>nf;q1?8ipput2:6input*03r3Input:-di-ata4:5inputidAta5MPri.FiCLlnhliisc-8g3&4GetEleuiFromLin^kList:inKUti-2INo3Isanykeytoc;dit:£nuc4、為第3題補(bǔ)充插入功能函數(shù)和刪除功能函數(shù)。并在主函數(shù)中補(bǔ)充代碼驗證算法的正確性。?算法代碼intListInsert_sq(LNode*L,inti,ElemTypee){intk;if(i<1||i>L->length+1)returnERROR;if(L->length>=L->listsize){L->data=(ElemType*)realloc(L->data,(INIT_SIZE+INCREM)*sizeof(ElemType));if(!L->data)returnERROR;L->listsize+=INCREM;}#include<stdio.h>#include<malloc.h>#defineERROR0#defineOK1typedefintElemType;/淀義表元素的類型*/typedefstructLNode{/*線性表的單鏈表存儲*/ElemTypedata;structLNode*next;}LNode,*LinkList;LinkListCreateList(intn);/*以下為選做實驗:5、循環(huán)鏈表的應(yīng)用(約瑟夫回環(huán)問題)n個數(shù)據(jù)元素構(gòu)成一個環(huán),從環(huán)中任意位置開始計數(shù),計到m將該元素從表中取出,重復(fù)上述過程,直至表中只剩下一個元素。提示:用一個無頭結(jié)點(diǎn)的循環(huán)單鏈表來實現(xiàn)n個元素的存儲。?算法代碼6、設(shè)一帶頭結(jié)點(diǎn)的單鏈表,設(shè)計算法將表中值相同的元素僅保留一個結(jié)點(diǎn)。提示:指針p從鏈表的第一個元素開始,利用指針q從指針p位置開始向后搜索整個鏈表,刪除與之值相同的元素;指針p繼續(xù)指向下一個元素,開始下一輪的刪除,直至p==null為至,既完成了對整個鏈表元素的刪除相同值。?算法代碼三、實驗小結(jié)具體的掌握線性表中元素的前驅(qū)、后續(xù)的概念。以及順序表與鏈表的建立、插入元素、刪除表中某元素的算法。并學(xué)習(xí)了對線性表相應(yīng)算法的時間復(fù)雜度進(jìn)行分析。四、教師評語實驗二棧和隊列一、實驗?zāi)康?、掌握棧的結(jié)構(gòu)特性及其入棧,出棧操作;2、掌握隊列的結(jié)構(gòu)特性及其入隊、出隊的操作,掌握循環(huán)隊列的特點(diǎn)及其操作。二、實驗內(nèi)容和要求1、閱讀下面程序,將函數(shù)Push和函數(shù)Pop補(bǔ)充完整。要求輸入元素序列12345e,運(yùn)行結(jié)果如下所示。#include<stdio.h>#include<malloc.h>#defineERROR0#defineOK1#defineSTACK_INT_SIZE10/*存儲空間初始分配量大/#defineSTACKINCREMENT5/*存儲空間分配增量大/typedefintElemType;/*定義元素的類型大/typedefstruct{ElemType*base;ElemType*top;intstacksize;當(dāng)前已分配的存儲空間大/}SqStack;intInitStack(SqStack*S);/構(gòu)造空棧大/intpush(SqStack*S,ElemType*e);/大入棧*/intPop(SqStack*S,ElemType*e);/*出棧*/intCreateStack(SqStack*S);/創(chuàng)建棧大/voidPrintStack(SqStack*S);/出棧并輸出棧中元素大/intInitStack(SqStack*S){S->base=(ElemType*)malloc(STACK_INT_SIZE*sizeof(ElemType));if(!S->base)returnERROR;S->top=S->base;S->stacksize=STACK_INT_SIZE;returnOK;}/*InitStack*/intPush(SqStack*S,ElemTypee){}/*Push*/intPop(SqStack*S,ElemType*e){}/*Pop*/intCreateStack(SqStack*S){inte;if(InitStack(S))printf("InitSuccess!\n");else{printf("InitFail!\n");returnERROR;}printf("inputdata:(Terminatedbyinputingacharacter)\n");while(scanf("%d”,&e))Push(S,e);returnOK;}/*CreateStack*/voidPrintStack(SqStack*S){ElemTypee;while(Pop(S,&e))printf("%3d”,e);}/*Pop_and_Print*/intmain(){SqStackss;printf("\n1-createStack\n");CreateStack(&ss);printf("\n2-Pop&Print\n");PrintStack(&ss);return0;}算法分析:輸入元素序列12345,為什么輸出序列為54321?體現(xiàn)了棧的什么特性?2、在第1題的程序中,編寫一個十進(jìn)制轉(zhuǎn)換為二進(jìn)制的數(shù)制轉(zhuǎn)換算法函數(shù)(要求利用棧來實現(xiàn)),并驗證其正確性。實現(xiàn)代碼voidconveshen(SqStack*S){ElemTypen,h;intm=0,k=0;InitStack(S);printf("Inputelement\n");scanf("%d”,&n);while(n){m++;Push(S,n%2);n=n/2;}while(k<m){k++;Pop(S,&h);printf("%d”,h);}}intmain(){SqStackS;conveshen(&S);printf(〃\n〃);}[inputN:111011Pressanykeytocontinue3、閱讀并運(yùn)行程序,并分析程序功能。#include<stdio.h>#include<malloc.h>#include<string.h>#defineM20#defineelemtypechartypedefstruct{elemtypestack[M];inttop;}stacknode;voidinit(stacknode*st);voidpush(stacknode*st,elemtypex);voidpop(stacknode*st);voidinit(stacknode*st){st->top=0;}voidpush(stacknode*st,elemtypex){if(st->top==M)printf("thestackisoverflow!\n");else{st->top=st->top+1;st->stack[st->top]=x;}}voidpop(stacknode*st){st->top=st->top-1;}intmain(){chars[M];inti;printf("createaemptystack!\n");stacknode*sp;sp=malloc(sizeof(stacknode));init(sp);printf("inputaexpression:\n");gets(s);for(i=0;i<strlen(s);i++){if(s[i]=='(')push(sp,s[i]);if(s[i]==')')pop(sp);}if(sp->top==0)printf("'('match')'!\n");elseprintf("'('notmatch')'!\n");return0;J輸入:2+((c-d)*6-(f-7)*a)/6運(yùn)行結(jié)果:input丑eK^riBKBian:a-<Ce-d>*b-C*/3-se>z2Press尊位¥k中丫tac^nt£mue輸入:a-((c-d)*6-(s/3-x)/2運(yùn)行crefitcatnjjtjjaexpressionI2+<Cc-d-6-(f-?>3/GJ-i1r?n-tmatcJi*VJtPressanyk噂#tflemitin(te程序的基本功能:以下為選做實驗:4、設(shè)計算法,將一個表達(dá)式轉(zhuǎn)換為后綴表達(dá)式,并按照后綴表達(dá)式進(jìn)行計算,得出表達(dá)式得結(jié)果。實現(xiàn)代碼5、假設(shè)以帶頭結(jié)點(diǎn)的循環(huán)鏈表表示隊列,并且只設(shè)一個指針指向隊尾結(jié)點(diǎn)(不設(shè)隊頭指針),試編寫相應(yīng)的置空隊列、入隊列、出隊列的算法。實現(xiàn)代碼:三、實驗小結(jié)基本掌握棧的結(jié)構(gòu)特性及其入棧,出棧操作;以及隊列的結(jié)構(gòu)特性及其入隊、出隊的操作,掌握循環(huán)隊列的特點(diǎn)及其操作四、教師評語實驗三串的模式匹配一、實驗?zāi)康?、了解串的基本概念2、掌握串的模式匹配算法的實現(xiàn)二、實驗內(nèi)容和要求1、閱讀并運(yùn)行下面程序,根據(jù)輸入寫出運(yùn)行結(jié)果。#include<stdio.h>#include<string.h>#defineMAXSIZE100typedefstruct{chardata[MAXSIZE];intlength;}SqString;intstrCompare(SqString*s1,SqString*s2);/*串的比較*/voidshow_strCompare();voidstrSub(SqString*s,intstart,intsublen,SqString*sub);/*求子串*/voidshow_subString();intstrCompare(SqString*s1,SqString*s2){inti;for(i=0;i<s1->length&&i<s1->length;i++)if(s1->data[i]!=s2->data[i])returns1->data[i]-s2->data[i];returns1->length-s2->length;}voidshow_strCompare(){SqStrings1,s2;intk;printf("\n***showCompare***\n");printf("inputstrings1:");gets(s1.data);s1.length=strlen(s1.data);printf("inputstrings2:");gets(s2.data);s2.length=strlen(s2.data);if((k=strCompare(&s1,&s2))==0)printf("s1=s2\n");elseif(k<0)printf("s1<s2\n");elseprintf("s1>s2\n");printf("\n***showover***\n");}voidstrSub(SqString*s,intstart,intsublen,SqString*sub){inti;if(start<1||start>s->length||sublen>s->length-start+1){sub->length=0;}for(i=0;i<sublen;i++)sub->data[i]=s->data[start+i-1];sub->length=sublen;}voidshow_subString(){SqStrings,sub;intstart,sublen,i;printf("\n***showsubString***\n");printf("inputstrings:");gets(s.data);s.length=strlen(s.data);printf("inputstart:");scanf("%d”,&start);printf("inputsublen:");scanf("%d”,&sublen);strSub(&s,start,sublen,&sub);if(sub.length==0)printf("ERROR!\n");else{printf("subStringis:");for(i=0;i<sublen;i++)printf("%c”,sub.data[i]);}printf("\n***showover***\n");}intmain(){intn;do{printf("\nString\n");printf("1.strCompare\n");printf("2.subString\n");printf("0.EXIT\n");printf("\ninputchoice:");scanf("%d”,&n);getchar();switch(n){case1:show_strCompare();break;case2:show_subString();break;default:n=0;break;}}while(n);return0;}運(yùn)行程序輸入:1studentstudents2ComputerDataStuctures104運(yùn)行結(jié)果:"F:\Cn-+WENJlAN\Debug\^驗三wxe"String1<,stvConpare2qsubstringS.EXITinputchoice;1***showConpaye***inputstririgsistudentInputstriitgfsS:studentssl<s3WMsliowover***Stringl-istrConparesufcStriinjEKITInpul;choice:S***sFow?uhStrinjf***inputstrings:ConputerD爪七亂Structuresinputst-art:lflinputsublcn;4substringis:D-^ta***51101?uv^r***StringstrConparcrt.suhStrir)sr[1.ENITinputchoicei2、實現(xiàn)串的模式匹配算法。補(bǔ)充下面程序,實現(xiàn)串的BF和KMP算法。#include<stdio.h>#include<string.h>#defineMAXSIZE100typedefstruct{chardata[MAXSIZE];intlength;}SqString;intindex_bf(SqString*s,SqString*t,intstart);voidgetNext(SqString*t,intnext[]);intindex_kmp(SqString*s,SqString*t,intstart,intnext[]);voidshow_index();intindex_bf(SqString*s,SqString*t,intstart){inti,j,pos;if(t->length==0)return(0);pos=start;i=pos;j=0;while(i<s->length&&j<t->length)if(s->data[i]==t->data[j]){i++;j++;}else{pos++;i=pos;j=0;}if(j>=t->length)return(pos);elsereturn(-1);}}voidgetNext(SqString*t,intnext[]){inti=0,j=-1;next[0]=-1;while(i<t->length){if((j==-1)||(t->data[i]==t->data[j])){i++;j++;next[i]=j;}elsej=next[j];}}intindex_kmp(SqString*s,SqString*t,intstart,intnext[]){inti,j;if(t->length==0)return(0);i=start;j=0;while(i<s->length&&j<t->length)if(s->data[i]==t->data[j]){i++;j++;}elsej=next[j];if(j>=t->length)return(i-j);elsereturn(-1);}voidshow_index(){SqStrings,t;intk,next[MAXSIZE]={0},i;printf("\n***showindex***\n");printf("inputstrings:");gets(s.data);s.length=strlen(s.data);printf("inputstringt:");gets(t.data);t.length=strlen(t.data);printf("inputstartposition:");scanf("%d”,&k);printf("BF:\ntheresultofBFis%d\n",index_bf(&s,&t,k));getNext(&t,next);printf("KMP:\n");printf("next[]:");for(i=0;i<t.length;i++)printf("%3d",next[i]);printf("\n");printf("theresultofKMPis%d\n",index_kmp(&s,&t,k,next));printf("\n***showover***\n");}intmain(){show_index();return0;}輸入:abcaabbabcabaacbacbaabcabaa運(yùn)行結(jié)果:Lop'Aifi-y■--nbc-Ei-Hbb-BlKffll>?AGlMGbflLflpptit9LrKiAlninh^frigmtDtArtpocitlan^lUP:tlieTis-nultci'BPii7MMF;^Kt11:-1a6B121Lhn『if蛔1電nfKMFi-Y■■u—sg?郵ptr-nrm-h-h!Frci^am*2cuntlinM?!】FlI^Ylcw|白I三、實驗小結(jié)通過對算法的運(yùn)行,加上思考可以深刻了解串的基本概念。并且可以掌握串的模式匹配算法的建立。四、教師評語實驗四二叉樹一、實驗?zāi)康?、掌握二叉樹的基本特性2、掌握二叉樹的遞歸遍歷算法3、理解二叉樹的非遞歸算法4、通過二叉樹的深度和層次遍歷算法,理解二叉樹的基本特性二、實驗內(nèi)容和要求1、閱讀并運(yùn)行下面程序,根據(jù)輸入寫出運(yùn)行結(jié)果,并畫出二叉樹的形態(tài)。#include<stdio.h>#include<malloc.h>#defineMAX20typedefstructBTNode{/節(jié)點(diǎn)結(jié)構(gòu)聲明*/chardata;節(jié)點(diǎn)數(shù)據(jù)*/structBTNode*lchild;structBTNode*rchild;/*指針*/}*BiTree;voidcreateBiTree(BiTree*t){/*先序遍歷創(chuàng)建二叉樹*/chars;BiTreeq;printf("\npleaseinputdata:(exitfor#)");s=getche();if(s=='#'){*t=NULL;return;}q=(BiTree)malloc(sizeof(structBTNode));if(q==NULL){printf("Memoryallocfailure!");exit(0);}q->data=s;*t=q;createBiTree(&q->lchild);/*遞歸建立左子樹*/createBiTree(&q->rchild);/*遞歸建立右子樹*/}voidPreOrder(BiTreep){/*先序遍歷二叉樹*/if(p!=NULL){printf("%c”,p->data);PreOrder(p->lchild);PreOrder(p->rchild);}}voidInOrder(BiTreep){/*中序遍歷二叉樹*/if(p!=NULL){InOrder(p->lchild);printf("%c”,p->data);InOrder(p->rchild);}}voidPostOrder(BiTreep){/*后序遍歷二叉樹*/if(p!=NULL){PostOrder(p->lchild);PostOrder(p->rchild);printf("%c”,p->data);}}voidPreorder_n(BiTreep){/*先序遍歷的非遞歸算法*/BiTreestack[MAX],q;inttop=0,i;for(i=0;i<MAX;i++)stack[i]=NULL;/初始化棧*/q=p;while(q!=NULL){printf("%c”,q->data);if(q->rchild!=NULL)stack[top++]=q->rchild;if(q->lchild!=NULL)q=q->lchild;elseif(top>0)q=stack[--top];elseq=NULL;}}voidrelease(BiTreet){/*釋放二叉樹空間*/if(t!=NULL){release(t->lchild);release(t->rchild);free(t);}}intmain(){BiTreet=NULL;createBiTree(&t);printf("\n\nPreOrderthetreeis:");PreOrder(t);printf("\n\nInOrderthetreeis:");InOrder(t);printf("\n\nPostOrderthetreeis:");
PostOrder(t);printf("\n\n先序遍歷序列(非遞歸):");Preorder_n(t);release(t);return0;}運(yùn)行程序輸入:ABC##DE#G##F###運(yùn)行結(jié)果:F:\C++WENJlANVDebug\^驗四舊加"pleaseinputdata:<exitfor1t)Apleaseinputdata:<exitforpleaseinputdata:<exitforpleaseinputdata:<exitfor乖)。pleaseinputdata:<exitfor乖)。pleaseinputdata:<exitforpleaseinputdata:<exitfor#)Epleaseinputdata:<exitforpleaseinputdata:<exitforpleaseinputdata:<exitforpleaseinputdata:<exitforpleaseinputdata:<exitfor#>Fpleaseinputdata:<exitfor#>#pleaseinputdata:<exitfor#>#pleaseinputdata:<exitfor#>#^reOrder*thetreeis:ABCDECFInOrderthetreeis:CBEGI>FAicastOrderthetreeis:CG£F])BA先序遍歷序列匚非遞歸1:ABCMGFPressanykeytocontinue2、在上題中補(bǔ)充求二叉樹中求結(jié)點(diǎn)總數(shù)算法(提示:可在某種遍歷過程中統(tǒng)計遍歷的結(jié)點(diǎn)數(shù)),并在主函數(shù)中補(bǔ)充相應(yīng)的調(diào)用驗證正確性。算法代碼:intPreOrder_num(BiTreep){intj=0;BiTreestack[MAX],q;inttop=0,i;for(i=0;i<MAX;i++)stack[i]=NULL;/初始化棧大/q=p;while(q!=NULL){j++;0if(q->rchild!=NULL)stack[top++]=q->rchild;if(q->lchild!=NULL)q=q->lchild;elseif(top>0)q=stack[--top];elseq=NULL;}returnj;}pleaseinputdata:(exitFoptt)Apleaseinuutdata:<exitFoptt>Binputdata:<exitfnvtncplInputdata:(exitFovtt)ttpleaseinputdata:<exitFoi*tt>ttplcaocInputdatas<exitFortt>Dpleaseinputdata.:<exitCor#)EInputdeltas<exitCur#>#pleaseinput(lata=<exitfurIDGpleaseinputdata-Cexitforn?npleaseinputdata:(exitforpleaseinputdata:Cexitforlt)Fpleaseinputdata:(exitforpleaseinputdata:CexitFop#>#pleaseinputdata:(exitforPreOi^devthetreeis:ABCDEGFInOrde]*thetree;is:CBEGDFAPtJBtOrdeit*tlieissCGEFDEA先序遍.萬序歹!口二遞歸):ABCDEGF輸山結(jié)點(diǎn)總教;anykey珈continue3、在上題中補(bǔ)充求二叉樹中求葉子結(jié)點(diǎn)總數(shù)算法(提示:可在某種遍歷過程中統(tǒng)計遍歷的葉子結(jié)點(diǎn)數(shù)),并在主函數(shù)中補(bǔ)充相應(yīng)的調(diào)用驗證正確性。算法代碼:intBTNodeDepth(BiTreep){intlchilddep,rchilddep;if(p==NULL)return0;else{lchilddep=BTNodeDepth(p->lchild);rchilddep=BTNodeDepth(p->rchild);return(lchilddep>rchilddep)?(lchilddep+1):(rchilddep+1);}??赲1LXhpleaseinputdata:(exit£op5pleaseinputdata:<exitf□!'fl>GiiuDiitdata:(exitfortDitpleaseinput:datza:(exitf□!*ID址pleaseirputdata-<exit£oi'IDFplcaccirputdata'<exit£oi*tl>ttplease±rputdata:<exitforpledgeinputdelta-(exitfar*ID林IpreOrderthetreeis:ABGDEGFInOrderthetreeis:UBEGDFHPDstOrdei'thetreeis:CGEFDBA異.序遍歷序利(非說IE)油BCDEGF萄5結(jié)點(diǎn)急救=?"id樹的深度瀉臨出樹叫子總數(shù);3(Fpbssanykey匚(1con七inuue4、在上題中補(bǔ)充求二叉樹深度算法,并在主函數(shù)中補(bǔ)充相應(yīng)的調(diào)用驗證正確性。算法代碼:intBTNodeDepth(BiTreep){
intlchilddep,rchilddep;if(p==NULL)return0;else{lchilddep=BTNodeDepth(p->lchild);rchilddep=BTNodeDepth(p->rchild);return(lchilddep>rchilddep)?(lchilddep+1):(rchilddep+1);}}yplea.sepleasepleaseplecisepleasepleasepleasepleasepleasepleaseuilea.seinput:inpuitInput;j.inputinputinputinputinputinputinputinput:da.ta.:(exitdmtm:Cexitdata:<exitdatci;<exitdata:Cexitdatayplea.sepleasepleaseplecisepleasepleasepleasepleasepleasepleaseuilea.seinput:inpuitInput;j.inputinputinputinputinputinputinputinput:da.ta.:(exitdmtm:Cexitdata:<exitdatci;<exitdata:Cexitdata:Cexitdata:(exitdata:<exitdata:(exitdata:<exitdata:(exit-fnr-fOJ?forforfOPforfOPforfOPforfDPttitttt>D#>E#>lt?>G#>##>F#>#tnIt[Tr-cOrdcrt]ietreeissflDCDEGF三、實驗小結(jié)掌握二叉樹的基本特性,以及對遞歸和非遞歸的了解。并且通過實驗對二叉樹在算法的應(yīng)用有了更深的理解。四、教師評語實驗五圖的表示與遍歷一、實驗?zāi)康?、掌握圖的鄰接矩陣和鄰接表表示2、掌握圖的深度優(yōu)先和廣度優(yōu)先搜索方法3、理解圖的應(yīng)用方法二、實驗內(nèi)容和要求1、閱讀并運(yùn)行下面程序,根據(jù)輸入寫出運(yùn)行結(jié)果。#include<stdio.h>#defineN20#defineTRUE1#defineFALSE0intvisited[N];typedefstruct/隊列的定義*/{intdata[N];intfront,rear;}queue;typedefstruct/圖的鄰接矩陣*/{intvexnum,arcnum;charvexs[N];intarcs[N][N];}graph;voidcreateGraph(graph*g);/*建立一個無向圖的鄰接矩陣*/voiddfs(inti,graph*g);/從第i個頂點(diǎn)出發(fā)深度優(yōu)先搜索*/voidtdfs(graph*g);深度優(yōu)先搜索整個圖*/voidbfs(intk,graph*g);/從第k個頂點(diǎn)廣度優(yōu)先搜索*/voidtbfs(graph*g);廣■度優(yōu)先搜索整個圖*/voidinit_visit();初始化訪問標(biāo)識數(shù)組*/voidcreateGraph(graph*g)/建立一個無向圖的鄰接矩陣*/{inti,j;charv;g->vexnum=0;g->arcnum=0;i=0;printf(輸入頂點(diǎn)序列(以#結(jié)束):\n");while((v=getchar())!='#')g->vexs[i]=v;i++;讀大頂點(diǎn)信息大/}g->vexnum=i;頂點(diǎn)數(shù)目*/for(i=0;i<g->vexnum;i++)/鄰接矩陣初始化*/for(j=0;j<g->vexnum;j++)g->arcs[i][j]=0;printf(輸入邊的信息:\n");scanf("%d,%d”,&i,&j);/讀入邊i,j*/while(i!=-1)讀入i,j為一1時結(jié)束*/{g->arcs[i][j]=1;g->arcs[j][i]=1;scanf("%d,%d”,&i,&j);}}voiddfs(inti,graph*g)/*從第i個頂點(diǎn)出發(fā)深度優(yōu)先搜索*/{intj;printf("%c”,g->vexs[i]);visited[i]=TRUE;for(j=0;j<g-〉vexnum;j++)if((g->arcs[i][j]==1)&&(!visited[j]))dfs(j,g);}voidtdfs(graph*g)/深度優(yōu)先搜索整個圖*/{inti;printf("\n從頂點(diǎn)%C開始深度優(yōu)先搜索序列:",g->vexs[0]);for(i=0;i<g->vexnum;i++)if(visited[i]!=TRUE)dfs(i,g);}voidbfs(intk,graph*g)/*從第k個頂點(diǎn)廣度優(yōu)先搜索*/{inti,j;queueqlist,*q;q=&qlist;q->rear=0;q->front=0;printf("%c”,g->vexs[k]);visited[k]=TRUE;q->data[q->rear]=k;q->rear=(q->rear+1)%N;while(q->rear!=q->front){i=q->data[q->front];q->front=(q->front+1)%N;for(j=0;j<g->vexnum;j++)if((g->arcs[i][j]==1)&&(!visited[j])){printf("%c”,g->vexs[j]);visited[j]=TRUE;q->data[q->rear]=j;q->rear=(q->rear+1)%N;}}}voidtbfs(graph*g)/*廣度優(yōu)先搜索整個圖*/{inti;printf("\n從頂點(diǎn)%C開始廣度優(yōu)先搜索序列:",g->vexs[0]);for(i=0;i<g->vexnum;i++)if(visited[i]!=TRUE)bfs(i,g);}voidinit_visit()/初始化訪問標(biāo)識數(shù)組*/{inti;for(i=0;i<N;i++)visited[i]=FALSE;}intmain(){graphga;inti,j;createGraph(&ga);printf(無向圖的鄰接矩陣:\n");for(i=0;i<ga.vexnum;i++){for(j=0;j<ga.vexnum;j++)printf("%3d”,ga.arcs[i][j]);printf("\n");}init_visit();tdfs(&ga);init_visit();tbfs(&ga);return0;}-根據(jù)右圖的結(jié)構(gòu)驗證實驗,輸入:ABCDEFGH#0,10,20,51,31,42,52,63,74,7-1,-1?運(yùn)行結(jié)果:2、閱讀并運(yùn)行下面程序,補(bǔ)充拓?fù)渑判蛩惴ā?include<stdio.h>#include<malloc.h>#defineN20typedefstructedgenode{/*圖的鄰接表:鄰接鏈表結(jié)點(diǎn)大/intadjvex;/預(yù)點(diǎn)序號大/structedgenode*next;/■下一個結(jié)點(diǎn)的指針大/}edgenode;typedefstructvnode{/大圖的鄰接表:鄰接表大/chardata;/頂點(diǎn)信息大/intind;頂點(diǎn)入度大/structedgenode*link;/指向鄰接鏈表指針大/}vnode;voidcreateGraph_list(vnodeadjlist[],int*p;/大建立有向圖的鄰接表大/voidtopSort(vnodeg[],intn);/大拓?fù)渑判虼?voidcreateGraph_list(vnodeadjlist[],int*p){/*建立有向圖的鄰接表大/inti,j,n,e;charv;edgenode*s;i=0;n=0;e=0;printf(輸入頂點(diǎn)序列(以#結(jié)束):\n");while((v=getchar())!='#'){adjlist[i].data=v;讀大頂點(diǎn)信息*/adjlist[i].link=NULL;adjlist[i].ind=0;i++;}n=i;*p=n;/建立鄰接鏈表*/printf("\ni青輸入弧的信息(i=-1結(jié)束):i,j:\n");scanf("%d,%d”,&i,&j);while(i!=-1){s=(structedgenode*)malloc(sizeof(edgenode));s->adjvex=j;s->next=adjlist[i].link;adjlist[i].link=s;adjlist[j].ind++;頂點(diǎn)j的入度加1*/e++;scanf("%d,%d”,&i,&j);}printf(鄰接表:");for(i=0;i<n;i++){/輸出鄰接表*/printf("\n%c,%d:",adjlist[i].data,adjlist[i].ind);s=adjlist[i].link;while(s!=NULL){printf("->%d”,s->adjvex);s=s->next;}}}voidtopSort(vnodeg[],intn){/*拓?fù)渑判?/voidtopSort(vnodeg[],intn){/*拓?fù)渑判?/intTopoSort(AdjListG){StackS;intindegree[MAX_VERTEX_NUM];inti,count,k;AreNode*p;FindID(G,indegree);InitStack(&s);for(i=0;i<G.vexnum;i++)if(indegree[i]==0)Push(&s,i)count=0;while(!IsEmpty(s)){Pap(&s,&i);}intmain(){vnodeadjlist[N];intn,*p;p=&n;createGraph_list(adjlist,p);return0;}-根據(jù)輸入,輸出有向圖的拓?fù)渑判蛐蛄?。并畫出有向圖。輸入:ABCDEF#0,11,22,34,14,5T,T?運(yùn)行結(jié)果:3、閱讀并運(yùn)行下面程序。#include<stdio.h>#defineN20#defineTRUE1#defineINF32766鄰接矩陣中的無窮大元素*/#defineINFIN32767比無窮大元素大的數(shù)*/typedefstruct{/大圖的鄰接矩陣大/intvexnum,arcnum;charvexs[N];intarcs[N][N];}graph;voidcreateGraph_w(graph*g,intflag);voidprim(graph*g,intu);voiddijkstra(graphg,intv);voidshowprim();voidshowdij();/大建帶權(quán)圖的鄰接矩陣,若flag為1則為無向圖,flag為0為有向圖大/voidcreateGraph_w(graph*g,intflag){inti,j,w;charv;g->vexnum=0;g->arcnum=0;i=0;printf(輸入頂點(diǎn)序列(以#結(jié)束):\n");while((v=getchar())!='#'){g->vexs[i]=v;讀入頂點(diǎn)信息*/i++;}g->vexnum=i;for(i=0;i<6;i++)鄰接矩陣初始化*/for(j=0;j<6;j++)g->arcs[i][j]=INF;printf(輸入邊的信息:\n");scanf("%d,%d,%d”,&i,&j,&w);/讀入邊(i,j,w)*/while(i!=-1)讀入i為一1時結(jié)束*/{g->arcs[i][j]=w;if(flag==1)g->arcs[j][i]=w;scanf("%d,%d,%d”,&i,&j,&w);}}voidprim(graph*g,intu)/*出發(fā)頂點(diǎn)u*/{intlowcost[N],closest[N],i,j,k,min;for(i=0;i<g->vexnum;i++)/求其他頂點(diǎn)到出發(fā)頂點(diǎn)u的權(quán)*/{lowcost[i]=g->arcs[u][i];closest[i]=u;}lowcost[u]=0;for(i=1;i<g->vexnum;i++)/盾環(huán)求最小生成樹中的各條邊*/{min=INFIN;for(j=0;j<g->vexnum;j++)選擇得到一條代價最小的邊*/if(lowcost[j]!=0&&lowcost[j]<min){min=lowcost[j];k=j;}printf("(%c,%c)--%d\n”,g->vexs[closest[k]],g->vexs[k],lowcost[k]);/*輸出該邊*/lowcost[k]=0;頂點(diǎn)k納入最小生成樹*/for(j=0;j<g->vexnum;j++)求■其他頂點(diǎn)到頂點(diǎn)k的權(quán)*/if(g->arcs[k][j]!=0&&g->arcs[k][j]<lowcost[j]){lowcost[j]=g->arcs[k][j];closest[j]=k;}}}voiddijkstra(graphg,intv){/*dijkstra算法求單源最短路徑*/intpath[N][N],dist[N],s[N];intmindis,i,j,u,k;for(i=0;i<g.vexnum;i++){dist[i]=g.arcs[v][i];s[i]=0;for(j=0;j<g.vexnum;j++)path[i][j]=0;if(dist[i]<INF){path[i][v]=1;path[i][i]=1;}}dist[v]=0;s[v]=1;for(i=0,u=1;i<g.vexnum;i++){mindis=INFIN;for(j=0;j<g.vexnum;j++)if(s[j]==0)if(dist[j]<mindis){u=j;mindis=dist[j];}s[u]=1;for(j=0;j<g.vexnum;j++)if((s[j]==0)&&dist[u]+g.arcs[u][j]<dist[j]){dist[j]=dist[u]+g.arcs[u][j];for(k=0;k<g.vexnum;k++)path[j][k]=path[u][k];path[j][j]=1;}}printf("\顧點(diǎn)%。->到各頂點(diǎn)的最短路徑\n",g.vexs[v]);for(i=0;i<g.vexnum;i++){printf("\頂點(diǎn)%。->頂點(diǎn)%c:",g.vexs[v],g.vexs[i]);if(dist[i]==INF)printf無路徑");else{printf("%d”,dist[i]);printf經(jīng)過頂點(diǎn):");for(j=0;j<g.vexnum;j++)if(path[i][j]==1&&i!=j)printf("->%c”,g.vexs[j]);printf("->%c\n”,g.vexs[i]);}}}voidshowprim()/*最小生成樹prim算法演示大/{graphga;createGraph_w(&ga,1);prim(&ga,0);voidshowdij(){/*dijstra算法演示*/graphga;createGraph_w(&ga,0);dijkstra(ga,0);}intmain(){showprim();/*prim算法演示*/getchar();showdij();/*dijstr算法演示*/return0;}下面的輸入分別驗證prim算法和dijstra算法。輸入的第一部分為無向圖,求其最小生成樹;輸入的第二部分為有向圖,求其最短路徑。ABCDEF#0,1,60,2,10,3,51,2,51,4,32,3,52,4,63,5,2-1,-1,-1ABCDEF#0,2,100,5,1000,4,302,3,503,4,203,5,104,3,204,5,60-1,-1,-1運(yùn)行結(jié)果:(并畫出兩個圖)<-■*€zffandtiniE\lidainiee!rntveXJS^SinKB,.H>--3輔入?點(diǎn)序列t以■拮卑>nEonii輸A邊的信息=—如%4.危。1-2-5P—5BI孔4皿LEulB4r3.307前頂點(diǎn)?卜,型苦頂點(diǎn)的條垣路隹皿點(diǎn)岳flT[.點(diǎn)土0,至邑頂點(diǎn)」-M頂無路匡項頁臼-可?女冬10豎詛頂點(diǎn).-MT口頂點(diǎn)ft->T^^BuEB經(jīng)過頂點(diǎn)I->i->E->E版點(diǎn)可7頊互E=3B{乏討頂點(diǎn)”-MTE頂點(diǎn)ft->Tl^Fu網(wǎng)經(jīng)過頂點(diǎn)I->i->C->E->FFitcti^r>jMycentinuo-v三、實驗小結(jié)學(xué)會了圖的鄰接矩陣和鄰接表表示,并了解深度優(yōu)先和廣度優(yōu)先搜索方法。理解圖的應(yīng)用方法四、教師評語實驗六查找一、實驗?zāi)康?、掌握查找表、動態(tài)查找表、靜態(tài)查找表和平均查找長度的概念。2、掌握線性表中順序查找和折半查找的方法。3、學(xué)會哈希函數(shù)的構(gòu)造方法,處理沖突的機(jī)制以及哈希表的查找。二、實驗內(nèi)容和要求靜態(tài)查找表技術(shù)依據(jù)順序查找算法和折半查找算法的特點(diǎn),對下面的兩個查找表選擇一個合適的算法,設(shè)計出完整的C源程序。并完成問題:查找表1:{8,15,19,26,33,41,47,52,64,90},查找key=41查找表2:{12,76,29,15,62,35,33,89,48,20},查找key=35查找key=41的比較次數(shù):查找key=35的比較次數(shù):算法實現(xiàn)代碼2、哈希表的構(gòu)造與查找/*采用開放地址法構(gòu)造哈希表*/#include<stdio.h>#include<malloc.h>#defineMAXSIZE25#defineP13#defineOK1#defineERROR0#defineDUPLICATE-1#defineTRUE1#defineFALSE0typedefstruct{/*哈希表元素結(jié)構(gòu)*/intkey;/*關(guān)鍵字值*/intflag;/*是否存放元素*/}ElemType;typedefstruct{ElemTypedata[MAXSIZE];intcount;/*元素個數(shù)*/intsizeindex;/*當(dāng)前哈希表容量*/}HashTable;intd1[15]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14};/*線性探測序列*/intd2[15]={0,1,-1,2*2,-2*2,3*3,-3*3,4*4,-4*4,5*5,-5*5,6*6,-6*6,7*7,-7*7};/*二次探測序列*/voiddataset(intds[],int*len);intInsertHash(HashTable*H,inte,intd[]);intCreateHash(HashTable*H,intds[],intlen,intd[]);intSearchHash(HashTable*H,inte,intd[]);voidmenu();/*輸入查找表*/voiddataset(intds[],int*len){intn,m;n=0;printf("\n查找表輸入:");while(scanf("%d”,&m)==1){/*以輸入一個非整數(shù)作為結(jié)束*/ds[n]=m;n++;}*len=n;}/*計算哈希地址,插入哈希表*/intInsertHash(HashTable*H,inte,intd[]){intk,i=1;k=e%P;while(H->data[k].flag==TRUE||k<0){k=(e%P+d[i])%MAXSIZE;i++;if(i>=15)returnERROR;}H->data[k].key=e;H->data[k].flag=TRUE;H->count++;returnOK;}/*構(gòu)造哈希表*/intCreateHash(HashTable*H,intds[],intlen,intd[]){inti;for(i=0;i<len;i++){if(SearchHash(H,ds[i],d)!=-1)returnDUPLICATE;InsertHash(H,ds[i],d);if(H->count>=MAXSIZE)returnERROR;}returnOK;}/*初始化哈希表*/voidInitHash(HashTable*H){inti;for(i=0;i<MAXSIZE;i++){H->data[i].key=0;H->data[i].flag=FALSE;}}/*在哈希表中查找*/intSearchHash(HashTable*H,inte,intd[]){intk,i=1;k=e%P;while(H->data[k].key!=e){k=(e%P+d[i])%MAXSIZE;i++;if(i>=15)return-1;}returnk;}/*演示菜單*/voidmenu(){intchoice;int*p;H
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024廣東省林地流轉(zhuǎn)買賣合同
- 2024法律顧問委托合同
- 2024民間抵押借款合同民間借貸合同范本
- 2024房屋裝修合同(范本)
- 新車銷售合同范本樣式
- 不動產(chǎn)抵押借款合同范本解析
- 2024蔬菜買賣合同示范文本
- 2024年墻面裝飾分包工程合同
- 合租住房協(xié)議書樣本
- 投資項目資金監(jiān)管合同
- 云南省學(xué)校食堂“六T”管理檢查評分標(biāo)準(zhǔn)
- 腫瘤細(xì)胞代謝與腫瘤微環(huán)境課件
- 工程建設(shè)項目招投標(biāo)領(lǐng)域整治強(qiáng)調(diào)發(fā)言
- 腹部閉合性損傷護(hù)理查房課件
- 裴禮文數(shù)學(xué)分析中的典型問題與方法第二版習(xí)題參考解答
- 高考模擬作文寫作:“如何辨別取舍信息”導(dǎo)寫(附:寫作指導(dǎo)及范文點(diǎn)評)
- KF思維技術(shù)-在合作中解決問題與決策完整課件
- 壓裂優(yōu)化設(shè)計理論及案例
- 喜馬拉雅有聲書用戶行為市場報告課件
- 《汽車服務(wù)企業(yè)管理》試題及參考答案A
- 腦梗死培訓(xùn)課件
評論
0/150
提交評論