Recursion with Return instruction without parameter

Please I have a doubt about following code:

public void solveTowers( int disks, int sourcePeg, int destinationPeg,

int tempPeg )

{

if ( disks == 1 )

{

System.out.printf( "\n%d --> %d", sourcePeg, destinationPeg );

return;

}

solveTowers( disks - 1, sourcePeg, tempPeg, destinationPeg );

System.out.printf( "\n%d --> %d", sourcePeg, destinationPeg );

}

--

If I enter witch amount variable DISK = 3

I'd like to known: Why ouput after perform the code is

1>3

2>3

1>3?

I didn't get it about the mechanism logical of RETURN instruction !!!

Please, some could me help and explain about with mechanism

OBS: An draw or design it will be helpfull for me understant

A lot of thanks

Gmourad

[838 byte] By [Gmourada] at [2007-11-27 2:39:46]
# 1
hi this problem is this unstack, named reverse recursionPlease search about the theme Reverse recursion
Gmurada at 2007-7-12 3:02:01 > top of Java-index,Java Essentials,Java Programming...
# 2

You didn't mention other parameters of your recursive method, so I am not guessing but here is an easier example.

public class Test{

public void resursive(int num) {

if (num == 1) {

System.out.println(num);

return;

}

resursive(--num);

System.out.println(num);

}

public static void main(String[] args) {

int num = 3;

Test myTest = new Test();

a.resursive(num);

}

}

1

1

2

recursive(3) -> recursive(2)// print 2

recursive(2) -> recursive(1) // print 1

recursive(1) -> // print 1

It would print the last one first because the upper one would call itself first before print out the value.

rym82a at 2007-7-12 3:02:01 > top of Java-index,Java Essentials,Java Programming...