正在加载图片...
A)front=front->next B)rear=rear->next C) rear=front->next D)front=rear-> 6、写出下列程序段的输出结果(其中栈的元素类型 SElemType为char) i Stack S; char y: InitStack(S) Push(S, x): Push(S, 'a): Push(S, y): Pop(s, x) Push(s, 't'): Push(S, x): Pop (S, x ): Push(S, 's") while(! StackEmpty(S))(Pop(s, y): printf(y): 1 7、写出以下程序段的输出结果(队列中的元素类型 QElemType为char) id @ ueue Q; char x=’e Queue(Q) EnQueue( Q,'h): EnQueue(Q, r ) EnQueue( Q, y): DeQueue(Q, x) EnQueue(Q, x): DeQueue(Q, x): EnQueue(Q, ' a) while(! QueueEmpty(Q))[ DeQueue(, y): printf (y): 1 printf(x) 8、若栈用顺序存储表示,其栈的元素类型为整型,类型定义如下 #define maXsize 1000 typedef struct i int elem[ MAXSIZE];/用来存放栈元素的数组,下标从0开始 Int top //指向栈顶位置的域,栈底为位置0 STack 请补全以下栈操作函数:(用C语言) (1)判断栈S是否为空栈:若为空,则返回1,不为空则返回0 int StackEmpty (Stack S) else (2)入栈操作:若栈满,则返回0,不满,则入栈,返回1 int push( Stack*p,inte)//p为指向栈的指针,e为待入栈的元素 ) return(0);//栈满,则返回0 =e;//栈 p->top+=l /栈顶位置变化 return (1) 、简述栈、队列和线性表的差别和联系。 参考解答:1、C2、D3、C4、C5、A6、 stack7、char return(O p>top>=MAXSIZE-1 D->elemlp->topl 本章其它习题解答请参看本系网站。6 A) front=front->next; B)rear=rear->next; C) rear=front->next; D)front=rear->next; 6、写出下列程序段的输出结果(其中栈的元素类型 SElemType 为 char) void main() { Stack S; char x,y; InitStack(S); x=’c’; y=’k’; Push(S,x); Push(S,’a’); Push(S,y); Pop(S,x); Push(S,’t’); Push(S,x); Pop(S,x); Push(S,’s’); while(!StackEmpty(S)){Pop(S,y); printf(y); }; printf(x); } 7、写出以下程序段的输出结果(队列中的元素类型 QElemType 为 char)。 void main() { Queue Q; char x=’e’,y=’c’; InitQueue(Q); EnQueue(Q,’h’); EnQueue(Q,’r’); EnQueue(Q,y); DeQueue(Q,x); EnQueue(Q,x); DeQueue(Q,x); EnQueue(Q,’a’); while(!QueueEmpty(Q)){ DeQueue(Q,y); printf(y);} printf(x); } 8、若栈用顺序存储表示,其栈的元素类型为整型,类型定义如下: #define MAXSIZE 1000 typedef struct{ int elem[MAXSIZE]; //用来存放栈元素的数组,下标从 0 开始 int top; //指向栈顶位置的域,栈底为位置 0 }Stack; 请补全以下栈操作函数:(用 C 语言) (1)判断栈 S 是否为空栈:若为空,则返回 1,不为空则返回 0 int StackEmpty(Stack S){ if( )return (1); else ; } (2)入栈操作:若栈满,则返回 0,不满,则入栈,返回 1 int Push(Stack *p,int e){ //p 为指向栈的指针,e 为待入栈的元素 if( )return(0);//栈满,则返回 0 =e; //入栈 p->top+=1; //栈顶位置变化 return(1); } 9、简述栈、队列和线性表的差别和联系。 参考解答:1、C 2、D 3、C 4、C 5、A 6、stack 7、char 8、S.top==0 或!(S.top) return(0) p->top>=MAXSIZE-1 p->elem[p->top] 本章其它习题解答请参看本系网站
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有