Page 420 - Computer science 868 Class 12
P. 420
25 }
26 }
27 void show()
28 { String w=findlong(sen); // method calling and printing longest word
29 System.out.println("Longest word ="+w);
30 }
31 public static void main()
32 { Longword ob=new Longword();
33 ob.read();
34 ob.show();
35 }
36 }
The output of the preceding program is as follows:
11.4 TOWER OF HANOI
TOWER OF HANOI, is a mathematical puzzle which consists N Disks Move N-1
of three towers (pegs) and multiple rings placed one above Step 1 Recusively
another in increasing order of their diameter, i.e., the smaller Source Auxillary Destination
ring is stacked over the larger one.
The purpose is to move all the disks stacked in first tower to Step 2 Last disk N1
the third tower using the intermediate middle tower without
violating the sequence of arrangement. The rules to be followed Source Auxillary Destination
during transfer are listed below:
N1
• Only one disk can be moved among the towers at any given Step 3 Last disk
time. Source Auxillary Destination
• Only the “top” disk can be removed. Move N-1
Recusively
• No large disk can sit over a small disk.
Step 4
Source Auxillary Destination
418418 Touchpad Computer Science-XII

