2c03-review - 00012

2c03-review - 00012 - if L.elements[p]=x then L.last=...

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

View Full Document Right Arrow Icon
2 if (x=L.elements[i]) then for j:=i+1 to L.last do begin L.elements[j-1]:=L.elements[j]; L.last:=L.last-1; end i:=i+1; end end O(n*n) Solution 2 type LIST = record elements: array[1. .maxlength] of elementtype; last: integer end; position = integer; prodedure REMOVEALL(x: elementtype; L: LIST) var p,q: position begin for p:=1 to L.last do
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if L.elements[p]=x then L.last= L.last-1; for q:=p to L.last do {shift elements at p+1, p+2} L.elements[p]:=L.elements[p+1]; end time complexity is O(n^2). 2.[10] solution 1 1.0 / \ 0.6 a / \ 0.4 c / \ 0.2 b / \ d e a: 1 b: 001 c: 01 d: 0000 e: 0001 length=2.2...
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