電子科技數(shù)據(jù)結(jié)構(gòu)教案_第1頁
電子科技數(shù)據(jù)結(jié)構(gòu)教案_第2頁
電子科技數(shù)據(jù)結(jié)構(gòu)教案_第3頁
電子科技數(shù)據(jù)結(jié)構(gòu)教案_第4頁
電子科技數(shù)據(jù)結(jié)構(gòu)教案_第5頁
已閱讀5頁,還剩168頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

數(shù)據(jù)結(jié)構(gòu) Huo …………002,004,001,003,004,L002,SHuo ···························· Huo 例3多叉 1 1

4 Huo 。Huo 。Huo

Huo 樹樹串Huo 是指數(shù)據(jù)的邏輯結(jié)構(gòu)在計算機中的映象,即表示。映象Huo 順序機構(gòu)是邏輯上相鄰的數(shù)據(jù)元素存鍺在物理位置上相毗鄰的單元里,元素的關系由單元的鄰接關系來體 Huo 1.4 輸入輸出Huo

1.4Huo 1.4算法和算法分析定義:如果存在兩個正常數(shù)c和n0nn0

Huo 1.4語句頻度為:2nHuo 1.4算法和算法分析定理:若A(n)=amnm+am-1nm-1+…+a1n+a0是一個m次多項式,則Huo 1.4算法和算法分析例5–1+2+3+…+n-2=(1+n-2)×(n-2)/2=(n-1)(n-2)/2=n2-Huo 1.4算法和算法分析–O(1)<O(logn)<O(n)<O(nlogn)<O(n2)<–Huo 1.4算法和算法分析voidbubble-sort(inta[],intfor(i=n-1;change=TURE;i>1&&change;--i){if(a[j]>a[j+1])a[j]?a[j+1];change=TURE;}}Huo 1.4 Huo 1.4算法和算法分析空間復雜度(SpaceComplexity):算法所需 Huo 數(shù)據(jù)結(jié)構(gòu)LinearHuo (A,B,C,…例2某校 Huo 例3男女男男Huo Huo voidunion(List&La,ListLb)

} Huo voidmergelist(listLa,listLb,list

else{ListInsert(Lc,++k,bj);++j;}{Ge { }Huo Huo 2.2線性表的順 #defineListSize100typedefintElemType;typedefstruct{ElemType

地址內(nèi)存狀態(tài)位序 int}

b+n Huo Huo voidInsertList(Sqlist*L,ElemTypex,int{intif(i<1||{printf(“Positionerror”);returnERROR}{

}

Huo Huo 2.2線性表的順 Eis(n)=(n-i+1)/(n+1)=n/2Huo 2.2線性表的順 Huo 2.2線性表的順 void ist(Sqlist*L,int{intif(i<1||{printf(“Positionerror”);returnERROR;}

Huo 2.2線性表的順 Edl(n)=pi(n-i)(i=1,…,n)Huo 2.2線性表的順 Huo 2.3 Huo

2.3 … (b)空H

Huo 2.3……

LNode }LnodeH…

…Huo 2.3LNodelinklist–Huo 2.3Huo charlinklist charlinklisthead;LNode

whilereturn}}

Huo linklistcreater( ){charch;linklistLNode*p,*r; //(,*head;)while((ch=getchar()!=‵’\n′){

{head=p;r=p;}

}

if}Huo Huo 2.3Huo 2.3…H

Huo 2.3linklist istr1(charch;linklisthead;

printf(“Nospacefornodecanbeobtained”);returnERROR;}LNodewhile((ch=getchar())!=‵\n′{}}

Huo 2.3 從鏈表的頭指針出發(fā),順鏈域next逐個結(jié)點往下搜索,Huo LNode*getnode(linklisthead,intj;LNode*p;while(p–>next&&j<i){

inti)}

ifreturn}

return

Huo 2.3LNode*locatenode(linklisthead,int{LNode*p=head–>next;while(p&&p–>data!=key)returnp;

}Huo 2.3 Huo 2.3voidinsertnode(linklisthead,ElemTypex,int{LNode*p,*q;

error(“positionq=(LNode

Huo 2.3Huo 2.3void ist(linklisthead,int{LNode*p,*r;

if(p==NULL||p–>next==NULL)returnERROR;r=p–>next;(r)}

Huo 2.3。Huo 2.3循環(huán)鏈表是一種頭尾相接的鏈表。其特點是無須增加,僅對表的方式稍作改變,即可使得表處理更加方便靈。Huo 2.3…HHuo 2.3(rfinext) rHuo 2.3 Huo 2.3 …linklistconnect(linklistra,linklistrb){linklist… }

P352.13

Huo 2.3 typedefstructDuLNode{ElemTypedata;structDuLNodetypedefDuLNode*dlinklist;dlinklisthead;Huo 2.3 –(pfiprior)finextppfinext)fiprior,即結(jié)點*p的存儲位置既存放在其前趨結(jié)點*(pfiprior)的直接后繼指針域。Huo 2.3voiddinsertbefor(DuLNode*p,ElemType{ p—x xsHuo 2.3voidddeletenode(dlistnode{}Huo 3x2+2x+ (3258x+x2+

(87(103Huo 3x2001+(4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000Huo 0000000000000000000000000000000000000000000000000000000000000000000000000000000000

000000000000000000000000000000000000000000000000000000003x2001+–(<4 <3?3340Huo 15+10x50p445030q3340Huo 數(shù)據(jù)結(jié)構(gòu)Stackand棧3.2.5

Huo

Huo 棧–ADT數(shù)據(jù)對象:D={ai|ai?ElemSet,i=1,2,…,n,n?0}數(shù)據(jù)關系:R1={<ai-1,ai>|ai-1,ai?D,i=1,2,…,n} …–…Huo

4

#defineSTACK_INIT_SIZE100;//#defineSTACKINCREMENT10; typedefcharSElemType;typedefstruct{

5int5Huo

/*Constructanemptystack/*Destroythestack/*Setstacktobeempty/*Returnthenumberofelementsinthestack Push(&S,e/*addelementetothetopofthestack–Pop(&S,&e/*removeanelementefromthetopoftheStackEmpty(S

/*ReturnTRUEifempty/*Returntheelementatthetop,withoutdeletingitHuo

–假設棧S=(a1,a2,a3,…,an),則出表(LastInFirstOut,LIFO)。

…Huo

#defineSTACKINCREMENTtypedefcharSElemType;typedefstruct{

intHuo

…S.top-

Huo 棧 AFEAFEDCBA

BABAHuo 棧voidInitStack(SqStack*S){S.base=(SElemType*)}–intStackEmpty(SqStack*S){}Huo 棧intStackFull(SqStack*S){}voidPush(SqStack*S,SElemTypee)if(StackFull(S))error(“stack}Huo 棧voidPop(SqStack*S,SElemType{}Huo 棧voidSElemTypeGetTop(SqStack*S,SElemType{error(“stackisempty”);}Huo

typedefstruct{SElemTypedata;structstacknode*next;}

data Huo 棧voidInitStack(SqStack{}–intStackEmpty(linkstack{return}Huo 棧voidPush(linkstack*p,SElemType{stacknode*q;p–>top=q//}Huo –退棧{

Pop(linkstack

return}Huo –取棧頂元{

GetTop(linkstackerror(“stackisempty.”);return}Huo

N=(Ndivd)*d+NmodNNdivNmod025202Huo scanf scanf }44

}}Huo voidconversion() }4040

}}Huo voidconversion() }504504

}}Huo voidconversion() }25042504

}Huo voidconversion()scanf(“%d”,&n);}}}2504

Huo

22voidconversion()scanf(“%d”,&n);

}}while(!}405Huo

22voidconversion()scanf(“%d”,&n);

}}}}0while(!4 Huo voidconversion()scanf(“%d”,&n);

}}4}while(! Huo voidconversion()scanf(“%d”,&n);

}}} 25 Huo (()()Huo

實際輸出:WhileHuo voidch=gether();

{while(ch!=EOF&&ch!=‘\n’){casecase‘#’case‘@’default }}

Huo

Huo typedefstruct

PostTypeseat;intdi;

voidMazePath(MazeTypemaze,PostTypestart,PosTypeend){InitStack(S);curpos=start;//設定當前位置為 doif(Pass(curpos))/

if(curpos==end)return(TRUE);//到達終點 Huo 3.2 while(e.di==4&&}e.di++;Push(S,e);}Huo Huo ???

Huo

3.2Huo OperandTypeEvaluateExpression(){InitStack(OPTR);Push(OPTR,’#’);InitStack(OPND);c=getchar();while(c!=‘#’||GetTop(OPTR)!=‘#’){ case‘<’: case‘=’: Huo case}returnHuo 2.31#2#3334356789###Huo : Fib(n)= 1

ifn=0ifn>0

ifn=0if Ack(m,n)= n+1Ack(m-1,

ifAck(m-1,Ack(m,n- Huo intfac(int{if(n<=1)return1;}voidmain(){return;}Huo n階HanoiHuo 3.3Basecase:nBasecase:n= Huo Basecase:nBasecase:n= Huo 3.3Recursion:n>前n-1個盤:Recursion:n> Huo 3.3Recursion:n>前n-1個盤:Recursion:n> Huo 3.3Recursion:n>最大盤:Recursion:n> Huo 3.3Recursion:n>最大盤:Recursion:n> Huo 3.3Recursion:n>前n-1個盤:Recursion:n> Huo 3.3Recursion:n>前n-1個盤:Recursion:n> Huo 3.3ActedastemporaryActedastemporaryholdingpeg.Recursion:n> Huo 3.3voidhanoi(intn,charx,chary,charelse Huo 3.4

Huo

3.4列。因此隊列亦稱作先進先出(FirstInFirstOut)的線性表,簡稱FIFO表。Huo

3.4隊列的鏈式結(jié)構(gòu)簡稱為鏈隊列,它是限制僅在表頭刪除和表入的單鏈表。顯然僅有單鏈表的頭指針不便于在表尾做Huo

3.4typedefstructQElemTypedata;structQNode*next;}QNode,*QueuePtr;typedefstruct{}

Huo

3.4xxyx…yx…

yxyxHuo 3.4voidInitQueue(LinkQueue&Q){}intQueueEmpty(LinkQueue}

&Q)Huo 3.4voidEnQueue(LinkQueue&Q,QElemType{QNodep=(QNode*)malloc(sizeof(QNode));}Huo 3.4{QElemTypex;QNode*preturn}Huo {error(“queueisempty.”);return}Huo 3.4–隊列的順序結(jié)構(gòu)稱為順序隊列,順序隊列實際上是運算Huo 3.4012

abc bc (c)a出 Huo

Huo

………0…01Huo

if(i+1==Huo

3.4

4 40

3j 3 3j7

5

3 Huo 3.4Huo 3.4#defineMAXQSIZE100typedefcharQElemType;typedefStruct{intfront;//頭指針,若隊列不空,指向隊列頭元素intHuo 3.4–voidInitQueue(SqQueue&Q)if(!Q.base)exit(OVERFLOW);return;}Huo 3.4intQueueEmpty(SqQueueQ){return(Q–>count==0);}intQueueFull(SqQueueQ)return}Huo 3.4voidEnQueue(SqQueue&Q,QElemType{error(“queueoverflow”);}Huo 3.4SElemTypeQeQueue(SqQueue&Q,QElemType{}Huo 3.4QElemTypeQueueFront(SqQueue{error(“queueisempty.”);return}Huo 數(shù)據(jù)結(jié)構(gòu)第四章串 Huo

為零的串稱為空串(NullString),它不包含任何字符。例如,設A和BA=“Thisisastring”,B=“is”Huo

intStrLength(StringS); charHuo

charStrchr(Strings,charHuo #defineMAXSTRLEN

typedefunsignedcharSString[MAXSTRLEN+1];SStrings; //s是一個可容納255個字符的順序串Huo

(a)Huo

(bS1[0]<MAXSTRLENHuo

(C)Huo 7N27N2M…abstudentar…Huo hgfehgfedcbaij## Huo Huo 稱模式t在目標s中出現(xiàn);若s[i..i+m-1≠t[0..m-1],則Huo intIndex(SStringS,SStringT,intpos){i=pos;j=1;while(i<=S[0]&&if(S[i]==T[j]){++i;els

溫馨提示

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

最新文檔

評論

0/150

提交評論