2c03-review - 00097

2c03-review - 00097 - end end[5 procedure SHUFFLE(var L 1,L...

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

View Full Document Right Arrow Icon
10 L[p] := L[q]; L[q] := tmp; p := p + 1 ; q := q-1 end end The time complexity is O(n). 8.[15] Using the operations given on pages 38-39 of Aho-Hopcroft-Ullman, write procedures to compute the functions from question 6. [5] procedure 3ONLY(var L: List;); var p : position; var n : integer; begin p := FIRST(L); n:=1; while (p <> END(L)) do begin if ((n mod 3) <> 1) then begin Delete(p,L); n:=n+1; end p := Next(p,L); n:= n+1;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: end end [5] procedure SHUFFLE(var L 1 ,L 2 : List;); var p,q: position; begin p := FIRST(L 1 ); q := FIRST(L 2 ); while (p<>END(L 1 ) and q<>END(L 2 )) do begin p:=NEXT(p,L 1 ); INSERT(RETRIEVE(q, L 2 ), p, L 1 ); p:=NEXT(p,L 1 ); q:=NEXT(q,L 2 ) end while (q<>END(L 2 )) do begin INSERT(RETRIEVE(q, L 2 ), END(L 1 ), L 1 ); q:=NEXT(q,L 2 ) end end [5] procedure REV1(var L: List;);...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online