1: // @author Frank M. Carrano, Timothy M. Henry
2: // @version 5.0
3: public void displayArray(int first, int last)
4: {
5: boolean done = false;
6: StackInterface<Record> programStack = new LinkedStack<>();
7: programStack.push(new Record(first, last));
8: while (!done && !programStack.isEmpty())
9: {
10: Record topRecord = programStack.pop();
11: first = topRecord.first;
12: last = topRecord.last;
13:
14: if (first == last)
15: System.out.println(array[first] + " ");
16: else
17: {
18: int mid = first + (last - first) / 2;
19: // Note the order of the records pushed onto the stack
20: programStack.push(new Record(mid + 1, last));
21: programStack.push(new Record(first, mid));
22: } // end if
23: } // end while
24: } // end displayArray