●试题三阅读下列说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】本题给出四个函数,它们的功能分别是:1.int push(PNODE *top,int e)是进栈函数,形参top是栈顶指针的指针,形参e是入栈元素。2.int pop(PNODE *top,int *e)是出栈函数,形参top是栈顶指针的指针,形参e作为返回出栈元素使用。3.int enQueue(PNODE *tail,int e)是入队函数,形参tail是队尾指针的指针,形参e是入队元素。4.int deQueue(PNODE *tail,int *e)是出队函数,形参tail是队尾指针的指针,形参e作为返回出队元素使用。以上四个函数中,返回值为0表示操作成功,返回值为-1表示操作失败。栈是用链表实现的;队是用带有辅助结点(头结点)的单向循环链表实现的。两种链表的结点类型均为:typedef struct node{int value;struct node *next;}NODE,*PNODE;【函数1】int push(PNODE *top,int e){PNODE p=(PNODE)malloc (sizeof(NODE));if (!p) return-1;p- value =e;(1) ;.*top=p;return 0;}【函数2】int pop (PNODE *top,int *e){PNODE p=*top;if(p==NULL)return-1;*e=p-value;(2) ;free(p);return 0;}【函数3】int enQueue (PNODE *tail,int e){PNODE p,t;t=*tail;p=(PNODE)malloc(sizeof(NODE));if(!p)return-l;p-value=e;p-next=t-next;(3) ;*tail=p;return 0;}【函数4】int deQueue(PNODE *tail,int *e){PNODE p,q;if((*tail)-next==*tail)return -1;p=(*tail)-next;q=p-next;*e=q-value;(4) =q-next;if(*tail==q) (5) ;free(q);return 0;}
●试题三
阅读下列说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
本题给出四个函数,它们的功能分别是:
1.int push(PNODE *top,int e)是进栈函数,形参top是栈顶指针的指针,形参e是入栈元素。
2.int pop(PNODE *top,int *e)是出栈函数,形参top是栈顶指针的指针,形参e作为返回出栈元素使用。
3.int enQueue(PNODE *tail,int e)是入队函数,形参tail是队尾指针的指针,形参e是入队元素。
4.int deQueue(PNODE *tail,int *e)是出队函数,形参tail是队尾指针的指针,形参e作为返回出队元素使用。
以上四个函数中,返回值为0表示操作成功,返回值为-1表示操作失败。
栈是用链表实现的;队是用带有辅助结点(头结点)的单向循环链表实现的。两种链表的结点类型均为:
typedef struct node{
int value;
struct node *next;
}NODE,*PNODE;
【函数1】
int push(PNODE *top,int e)
{
PNODE p=(PNODE)malloc (sizeof(NODE));
if (!p) return-1;
p-> value =e;
(1) ;.
*top=p;
return 0;
}
【函数2】
int pop (PNODE *top,int *e)
{
PNODE p=*top;
if(p==NULL)return-1;
*e=p->value;
(2) ;
free(p);
return 0;
}
【函数3】
int enQueue (PNODE *tail,int e)
{PNODE p,t;
t=*tail;
p=(PNODE)malloc(sizeof(NODE));
if(!p)return-l;
p->value=e;
p->next=t->next;
(3) ;
*tail=p;
return 0;
}
【函数4】
int deQueue(PNODE *tail,int *e)
{PNODE p,q;
if((*tail)->next==*tail)return -1;
p=(*tail)->next;
q=p->next;
*e=q->value;
(4) =q->next;
if(*tail==q) (5) ;
free(q);
return 0;
}