Gustavo Siqueira wrote:Hi, everyone!
I'm studying a algorithm called merge sort, in which i did in Java. But, I'm having problems to understand it.
What do you mean by "in which I did in Java?" Surely you do not mean that you wrote the code, because then you would understand it, right? So if you didn't write it, then where do you get it, can you
QuoteYourSources?
Gustavo Siqueira wrote:So, when I run the program, is called the method mergeSort for to make the sorting of numbers. After , make the 'if', then is executed the method mergeSort(A, p, q); three times, and just after is executed the method mergeSort(A, q+1, r). Why that happens ?
This is recursion. In this scenario you take a task and you split it into smaller parts, and you do that over and over again until you get to parts that are so easy you can handle them. Then you put everything back together as the method stack unrolls.
Try a search for recursion and you will get lots of useful info.
Below is the code you posted.
Gustavo Siqueira wrote:
So, when I run the program, is called the method mergeSort for to make the sorting of numbers. After , make the 'if', then is executed the method mergeSort(A, p, q); three times, and just after is executed the method mergeSort(A, q+1, r). Why that happens ?
Thanks you!