Other 2017 FR Questions FR other years Be Prepared Home
A-4
Part (a)
  public static Position findPosition(int num, int[][] intArr)
  {
    for (int r = 0; r < intArr.length; r++)
      for (int c = 0; c < intArr[0].length; c++) 1
        if (intArr[r][c] == num)
          return new Position(r, c);
    return null;
  }
Notes:
  1. Only rectangular arrays are in the AP subset, and the precondition guarantees that intArr has at least one row.


Part (b)
  public static Position[][] getSuccessorArray(int[][] intArr)
  {
    int rows = intArr.length;
    int cols = intArr[0].length;

    Position[][] succ = new Position[rows][cols];

    for (int r = 0; r < rows; r++)
    {
      for (int c = 0; c < cols; c++)
      {
        int num = intArr[r][c];
        succ[r][c] = findPosition(num + 1, intArr);
      }
    }
    return succ;
  }


Other 2017 FR Questions | Back to Contents

Copyright © 2017 by Skylight Publishing
support@skylit.com