private void mergesort(int low, int high) { //line 1
if (low < high) { //line 2
int middle = (low + high)/2 ; //li
Regarding your second snippet :
public static void recursionExample(int i){
if(i < 3){
recursionExample(i+1); // this is called for the last time when i==2, i.e. the
// last call is recursionExample(3). When that call
// returns, i is still equal 2, since calling
// recursionExample(i+1) doesn't change the value of the
// local variable i of the current method call
recursionExample(i-1); // Therefore when this line is first called, i is equal 2
}
}
Considering your second snippet, the order of calls is the following (represented as a tree for ease of understanding) :
- recursionExample(0)
- recursionExample(1)
- recursionExample(2)
- recursionExample(3), here no more recursion
- recursionExample(1)
...
- recursionExample(0)
...
- recursionExample(-1)
- recursionExample(0)
...
- recursionExample(-2)
...