my professor assigned a problem in which we must use Stacks (or Queues) to make a non-recursive MergeSort. The current code is as follows:
private static void sort(Comparable[] a, int[] index, int[] aux, int lo, int hi) {
if (hi <= lo) return;
int mid = lo + (hi - lo) / 2;
sort(a, index, aux, lo, mid);
sort(a, index, aux, mid + 1, hi);
merge(a, index, aux, lo, mid, hi);
I'm not sure how to approach this problem, and any help would be appreciated. I know that i must use a while loop to emulate the recursion. But how can I split the actual values? Also, how can I keep track of the middle of the partitioned values?
I am really confused by the problem. Any help would be appreciated!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…