Need some help filling in the function at the bottom of code

Need some help filling in the function at the bottom of code labeled /******* *******/.

The function will take in a list of the number of activities for each day. The function should also take in a starting day and an ending day to create a range. The function should then return the day number with the fewest activities in that range.

For example, if the input array looked like this:

index

0

1

2

3

4

5

6

7

8

9

10

11

# activities

8

3

6

7

9

5

3

8

6

7

4

5

and the start day of the request was 2 and the end day of the request was 9, the answer would be 6, since on day 6 there are only 3 activities and this is less than any of the other days.

Since you like getting things out of the way as early as possible, if there are multiple days that are the \"least busy\" in the given interval, return the day that is earliest. For example, if you were given the query day 0 to day 10 with the array above, your function should return 1, since day 1 is the first day with only 3 activities planned.

Here is the code I have so far. The part I need is at the bottom.

#include <stdio.h>

#define MAX 100

int findMinIndex(int data[], int low, int high);

int main() {

int i, loop, n, queries, data[MAX];

FILE* ifp = fopen(\"schedule.in\", \"r\");

fscanf(ifp, \"%d\", &n);

for (i=0; i<n; i++)

fscanf(ifp, \"%d\", &data[i]);

fscanf(ifp, \"%d\", &queries);

for (loop=0; loop<queries; loop++) {

int low, high;

fscanf(ifp, \"%d%d\", &low, &high);

printf(\"%d\ \", findMinIndex(data, low, high));

}

return 0;

}

// Pre-condition: low <= high and are both valid indexes to data.

// Post-condition: Returns the lowest index in [low, high] storing the minimum of array[low]…array[high].

int findMinIndex(int data[], int low, int high) {

/*******Fill this in*******/.

return 0;

index

0

1

2

3

4

5

6

7

8

9

10

11

# activities

8

3

6

7

9

5

3

8

6

7

4

5

Solution

public static int findMinIndex(int[] data, int low,int high) { int minIndex; if (low == data.length - 1) return index; minIndex = findMinIndex(data, low + 1); if (data[minIndex] < data[low]) return minIndex; else return index; }
Need some help filling in the function at the bottom of code labeled /******* *******/. The function will take in a list of the number of activities for each da
Need some help filling in the function at the bottom of code labeled /******* *******/. The function will take in a list of the number of activities for each da

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site