.完善算法已知单链表结点类型为
TYPE ptr=^node
node=RECORD
datainteger nextptr
END
过程create建立以head为头指针的单链表
PROCEDURE create ( () )
VAR pqptr kinteger
BEGIN
new(head) q:=headread(k)
WHILE k> DO
BEGIN
(); (); (); ();
read(k)
END;
q^next=NIL;
END;【北京师范大学 三】
已给如下关于单链表的类型说明
TYPE
list=^node ;
node=RECORD
data: integer; next: list;
END;
以下程序采用链表合并的方法将两个已排序的单链表合并成一个链表而不改变其排序性(升序)这里两链表的头指针分别为p和q
PROCEDURE mergelink(VAR pq:list):
VAR hr: list;
BEGIN
()
h^next:= NIL; r:=h;
WHILE((p<>NIL) AND (q<>NIL)) DO
IF (p^data<=q^data)
THEN BEGIN () r:=p; p:=p^next END
ELSE BEGIN () r:=q; q:=q^next; END;
IF (p=NIL) THEN r^next:=q;
()
p:=h^next; dispose(h);
END;【厦门大学 三 (分)】
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []