归并排序 递归调用栈分析

发布于 2021-07-31  58 次阅读


Merge.sort(a)进栈

sort(a, 0, 2)进栈

sort(a, 0, 1)进栈

sort(a, 0, 0)进栈、sort(a, 0, 0)出栈

sort(a, 1, 1)进栈,sort(a, 1, 1)出栈

merge(a, 0, 0, 1)进栈;->assist = [2,3,null] -> a = [2,3,1],merge(a, 0, 0, 1)出栈

sort(a,0,1)出栈;

sort(a,2,2)进栈;sort(a,2,2)出栈;

merge(a,0,1,2)进栈; -> assist = [1,2,3] -> a = [1,2,3];merge(a,0,1,2) 出栈;

sort(a, 0, 2)出栈;

Merge.sort(a)出栈;

结束!

等一下还有!println进栈,toString进栈,toString出栈,println出栈...................