0

Hi, i just started taking java in uni and im a little stumped, our assignment is to do this.

Complete the body of the following method, as indicated by the comment:

class Q2 {

/** Sort the 'partially sorted' array 'p' into nondecreasing order.
    Requires: 0 <= i <= p.length and 'p' consists of two sorted pieces
    p[0..i-1] and p[i..p.length-1] in nondecreasing order.
    @param p  partially sorted array.
    @param i  starting index of second sorted piece of p. */

public static void sortTogether(int[] p, int i) {

  int i0 = 0;
  int i1 = i;
  int[] temp = new int[p.length];
  int t = 0;
  while (i0 < i && i1 < p.length) {
    if (p[i0] < p[i1]) {
      temp[t] = p[i0];
      ++i0;
    } else {
      temp[t] = p[i1];
      ++i1;
    }
    ++t;
  }

  // FILL IN THIS PART.
  // Use arraycopy (perhaps more than once) to complete
  //  the method. Do not use any more loops.

}
}

Im not quite sure where to begin, or even what im supposed to do, any help would be appreciated.

Edited by pyTony: fixed formatting

2
Contributors
1
Reply
2
Views
10 Years
Discussion Span
Last Post by jwenting
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.