2c03-review - 00018

2c03-review - 00018 - A(x, y : int ; var z : int); label :...

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

View Full Document Right Arrow Icon
3 if DATA(v)=x then return(true); if LEFTMOST_CHILD(v,T)<> null then begin v:= LEFTMOST_CHILD(v,T); ENQUEUE(v,level); while RIGHT_SIBLING(v,T)<>null do begin v:=RIGHT_SIBLING(v,T); ENQUEUE(v,level); end end end return(false) end c. O(n). In worst case, all nodes are enqueueed and dequeued once. 6. procedure
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: A(x, y : int ; var z : int); label : 1. .2; S : STACK of (x, y, label); begin MAKENULL(S); 1: if x=0 or y= 0 then z:=0; else if (x mod y) =0 then z:=y else begin PUSH((x,y,2), S); goto 1 end 2: if not EMPTY(S) then begin (x, y, label):= TOP(S); POP(S); goto label end end ;...
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