請問反轉單向鏈結串列的元素,反轉後的結果亦為一單向鏈結串列。 程式碼如下,是否有bug. Procedure Invert C begin if (C ≠ nil) then begin p = C→link; q = C; while (p ≠ c) do begin r = q; q = p; p = p→link; q→link = r; end; C→link = q; C = q; end; end
Procedure Invert C
begin
if (C ≠ nil) then
begin
trail,middle =nil;
rear=C
while (rear) do
begin
trail=middle;
middle=rear;
rear=rear->link
middle->link=trail;
end;
end;
end