53 lines
1.3 KiB
C++
53 lines
1.3 KiB
C++
|
//
|
||
|
// Created by caleb on 3/16/24.
|
||
|
//
|
||
|
|
||
|
#include <string>
|
||
|
|
||
|
int * reverseArray(int arr[], int size) {
|
||
|
int* newArray = new int[size];
|
||
|
int j = 0;
|
||
|
int * temp; // dereference pointer FTW
|
||
|
for (int i = (size - 1); i >= 0; --i) {
|
||
|
temp = &arr[i];
|
||
|
newArray[j++] = *temp;
|
||
|
}
|
||
|
return newArray;
|
||
|
}
|
||
|
int * arrayExpander( int arr[], int size) {
|
||
|
int * newArray = new int[(size * 2)];
|
||
|
int * temp; // dereference pointer FTW
|
||
|
for (int i = 0; i < (size * 2); ++i) {
|
||
|
if (i < size) {
|
||
|
temp = &arr[i];
|
||
|
newArray[i] = *temp;
|
||
|
} else {
|
||
|
newArray[i] = 0;
|
||
|
}
|
||
|
}
|
||
|
return newArray;
|
||
|
}
|
||
|
int * elementShifter( int arr[], int size) {
|
||
|
int * newArray = new int[(size + 1)];
|
||
|
int * temp; // dereference pointer FTW
|
||
|
// set first value to zero
|
||
|
newArray[0] = 0;
|
||
|
int j = 0;
|
||
|
for (int i = 1; i < (size + 1); ++i) {
|
||
|
temp = &arr[j++];
|
||
|
newArray[i] = *temp;
|
||
|
}
|
||
|
return newArray;
|
||
|
}
|
||
|
|
||
|
void printArray(int arr[], int size) {
|
||
|
std::string printString = "{";
|
||
|
for (int i = 0; i < size; ++i) {
|
||
|
printString.append(std::to_string(arr[i]));
|
||
|
if (i < (size - 1)) {
|
||
|
printString.append(", ");
|
||
|
}
|
||
|
}
|
||
|
printString.append("}");
|
||
|
printf("%s\n", printString.c_str());
|
||
|
}
|