2c03-review - 00019

2c03-review - 00019 - ↑ celltype end procedure...

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. [15] function NEXT(p: position, L: list): position var q, BEGIN: positin; begin if EMPTY(L) then write(“empty list”); q:=PROVIOUS(FIRST(L), L); BEGIN:=q; while (PROVIOUS(q,L) <> BEGIN do if PROVIOUS(q,L) = p then return(q) else q:=PROVIOUS(q,L); write(“invalid input”) end 2.[20] a.[10] type celltype = record element: elementtype next:
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ↑ celltype end; procedure ERASE_DUPLICANTS(L: ↑ celltype); var p,q: ↑ celltype; begin p:=L; while p ↑ .next<>nil do begin q:=p ↑ .next; while q ↑ .next<>nil do if q ↑ .next.element=p ↑ .next.element then q ↑ .next:= q ↑ .next ↑ .next else q:= q ↑ .next; p:= p ↑ .next end end O(n 2 ), since 2 nested loops....
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