电子科技数据结构教案_第1页
电子科技数据结构教案_第2页
电子科技数据结构教案_第3页
电子科技数据结构教案_第4页
电子科技数据结构教案_第5页
已阅读5页,还剩168页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

数据结构 Huo …………002,004,001,003,004,L002,SHuo ···························· Huo 例3多叉 1 1

4 Huo 。Huo 。Huo

Huo 树树串Huo 是指数据的逻辑结构在计算机中的映象,即表示。映象Huo 顺序机构是逻辑上相邻的数据元素存锗在物理位置上相毗邻的单元里,元素的关系由单元的邻接关系来体 Huo 1.4 输入输出Huo

1.4Huo 1.4算法和算法分析定义:如果存在两个正常数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 数据结构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

地址内存状态位序 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 从链表的头指针出发,顺链域next逐个结点往下搜索,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循环链表是一种头尾相接的链表。其特点是无须增加,仅对表的方式稍作改变,即可使得表处理更加方便灵。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,即结点*p的存储位置既存放在其前趋结点*(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 数据结构Stackand栈3.2.5

Huo

Huo 栈–ADT数据对象:D={ai|ai˛ElemSet,i=1,2,…,n,n‡0}数据关系: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队列的链式结构简称为链队列,它是限制仅在表头删除和表入的单链表。显然仅有单链表的头指针不便于在表尾做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–队列的顺序结构称为顺序队列,顺序队列实际上是运算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 数据结构第四章串 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中出现;若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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论