/**
* Names: Luke Whipple and Colton Johnson
*
* A simple warm-up program to prepare us for usiong arrays in the future.
*/
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <stdlib.h>
#include <math.h>
#include "array_utils.h"
int contains(const int * arr, int size, int x) {
if ((arr == NULL) || (size <= 0)) {
return 0;
}
return(containsWithin(arr, size, x, 0, size - 1));
}
int containsWithin(const int * arr, int size, int x, int i, int j) {
int n;
if ((arr == NULL) || (i < 0) || (j < 0) || (size <= 0) || (j >= size) || (i >= size)) {
return 0;
}
for (n = i; n <= j; n++) {
if (arr[n] == x) {
return (1);
}
}
return (0);
}
int * paddedCopy(const int * arr, int oldSize, int newSize) {
if ((arr == NULL) || (oldSize < 0) || (newSize < 0)) {
return NULL;
}
if (oldSize < newSize) {
int * copy = (int * ) malloc(newSize * sizeof(int));
for (int i = 0; i < oldSize; i++) {
copy[i] = arr[i];
}
for (int i = oldSize; i < newSize; i++) {
copy[i] = 0;
}
return (copy);
}
if (newSize < oldSize) {
int * copy = (int * ) malloc(newSize * sizeof(int));
for (int i = 0; i < newSize; i++) {
copy[i] = arr[i];
}
return (copy);
}
if (newSize == oldSize) {
int * copy = (int * ) malloc(oldSize * sizeof(int));
for (int i = 0; i < oldSize; i++) {
copy[i] = arr[i];
}
return(copy);
}
return(0);
}
void reverse(int * arr, int size) {
int k = 0;
for (int i = size - 1; i >= size/2; i--) {
int placeHolder = arr[i];
arr[i] = arr[k];
arr[k] = placeHolder;
k++;
}
}
int * reverseCopy(const int * arr, int size) {
if (arr == NULL || size < 0) {
return NULL;
}
int *copy = paddedCopy(arr, size, size);
reverse(copy, size);
return copy;
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}