正在加载图片...
3.4己知栈S中存放了8个数据元素,自栈底至栈顶依次为(1,2,3,4,5,6,7,8)。 (1)写出在执行了函数调用algol(S)后,S中的元素序列。 (2)在(1)的基础上,又执行了函数调用algo2(S,5),写出此时S中的元素 序列。 void algol(Stack &S){ int a[10],i,n=0; while(!StackEmpty(S)){n++:Pop(S,a[n]): for(i=1;i<=n;i++)Push(S,a[i]): void algo2(Stack &S,int e){ Stack T: int d; InitStack(T): while(!EmptyStack(S)){ Pop(S,d); if(d!=e)Push(T,d): while(!StackEmpty(T))( Pop(T,d); Push(S,d); 3.5已知队列Q中自队头至队尾依次存放着(1,2,3,4,5,6,7,8)。写出在执行了 函数调用algo3(Q)后,Q中的元素序列。 void algo3(Queue &Q) Stack S; int d; InitStack(S); while(!QueueEmpty(Q)){ 第4页 第 4 页 3.4 已知栈 S 中存放了 8 个数据元素,自栈底至栈顶依次为(1,2,3,4,5,6,7,8)。 (1)写出在执行了函数调用 algo1(S)后,S 中的元素序列。 (2)在(1)的基础上,又执行了函数调用 algo2(S,5),写出此时 S 中的元素 序列。 void algo1(Stack &S){ int a[10], i, n=0; while(!StackEmpty(S)){ n++; Pop(S, a[n]); } for(i=1; i<=n; i++) Push(S, a[i]); } void algo2(Stack &S, int e){ Stack T; int d; InitStack(T); while(!EmptyStack(S)){ Pop(S,d); if(d!=e) Push(T,d); } while(!StackEmpty(T)){ Pop(T,d); Push(S,d); } } 3.5 已知队列 Q 中自队头至队尾依次存放着(1,2,3,4,5,6,7,8)。写出在执行了 函数调用 algo3(Q)后,Q 中的元素序列。 void algo3(Queue &Q){ Stack S; int d; InitStack(S); while(!QueueEmpty(Q)){
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有