题目内容

写出下列程序段的输出结果:栈结构定义为typedef struct astack *Stack;typedef struct astack{int top; //栈顶位置int maxtop; //栈顶位置的最大值StackItem *data; //栈元素数组指针}Astack;基本函数包括(1)初始化栈 StackInit (Stack S)(2)判断栈是否为空 int StackEmpty(Stack S)(3)判断栈是否满 int StackFull(Stack S)(4)入栈 Push(StackItem x,Stack S)(5)出栈 StackItem Pop(Stack S)(6)获取栈顶元素内容 StackItem StackTop(Stack S)void main( ) {Stack S;char x, y;x = 'c';y = 'k';Push ( x );Push ( 'a' );Push ( y );x=Pop ( S );Push ( 't' );Push ( x );x=Pop ( S );Push ( 's' );while (!StackEmpty ( ) ){y= Pop (S );printf(“%c”, y);}printf(“%c\n”, x);}输出结果:______________________

查看答案
更多问题

写出下列程序段的输出结果:队列结构定义为typedef struct qnode *qlink;struct qnode{QItem element;qlink next;}Qnode; //队列结点定义typedef struct lque *Queue;typedef struct lque{qlink front; //队首结点指针qlink rear; //队尾结点指针}Lqueue;基本函数为(1)初始化队列 Queue QueueInit()(2)入队 void EnterQueue(QItem x,Queue Q)(3)出队 QItem DeleteQueue(Queue Q)(4)获取队头元素内容 QItem QueueFirst(Queue Q)(5)判断队列是否为空 int QueueEmpty(Queue Q)void main( ){Queue Q;char x = 'e', y = 'c';EnterQueue ( 'h' , Q);EnterQueue ( 'r' , Q);EnterQueue ( y , Q);x= DeleteQueue (Q);EnterQueue ( x, Q );x=DeleteQueue ( Q);EnterQueue ( 'a', Q );while (!QueueEmpty ( ) ){y= DeleteQueue ( Q );printf(“%c”, y);}printf(“%c\n”, x);}输出结果:______________________

简述下述算法功能void unknown ( Queue &Q ){Stack S;int d;while (!QueueEmpty (Q ) ){d= DeleteQueue (Q);Push ( d , S);}while (!Stack Empty (S ) ){d= Pop ( S );EnterQueue ( d, Q );}}功能是:_________________________________________

下面的算法中使用了一个栈st,阅读该算法,回答下列问题:(1)算法的功能是:__________________________________(2)若字符数组A[ ] = { ‘m’,‘a’,‘d’,‘a’,‘m’,‘i’,‘m’,‘a’,‘d’,‘a’,‘m’ },执行这个算法,跟踪栈的变化。栈结构定义为typedef struct astack *Stack;typedef struct astack{int top; //栈顶位置int maxtop; //栈顶位置的最大值StackItem *data; //栈元素数组指针}Astack;基本函数包括(1)初始化栈 StackInit (Stack S)(2)判断栈是否为空 int StackEmpty(Stack S)(3)判断栈是否满 int StackFull(Stack S)(4)入栈 Push(StackItem x,Stack S)(5)出栈 StackItem Pop(Stack S)(6)获取栈顶元素内容 StackItem StackTop(Stack S)#include “stack.h”int unknown ( char A[ ], int n ){Stackst=StackInit (n+1);int yes = 1, i = 0;char ch;while ( A[i] != “\0” ){Push ( A[i], st );i++;}i = 0;while ( A[i] != “\0” ){ch=Pop (st );if ( A[i] == ch )i++;else{yes = 0;break;}}return yes;}

下面的算法中使用了一个栈st,阅读该算法,回答下列问题:(1)算法的功能是:__________________________________(2) 若单链表中各结点中数据的逻辑顺序为 { ‘u’,‘n’,‘i’,‘v’,‘e’,‘r’,‘s’,‘i’,‘t’,‘y’ },执行这个算法,跟踪栈的变化。#include "stack.h"#include "LinkList.h"void unknown ( ){//此单链表带有表头结点,它的表头指针为first。Stack S;ListNode*p = first->link, *q;while ( p != NULL ){Push (p, S);p = p->link;}p = first;p->link = NULL;while ( !StackEmpty( ) ) //将栈中保存的结点依次出栈{q=Pop (S );q->link = p->link;p->link = q;p = q;}}

答案查题题库