2c03-review - 00004

2c03-review - 00004 - b[10] 8pts: procedure DUP(L); var...

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

View Full Document Right Arrow Icon
1 CS2MD3-SOLUTIONS TO THE MIDTERM TEST Summer 2001 1.[20] a.[10] 8pts: procedure DUP(L); var x:^node; temp:^node; begin X:=L; while X^.next<>nil do begin new(temp); x:=x^.next; temp^.element:=x^.element; temp^.next:=x^.next; x^.next:=temp; x:=x^.next; { or INSERT(x^.next^.element,x,L); x:=NEXT(x,L) } end; end 2pts: complexity T(n)=O(n) since one loop only and the entire list has to be visited.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: b[10] 8pts: procedure DUP(L); var i:integer; begin if 2*L.last max then begin for i:= L.last down to 1 do begin L.element[2*i] := L.element[i]; L.element[2*i-1]:=L.element[i]; end; L.last:=2*L.last end else write(error) end 2pts: complexity T(n)=O(n), one loop and the entire list has to be visited....
View Full Document

Ask a homework question - tutors are online