問題:構(gòu)造一鏈表,并按與輸入相同的次序輸出該鏈表中的數(shù)據(jù)。
程序:
PROGRAM fifolist(input,output);
TYPE
pointer=↑cooperate;
cooperate=RECORD
next:pointer;
data:integer
END;
VAR
p1,p2,p3:pointer;
BEGIN
( ?、堋 。?;
P3:=P1
read(p1↑。data);
WHILE NOT eof DO
BEGIN
( ?、荨 。?;
read(p2↑。data);
( ?、蕖 。?;
p3:=p2
END;
P2↑。next:=NIL;
WHILE P1 NIL DO
GEGIN
write(p1↑。data);
( ?、摺 。?;
END;
END.
4.你選擇( )
A.P1:=NIL
B.P2:=NIL
C.NEW(P1)
D.new(p2)
5.你選擇( ?。?BR> A.P1:=NIL
B.P2:=NIL
C.new(P1)
D.new(P2)
6.你選擇( ?。?BR> A.p3↑。next:=P2
B.P3↑。next:=NIL
C.P3↑。next:=P2↑。next
D.p3↑。next:=p3
程序:
PROGRAM fifolist(input,output);
TYPE
pointer=↑cooperate;
cooperate=RECORD
next:pointer;
data:integer
END;
VAR
p1,p2,p3:pointer;
BEGIN
( ?、堋 。?;
P3:=P1
read(p1↑。data);
WHILE NOT eof DO
BEGIN
( ?、荨 。?;
read(p2↑。data);
( ?、蕖 。?;
p3:=p2
END;
P2↑。next:=NIL;
WHILE P1 NIL DO
GEGIN
write(p1↑。data);
( ?、摺 。?;
END;
END.
4.你選擇( )
A.P1:=NIL
B.P2:=NIL
C.NEW(P1)
D.new(p2)
5.你選擇( ?。?BR> A.P1:=NIL
B.P2:=NIL
C.new(P1)
D.new(P2)
6.你選擇( ?。?BR> A.p3↑。next:=P2
B.P3↑。next:=NIL
C.P3↑。next:=P2↑。next
D.p3↑。next:=p3