2c03-review - 00095

2c03-review - 00095 - p := p ↑ .next ; q := q ↑...

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

View Full Document Right Arrow Icon
8 while (p .next <> nil) do begin tmp := p .next; p .next := p 2 .next .next; tmp .next := L .next .next; L .next .next := tmp; p 1 := p 1 .next .next ; p 2 .next := tmp2 ; end end The time complexity is O(n). d.[5] Assume that the list are doubly linked and redo (c). Discuss the difference if any. procedure REV1(var L: celltype;); var p,q: celltype; tmp: elementtype; begin if ((L = nil) or (L .next = nil)) return; p := L .next; q := L .previous; while ((p <> q) and (q .next <> p)) do begin tmp := p .element; p .element := q .element; q .element := tmp;
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 := p ↑ .next ; q := q ↑ .previous end end The time complexity is O(n). 7.[15] Redo (6) assuming an array implementation of lists. Design and array implementation which in your opinion guarantees the lowest time complexity. Justify your design. a.[5] 3ONLY(L). The procedure deletes from L all elements except those on 3k+1, k $ 0, positions. For instance if L=2,3,1,5,7,8,9 then 3ONLY(L) = 2,5,9, i.e. only positions 1,4,7 are left. procedure 3ONLY(L: List;); var n : integer;...
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