Re: Making sense of recursion

2018-06-26 Thread Timoses via Digitalmars-d-learn
On Monday, 25 June 2018 at 17:45:01 UTC, zbr wrote: Hi, this question is not specifically D related but I'll just ask anyway. Consider the following snippet: void mergeSort(int[] arr, int l, int r) { if (l < r) // 1 { int m = l+(r-l)/2;// 2

Re: Making sense of recursion

2018-06-25 Thread ag0aep6g via Digitalmars-d-learn
On 06/25/2018 07:45 PM, zbr wrote: void mergeSort(int[] arr, int l, int r) {    if (l < r)   // 1    {   int m = l+(r-l)/2;    // 2   mergeSort(arr, l, m); // 3   mergeSort(arr, m+1, r);   // 4   merge(arr, l, m, r);  // 5   

Re: Making sense of recursion

2018-06-25 Thread Colin via Digitalmars-d-learn
On Monday, 25 June 2018 at 17:45:01 UTC, zbr wrote: Hi, this question is not specifically D related but I'll just ask anyway. Consider the following snippet: [...] Your mistake is in your visualization :-) But... more like: 0 < 4 ? true : mergeSort(0,2) && mergeSort(3, 4) And so on. I.e,

Making sense of recursion

2018-06-25 Thread zbr via Digitalmars-d-learn
Hi, this question is not specifically D related but I'll just ask anyway. Consider the following snippet: void mergeSort(int[] arr, int l, int r) { if (l < r) // 1 { int m = l+(r-l)/2;// 2 mergeSort(arr, l, m); // 3