早教吧作业答案频道 -->其他-->
数据结构的题目第一题答案已经给出来了想要知道具体过程!1.假设以数组S[0..m-1]作为循环队列的存储结构,同时设变量front和rear分别指向队头元素的前一个位置和队尾元素位置,则队列中元素
题目详情
数据结构的题目
第一题答案已经给出来了 想要知道具体过程!
1.假设以数组S[0..m-1]作为循环队列的存储结构,同时设变量front和rear分别指向队头元素的前一个位置和队尾元素位置,则队列中元素个数为 (rear-front+m)%m .
2.指出下述程序段的功能是什么?
(1) void Demo1(SeqStack *S){
int i; arr[64] ; n=0 ;
while ( StackEmpty(S)) arr[n++]=Pop(S);
for (i=0,i< n; i++) Push(S,arr[i]);
} //Demo1
(2) SeqStack S1,S2,tmp;
DataType x;
...//假设栈tmp和S2已做过初始化
while ( StackEmpty (&S1))
{
x=Pop(&S1) ;
Push(&tmp,x);
}
while ( StackEmpty (&tmp) )
{
x=Pop( &tmp);
Push( &S1,x);
Push( &S2,x);
}
(3) void Demo2( SeqStack *S,int m)
{ // 设DataType 为int 型
SeqStack T; int i;
InitStack (&T);
while StackEmpty( S))
if(( i=Pop(S)) =m) Push( &T,i);
while StackEmpty( &T))
{
i=Pop(&T); Push(S,i);
}
}
(4)void Demo3( CirQueue *Q)
{ // 设DataType 为int 型
int x; SeqStack S;
InitStack( &S);
while QueueEmpty( Q ))
{x=DeQueue( Q); Push( &S,x);}
while StackEmpty( &s))
{ x=Pop(&S); EnQueue( Q,x );}
}// Demo3
(5) CirQueue Q1,Q2; // 设DataType 为int 型
int x,i ,n= 0;
...// 设Q1已有内容,Q2已初始化过
while ( QueueEmpty( &Q1) )
{ x=DeQueue( &Q1 ) ; EnQueue(&Q2,x); n++;}
for (i=0; i< n; i++)
{ x=DeQueue(&Q2) ;
EnQueue( &Q1,x) ; EnQueue( &Q2,x);}
第一题答案已经给出来了 想要知道具体过程!
1.假设以数组S[0..m-1]作为循环队列的存储结构,同时设变量front和rear分别指向队头元素的前一个位置和队尾元素位置,则队列中元素个数为 (rear-front+m)%m .
2.指出下述程序段的功能是什么?
(1) void Demo1(SeqStack *S){
int i; arr[64] ; n=0 ;
while ( StackEmpty(S)) arr[n++]=Pop(S);
for (i=0,i< n; i++) Push(S,arr[i]);
} //Demo1
(2) SeqStack S1,S2,tmp;
DataType x;
...//假设栈tmp和S2已做过初始化
while ( StackEmpty (&S1))
{
x=Pop(&S1) ;
Push(&tmp,x);
}
while ( StackEmpty (&tmp) )
{
x=Pop( &tmp);
Push( &S1,x);
Push( &S2,x);
}
(3) void Demo2( SeqStack *S,int m)
{ // 设DataType 为int 型
SeqStack T; int i;
InitStack (&T);
while StackEmpty( S))
if(( i=Pop(S)) =m) Push( &T,i);
while StackEmpty( &T))
{
i=Pop(&T); Push(S,i);
}
}
(4)void Demo3( CirQueue *Q)
{ // 设DataType 为int 型
int x; SeqStack S;
InitStack( &S);
while QueueEmpty( Q ))
{x=DeQueue( Q); Push( &S,x);}
while StackEmpty( &s))
{ x=Pop(&S); EnQueue( Q,x );}
}// Demo3
(5) CirQueue Q1,Q2; // 设DataType 为int 型
int x,i ,n= 0;
...// 设Q1已有内容,Q2已初始化过
while ( QueueEmpty( &Q1) )
{ x=DeQueue( &Q1 ) ; EnQueue(&Q2,x); n++;}
for (i=0; i< n; i++)
{ x=DeQueue(&Q2) ;
EnQueue( &Q1,x) ; EnQueue( &Q2,x);}
▼优质解答
答案和解析
1.假设以数组S[0..m-1]作为循环队列的存储结构,同时设变量front和rear分别指向队头元素的前一个位置和队尾元素位置,则队列中元素个数为 (rear-front+m)%m .
对于普通队列,如果变量front和rear分别指向队头元素的前一个位置和队尾元素位置,则队列中元素个数为 rear-front .
考虑到这里是循环队列,所以队列中元素个数为 (rear-front+m)%m.
2.指出下述程序段的功能是什么?
(1) void Demo1(SeqStack *S){
int i; arr[64] ; n=0 ;
while ( StackEmpty(S)) arr[n++]=Pop(S);
for (i=0,i< n; i++) Push(S,arr[i]);
} //Demo1
把栈S里的元素逆序.
(2) SeqStack S1,S2,tmp;
DataType x;
...//假设栈tmp和S2已做过初始化
while ( !StackEmpty (&S1))
{
x=Pop(&S1) ;
Push(&tmp,x);
}
while ( !StackEmpty (&tmp) )
{
x=Pop( &tmp);
Push( &S1,x);
Push( &S2,x);
}
把栈S1中的元素按序(注意不是逆序)添加到栈S2中
(3) void Demo2( SeqStack *S,int m)
{ // 设DataType 为int 型
SeqStack T; int i;
InitStack (&T);
while (!StackEmpty( S))
if(( i=Pop(S)) !=m) Push( &T,i);
while (!StackEmpty( &T))
{
i=Pop(&T); Push(S,i);
}
}
删除栈S中值为m的元素
(4)void Demo3( CirQueue *Q)
{ // 设DataType 为int 型
int x; SeqStack S;
InitStack( &S);
while (!QueueEmpty( Q ))
{x=DeQueue( Q); Push( &S,x);}
while (!StackEmpty( &s))
{ x=Pop(&S); EnQueue( Q,x );}
}// Demo3
把Q的元素逆序.
(5) CirQueue Q1,Q2; // 设DataType 为int 型
int x,i ,n= 0;
...// 设Q1已有内容,Q2已初始化过
while ( !QueueEmpty( &Q1) )
{ x=DeQueue( &Q1 ) ; EnQueue(&Q2,x); n++;}
for (i=0; i< n; i++)
{ x=DeQueue(&Q2) ;
EnQueue( &Q1,x) ; EnQueue( &Q2,x);}
把Q1的元素按序复制到Q2中
对于普通队列,如果变量front和rear分别指向队头元素的前一个位置和队尾元素位置,则队列中元素个数为 rear-front .
考虑到这里是循环队列,所以队列中元素个数为 (rear-front+m)%m.
2.指出下述程序段的功能是什么?
(1) void Demo1(SeqStack *S){
int i; arr[64] ; n=0 ;
while ( StackEmpty(S)) arr[n++]=Pop(S);
for (i=0,i< n; i++) Push(S,arr[i]);
} //Demo1
把栈S里的元素逆序.
(2) SeqStack S1,S2,tmp;
DataType x;
...//假设栈tmp和S2已做过初始化
while ( !StackEmpty (&S1))
{
x=Pop(&S1) ;
Push(&tmp,x);
}
while ( !StackEmpty (&tmp) )
{
x=Pop( &tmp);
Push( &S1,x);
Push( &S2,x);
}
把栈S1中的元素按序(注意不是逆序)添加到栈S2中
(3) void Demo2( SeqStack *S,int m)
{ // 设DataType 为int 型
SeqStack T; int i;
InitStack (&T);
while (!StackEmpty( S))
if(( i=Pop(S)) !=m) Push( &T,i);
while (!StackEmpty( &T))
{
i=Pop(&T); Push(S,i);
}
}
删除栈S中值为m的元素
(4)void Demo3( CirQueue *Q)
{ // 设DataType 为int 型
int x; SeqStack S;
InitStack( &S);
while (!QueueEmpty( Q ))
{x=DeQueue( Q); Push( &S,x);}
while (!StackEmpty( &s))
{ x=Pop(&S); EnQueue( Q,x );}
}// Demo3
把Q的元素逆序.
(5) CirQueue Q1,Q2; // 设DataType 为int 型
int x,i ,n= 0;
...// 设Q1已有内容,Q2已初始化过
while ( !QueueEmpty( &Q1) )
{ x=DeQueue( &Q1 ) ; EnQueue(&Q2,x); n++;}
for (i=0; i< n; i++)
{ x=DeQueue(&Q2) ;
EnQueue( &Q1,x) ; EnQueue( &Q2,x);}
把Q1的元素按序复制到Q2中
看了 数据结构的题目第一题答案已经...的网友还看了以下:
500mL溶质质量分数40%,密度为1.41的硫酸铬溶液.来配置1000mL浓度为1000mg/L 2020-04-09 …
初二数学证明题 如图,在△ABC中,已知D是BC的中点,DF⊥AB于F,DE⊥AC于E,且DF=D 2020-06-27 …
|E-A|=|AA^T-A|=|A(A^T-E^T)|,其中A是转置矩阵,为什么这里E也要跟着转置 2020-07-09 …
中秋节到了,学校组织举行庆祝活动,在长为72米的主道口上放置一盆花,再每隔3米放置一盆.后来由于其 2020-07-17 …
中秋节到了,学校举行庆祝活动,在长为72米的主道口上放置一盆花,再每隔3米放置一盆,后来由于其他地 2020-07-20 …
学校举行庆祝活动,在长为72米的朱道口上放置一盆花,再每隔3米放置一盆,后来由于其他地方也要放置花 2020-07-20 …
q为负电荷时计算场强电势电势能电势差的时候要不要带符号?比如E=F/qF=3*10^-3Nq为负电 2020-07-20 …
设置圈梁的位置一般在( )。A.外墙B.门窗C.女儿墙D.框架柱E.主要内墙 2020-08-30 …
某校(40°N,120°E)安置一个太阳能热水器,为了获得最多的太阳光热,提高利用效率,要根据太阳高 2020-12-06 …
置换反应需要元素全部被置换出来吗钠加水出于置换反应吗Na+H2O——>NaOH+H2其中氢没有被全部 2021-01-07 …