您好,欢迎访问三七文档
当前位置:首页 > IT计算机/网络 > 数据挖掘与识别 > 新版数据结构期中试卷及答案-新版.pdf
2301.DABCD2DAB.C.D.3AABCD49026BA98B100C102D1065DABCD6(D)ABCD7(A)ABCD8123456BA326145B342165C125346D5642319.123nnkCAkBn-k-1Cn-k+1D10.AA.B.C.D.11.CA.B.C.D.12frontrearAAfront=front-nextBrear=rear-nextCrear-next=frontDfront-nextrear13.BABCD14.CABCD15.BA.B.C.D.2201_______2_________________3_______4nkLoc(a1)iLoc(ai)=Loc(a1)+(i-1)*k5stack___________________6QQ.frontQ.rearMaxQSizeQ.rear==Q.front,(Q.rear+1)%MaxQSize==Q.front(.rear-Q.front+MaxQSize)%MaxQSize73301.LieCLtypedefstructnode{intdatastructnode*next}linknode,*linkintListInsert_L(link&L,inti,inte){Linknode*pintjp=Lj=0while(p&&ji-1){p=p-next++j}//i-1if(!p||ji-1)return0s=(link)malloc(sizeof(linknode))//ss-data=es-next=p-nextp-next=s//Lreturn1}\2.Ctope#defineSTACK_INIT_SIZE100#defineSTACKINCREMENT10typedefstruct{char*base;char*top;intstacksize;}SqStack;intPush(SqStack&S,chare){//if((s.top-s.base)=s.stacksize)//{S.base=(SElemType*)realloc(S.base,S.stacksize+STACKINCREMENT)*sizeof(SElemType))if(!S.base)return0S.top=s.base+s.stacksize//S.stacksize+=STACKINCREMENT}*s.top++=e//return1}3.CQetypedefstructQNode{QElemTypedatastructQNode*next}QNode,*QueuePtrtypedefstruct{QueuePtrfrontQueuePtrrear}LinkQueueintDeQueue(LinkQueue&Q,QElemType&e){Linknode*pif(Q.front==Q.rear)retrun0//p=Q.front-nexte=p-dataQ.front-next=p-next//if(Q.rear==p)Q.rear=Q.front//free(p)//return1}102015101typedefstructLNode{Chardata;structLNode*next;}LNode,*LinkList;LinkListDemo(LinkList&L){//LLNode*Q,*P;if(L&&L-next){Q=L;L=L-next;P=L;while(P-next)P=P-next;P-next=Q;Q-next=NULL;}returnL;}//Demo2#defineSTACK_INIT_SIZE100#defineSTACKINCREMENT10typedefstruct{int*base;int*top;intstacksize;}Stack;voidDemo1(Stack&S,intm){StackT;inti;InitStack(T);//while(!StackEmpty(S))//if((i=Pop(S))!=m)Push(T,i);//while(!StackEmpty(T)){i=Pop(T);//Push(S,i);}}Sm2.headXtypedefstructnode{intdata;structnode*next;}linknode,*link;intsample(linkhead,intX){intcount=0;linkp=head-next;while(p){if(p-data==X)count++;p=p-next;}returncount;}
本文标题:新版数据结构期中试卷及答案-新版.pdf
链接地址:https://www.777doc.com/doc-1787154 .html