2c03-review - 00011

2c03-review - 00011 - p:=First(L) while...

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

View Full Document Right Arrow Icon
1 SOLUTIONS TO THE MIDTERM TEST 1.[20] a) possible solutions: solution 1 procedure REMOVEALL(x:element, var L:LIST) var q:position; flag:integer begin flag=0; q:=L; while q^.next<>nil begin if q^.next^.element=x then if flag=0 then begin flag:=1; q:=q^.next end else DELETE(q,L) else q:=q^next end end O(n) Solution 2 prodedure REMOVEALL(x,L) p:^celltype
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: p:=First(L) while (p&lt;&gt;END(L)) if(x = RETRIVE(p, L)) then DELETE(p, L); p:=NEXT(p,L); end time complexity is O(n). b) solution 1 procedure REMOVEALL(x:element, var L:LIST) var i,j:position begin i:=1; while (i&lt;=L.last) and (x&lt;&gt;L.elements[i]) do i:=i+1; i:=i+1; while (i&lt;=L.last) do begin...
View Full Document

Ask a homework question - tutors are online