NUIMCrest SE307 - Computation and Complexity Theory
Class Test 1
Thursday 10 October 2001, 10:00, CS2

T Naughton, CS NUIM, Back to SE307 home


You have 25 minutes for both questions.


Q1 Write a function that takes an array A of positive integers and returns the index of the largest integer in A. If two or more indexes have this property, return the largest index. If A is empty, return -1. (Do not use the array.length operation; the end of array A will be marked by a -1.)

int findHighest(int A[]) {
  /* This function returns the index of the largest int in A.
  ** If there are multiple occurances of this int we return the
  ** last occurance. If the list has no elements, return -1.
  */

  // Your code here
}

Q2 Write a program to enumerate the integers (both positive and negative).

void enumerateInts(void) {

  // Your code here
}