My professor has identified a problem in which we must use Stacks (or Queues) to create 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 am not sure how to approach this problem, and any help will be appreciated. I know that I should use a while loop to emulate recursion. But how can I separate the actual values? Also, how can I track the middle of the divided values?
I am really confused by this problem. Any help would be appreciated!
java
svsav Feb 20 '14 at 2:55 a.m. 2014-02-20 02:55
source share