2c03-review - 00047

# 2c03-review - 00047 - p:= L2 if(p<> nil p:= p ↑.next...

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

3 The time complexity is O(n). d.[6] Assume that the list are doubly linked and redo (b). Discuss the difference if any. function C1H2H(L1, L2: celltype;): celltype; var p : celltype; var n : integer; begin {delete odd elements in List 1} p := L1; while (p <> nil) do begin if (p .previous .next <>nil) p .previous .next := p .next; else begin L1 := p .next; if L1 = nil break; L1 .previous := p .previous end if (p .next <> nil) p .next .previous := p .previous; else L1 .previous := p .previous; p := p .next; if (p <> nil) p := p .next; end {delete even elements in List 2}
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: p := L2; if (p <> nil) p := p ↑ .next ; while (p<> nil) do begin p ↑ .previous ↑ .next := p ↑ .next; if (p ↑ .next <> nil) p ↑ .next ↑ .previous := p ↑ .previous; else L1 ↑ .previous := p ↑ .previous; p := p ↑ .next; if (p <> nil) p := p ↑ .next; end if (L1 = nil) return(L2) if (L2 = nil) return(L1) p := L2 ↑ .previous; L1 ↑ .previous ↑ .next := L2; L2 ↑ .previous := L1 ↑ .previous; L1 ↑ .previous := p; return(L1); end function MIDDLE(L: ↑ celltype;): ↑ celltype; var p,q : ↑ celltype;...
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