2c03-review - 00011

2c03-review - 00011 - p:=First(L while(p<>END(L if(x =...

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<>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<=L.last) and (x<>L.elements[i]) do i:=i+1; i:=i+1; while (i<=L.last) do begin...
View Full Document

This note was uploaded on 12/10/2009 for the course CAS 2c03 taught by Professor Janicki during the Spring '03 term at McMaster University.

Ask a homework question - tutors are online