2c03-review - 00096

2c03-review - 00096 - 1 [n] := L 2 [n-l]; if (L 1 .last L 2...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
9 begin L.last := ((L.last - 1) div 3) + 1; for (n :=2 to L.last) do begin L.element[n] := L.element[3n-2] end end The time complexity is O(n). b.[5] SHUFFLE(L 1 ,L 2 ). This procedure shuffles the list, the result has the appropriate elements of the first list follows by the appropriate elements of the second list, see the example. For instance if L 1 = 2,3,1,4,5,6,7,8, L 2 = a,c,b,d,f, then SHUFFLE(L 1 ,L 2 ) = 2,a,3,c,1,b,4,d,5,f,6,7,8, L 1 = 1,2,3, L 2 = a,b,c,d,e,f, then SHUFFLE(L 1 ,L 2 ) = 1,a,2,b,3,c,d,e,f. procedure SHUFFLE(var L 1 ,L 2 : List;); var n,mlength: integer; begin mlength := min(L 1 .last, L 2 .last); if (L 1 .last < L 2 .last) then for (n:= L 1 .last + L 2 .last downto (2*l + 1)) do L
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 [n] := L 2 [n-l]; if (L 1 .last L 2 .last) then for (n:= L 1 .last + L 2 .last downto (2*l + 1)) do L 1 [n] := L 1 [n-l]; for (n:= mlength downto 1) do begin L 1 [2n] := L 2 [n]; L 1 [2n-1] := L 1 [n]; end end The time complexity is O(m+n). c.[5] REV1(L). The procedure reverse all the list except the first element. For instance if L= 2,3,1,4,5,6, then REV1(L)= 2,6,5,4,1,3. procedure REV1(var L: List;); var p,q: integer; tmp: elementtype; begin if (L.last 2)) return; p := 2; q := L .last; while ((p &lt;&gt; q) and (q+1 &lt;&gt; p)) do begin tmp := L[p];...
View Full Document

Ask a homework question - tutors are online