- Write a function that will add all the elements in an array
Pass the array and the size of the array as parameters. Return the sum
as the result of the function.
- Write a function that will count the number of elements less than x
Pass the value of x, the array. and the size of the array as parameters. Return the count of the number of elements less than x as the result of the function.
- Write a function to put the maximum element at the end
Pass the array. and the size of the array as parameters. The function
should not return anything.
- Write a function to put the minimum element from the range s through e
at the beginning of that range.
Pass the array. and the size of the array as parameters, along with the values
of s and e, which represent index values (e.g. positions in the array). So, the minimum element in the positions between array[s] and array[e] should be swappes with the element in position [s]. The function
should not return anything.
- Write a function to reverse all the elements of the array (in place)
- Write a function to insert an element into a sorted list. You should
pass the size of the array by reference and increment it.
- Write a function to insert an element only if that element does not
already exist, and increment the count only if it changes. Pass the
count by reference. Write two versions: one assuming the array is
sorted, the other that DOESN'T assume the array is sorted.
- Write a function to count the number of occurences of x
- Write a function to change every occurence of x to y
- Write a function to find the position of the first occurence of some element x.
Pass in the array by reference, as well as the number of elements in the array
(n). Pass n by value, and pass in the value of x by value. Return
the index as the result of the function. If the value is not found,
return -1.
For example:
int nums[6] = {34, 1, 7, 89, 21, 5};
pos1 = findOccurence (nums,6,3); /* returns -1 */
pos2 = findOccurence (nums,6,89); /* returns 3 */
- Write a function to find the position of the last occurence of some element x.
Pass in the array by reference, as well as the number of elements in the array
(n). Pass n by value, and pass in the value of x by value. Return
the index as the result of the function. If the value is not found,
return -1.
For example:
int nums[6] = {34, 1, 7, 89, 21, 89};
pos1 = findLastOccurence (nums,6,3); /* returns -1 */
pos2 = findLastOccurence (nums,6,89); /* returns 5 */
- Write a function to find the first occurence of the x in the range
between s and e
- Write a function that prints out the position of every occurence of
x in the array. The output should look like this:
Element 4 occurs in position 2
Element 4 occurs in position 5
Element 4 occurs in position 9