2015-2016学年《数据结构与算法》线性结构测验.doc
2015-2016学年《数据结构与算法》线性结构测验
答案
一、程序填空题(每分,共分)空号 答 空号 答 【1】 【2】 【3】 【4】 【5】 【6】 【7】 【8】
Q.front==Q.rear 【9】 【10】 【11】 【12】 【13】 -1] 【14】 【15】 【16】i=La_len j=Lb_len 【17】 1,ai); i++; 【1】 1,bj); j++; 【19】 GetElem(La,i++,ai);ListInsert(Lc,1,ai); 【20】 GetElem(Lb,j++,bj);ListInsert(Lc,1,bj); 【21】 p=L; 【22】 NULL 【23】 x 【24】 c或p-next 【25】 c-next=q 【26】 InitStack(S); 【27】 Push(S,ch); 【28】 Pop(S, t); 【29】 scanf(ch); 【30】 StackEmpty(S) 二、简答题(分)
顺序栈:
typedef struct
{ SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
循环队列
typedef struct
{QElemType *base; //初始化的动态分配存储空间
int front; //头指针,若队列不空,指向队列头元素
int rear; //尾指针,若队列不空,指向队列尾元素的下一个位置
}SqQueue;
4、O(na*nb)
三、算法设计题(24分)
1、
int Delete(Ptr L,int min,int max)
{
Node *p,*q;
int number=0;
p=L;
q=L-next;
while(q)
{
if(q-datamin)
break;
if(q-datamax q-datamin)
{
number++;
p-next=q-next;
free(q);
}
else
p=q;
q=p-next;
}
return number;
}
方法二:
int Delete(Ptr L,int min,int max)
{
Node *p,*q;
int number=0,len,i;
len=
for(i=1; i= ListLength(L);)
{ GetElem(L,i,e);
if(emin)
break;
if(emax emin)
{
number++;
ListDelete(L,i,e);
}
else
i++;
}
return number;
}
2、
#define MaxQSize 100
typedef struct
{
QElemType *base;
int front;
int length;
}SqQueue;
Status EnQueue(SqQueue Q,QElemTpe e)
{
int rear;
rear=(Q.front+Q.length )%MaxQSize;
if((rear+1) % MaxQSize==Q.front) // if(rear==Q.front)
return ERROR;
Q.base[rear]=e;
Q.length++;
return OK;
}
Status DeQueue(SqQueue Q,QElemType e)
{ int rear;
if(Q.length==0) //if( (Q.front+Q.length )%MaxQSize==Q.front)
return ERROR;
e=Q.base[Q.front];
Q.front=(Q.front+1)%MaxQSize;
Q.length--;
return OK;
}
3、
void change(Queue Q)
{ ElemType e;
Stack S;
InitStack(S);
while(!QueueEmpty(Q))
{
DeQueue(Q,e);
if(emin || emax)
push(S,e);
}
while(!StackEmpty(S))
{
pop(S,e
您可能关注的文档
最近下载
- 图案变化与统一课件设计.pptx VIP
- 2025年金融风险管理师买入看跌期权与卖出看跌期权策略专题试卷及解析.pdf VIP
- 2025年拍卖师拍卖谈判中的谈判记录与总结技巧专题试卷及解析.pdf VIP
- 2025年房地产经纪人客户隐私保护监管政策解读专题试卷及解析.pdf VIP
- 基于单片机的数控直流稳压电源的设计.docx VIP
- 县域消费扶贫与长效帮扶机制分析.pdf VIP
- 2025年项目管理专业项目交付成果验收检查表编制专题试卷及解析.pdf VIP
- 煤矿露天改扩建项目竣工验收报告.docx
- 人体解剖学复习测试有答案(二).doc VIP
- 基于stm32的智能小车设计毕业设计论文.docx VIP
原创力文档

文档评论(0)