Sunday, March 14, 2010

Does Best Buy Phone Insurance Cover Water Damage?

Pseudocode

Recursive Algorithm Pseudocode

hanoi (n, source, destination, auxiliary)

if n = 1



then move a disk from the tower to the tower source destination / / { solution of the recursive method}


if
/ / {move n-1 disks from tower to tower auxiliary source}
call hanoi (n-1, source, auxiliary target) / / recursive call} {
Move a disc from the source tower to tower
destination
/ / { move n-1 disks from tower to tower auxiliary destination}

method call hanoi (n-1, axuliar, destination, origin) / / recursive call} {



order order






Iterative Algorithm Pseudocode

/ / the arguments origin, destination and axuliar are variables representing the three towers of the original problem (may be structures or simply the name of each tower, in this case represent only the name of the towers is therefore assumed to be in text format).
/ / n is the number of disks
/ / Pilane, battery, and battery are Pilad type structures
BATTERY / / stop is a variable of type integer.
/ / varaux is a variable of type text (in this case because the towers are represented only by name, ie, this variable must be the same type as origin, destination and auxiliary)
/ / flag is a variable

boolean type iterative solution (n, source, destination, auxiliary)

to stop = 0 and flag = false
repeat while (n> 0) and (flag = false)

repeat while (N> 1)

/ / are stored in the batteries current values \u200b\u200bof the parameters
stop = stop +1
Pilan [top] = n
stack [top] = origin
Pilad [top] = desthio
stack [top] = auxiliary

n = n-1 = target varaux

target = helper helper = varaux


End / / end repeat while (N> 1)

move disk from source to destination


flag = true if top> 0 then / / means that the batteries are not
empty
n = Pilan [top]
origin = stack [top]
target = Pilad [top]
auxiliary = stack [top]
top = top-1 disk

move from origin to destination

n = n- 1
varaux = source source = auxiliary
Auxiliary = varaux

flag = false

End / / end if top> 0 then
End / / end repeat while (n> 0) and (band = false)
End / / end method