Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // the c-string max() doesn't work yet, but the array max() should pass all tests
- int max (int a, int b) {
- if (a > b)
- return a;
- else
- return b;
- }
- int max(int a, int b, int c, int d, int e, int f){
- return max( max( max(e,f) , max(c,d)), max(a,b));
- }
- double max (double a, double b){
- if (a > b)
- return a;
- else
- return b;
- }
- char max (char a, char b){
- if (a > b)
- return a;
- else
- return b;
- }
- int* max (int* A, int aLen, int* B, int bLen){
- int cLen = max(aLen, bLen);
- int* C = new int[cLen];
- int curMax = 0;
- for (int i = 0; i < cLen; i++) {
- // if both have an index at i, compare the two and get curMax
- if (aLen >= i && bLen >= i) {
- curMax = max(A[i], B[i]);
- } else if (aLen >= i && bLen < i) {
- curMax = A[i];
- } else if (bLen >= i && aLen < i) {
- curMax = B[i];
- }
- // else curMax = the one that IS still there
- C[i] = curMax;
- }
- return C;
- }
- char* max (char* a, char* b) {
- return a;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement