-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmoreArrayFuncs.h
More file actions
executable file
·80 lines (60 loc) · 2.74 KB
/
moreArrayFuncs.h
File metadata and controls
executable file
·80 lines (60 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef MOREARRAYFUNCS_H
#define MOREARRAYFUNCS_H
#include <cassert>
// a: an array of ints. size is how many ints in array
// Return the index of largest value.
// If more than one element has largest value,
// break tie by returning the smallest index that
// corresponds to an element with the largest value.
// You may assume size >= 1
int indexOfMax(int *a, int size);
// a: an array of ints. size is how many ints in array
// Return the index of smallest value.
// If more than one element has largest value,
// break tie by returning the smallest index that
// corresponds to an element with the largest value.
// You may assume size >= 1
int indexOfMin(int *a, int size);
// a: an array of ints. size is how many ints in array
// Return the largest value in the list.
// This value may be unique, or may occur more than once
// You may assume size >= 1
int largestValue(int *a, int size);
// a: an array of ints. size is how many ints in array
// Return the smallest value in the list.
// This value may be unique, or may occur more than once
// You may assume size >= 1
int smallestValue(int *a, int size);
// a: an array of ints. size is how many ints in array
// Return the sum of all the elements in the array
// size may be 0 in this case, or non-zero.
int sum(int *a, int size);
// dest is an array of int that has capacity at LEAST of size n
// (whatever is in dest will be written over, so is irrelevant)
// src is an array of int of at least size n
// n is number of elements in src to be copied
// copy n elements from src to dest.
void copyElements(int *dest, int *src, int n);
// dest is an array of int that has capacity at LEAST of size n
// (whatever is in dest will be written over, so is irrelevant)
// src is an array of int of at least size n
// n is number of elements in src to be copied
// copy ONLY the elements with odd values from src to dest.
// return the number of elements that were copied
int copyOddOnly(int *dest, int *src, int n);
// a, b and product are all arrays of size n (or greater)
// in each case, only the first n elements of a, b and product are used
// a and b have their values read, and are unchanged
// the old values in product are ignored, and overwritten.
// After this function, each element of product should
// contain the product of the corresponding elements of
// a and b.
// Example if a is {1,2,3,4} b is {3,5,7,9} and n=4,
// then after a call to multiplePairwise(a,b,product,4),
// product will be {3,10,21,36}.
void multiplyPairwise(int *a, int *b, int *product, int n);
// len is the number of elements the array you create should contain
// you should return a pointer to the new integer array of size len
// with all of the elements in it set to 0
int* createArray(int len);
#endif