【简答题】
试题六
阅读下列函数说明和 C 函数,将应填入__(n)__处的字句写在答题纸的对应栏内。
[函数6说明]
函数DelAInsB(LinkedList La,LinkedList lb,int key1,int key2,int len)的功能是,将线性表A中关键码为keyl的结点开始的len个结点,按原顺序移至线性表B中关键码为key2的结点之前,若移动成功,则返回0;否则返回-1。线性表的存储结构为带头结点的单链表,La为表A的头指针,Lb为表B的头指针。单链表结点的类型定义为:
typedef struct node{
int key;
struct node*next;
}*Linkedhist;
[函数6]
int DelllnsB(LinkedLiSt La,LinkedList Lb,int keyl,int key2,int len)
{ LinkedList p,q,S,prep,pres;
int k;
if (!La->next || !Lb->next || len<=0) return-1;
p = La->next; prep = La;
while (p && p->key != keyl){ /* 查找表A中键值为key1的结点 */
prep = p; p = p->next;
}
if (!p) return -1; /* 表A中不存在键值为key1的结点 */
q = p; k = 1;
while (q && __(1)__){ /* 在表A中找出待删除的len个结点 */
__(2)__: k++;
}
if (!q) return -1; /* 表A中不存在要被删除的len个结点 */ •
S = Lb->next;__ (3)__;
while (s && s->key != key2){ /* 查找表B中键值为key2的结点 */
pres = s; s = s->next;
}
if (!s)return -1; /* 表B中不存在键值为key2的结点 */
__(4)__q->next; /* 将表A中的len个结点删除 */
q->next:__(5)__
pres->next = p; /* 将len个结点移至表B */
return 0;
}