쉬운 ver.
template <class T>
void reverseArray(T arr[], int capacity) {
T *tp = new T[capacity];
for (int i = 0; i < capacity; i++)
tp[i] = arr[i];
for (int i = 0 ; i < capacity; i++)
arr[i] = tp[capacity - 1 - i];
delete[] tp;
}
효율적인 ver.
template <class T>
void reverseArray(T array[], int size) {
T temp;
for (int i = 0; i < size / 2; i++) {
temp = array[i];
array[i] = array[(size - 1) - i];
array[(size - 1) - i] = temp;
}
}
'Coding > 함수' 카테고리의 다른 글
system 함수 - system("pause") (0) | 2019.10.18 |
---|---|
stoi() 함수 직접 구현하기 (0) | 2019.10.18 |
exit 함수 (0) | 2019.09.30 |
난수 생성 (0) | 2019.09.28 |
to_string (0) | 2019.09.22 |