Website Summary Files Commits Branches @commit @diff @stats
path: root / Week10 / Exercise08.cpp
diff options
context:
space:
mode:
1 files changed, 50 insertions, 0 deletions
-rw-r--r--Week10/Exercise08.cpp50
diff --git a/Week10/Exercise08.cpp b/Week10/Exercise08.cpp
new file mode 100644
index 0000000..3d558e1
--- /dev/null
+++ b/Week10/Exercise08.cpp
@@ -0,0 +1,50 @@
+#include <iostream>
+
+void resizeArray(int*& arr, unsigned int& size) {
+ int* newArr = new int[size * 2];
+ for (unsigned int i = 0; i < size; i++)
+ newArr[i] = arr[i];
+
+ delete[] arr;
+ arr = newArr;
+ size *= 2;
+}
+
+int main() {
+ unsigned int countA = 0, sizeA = 4, countB = 0, sizeB = 4;
+ int* arrA = new int[sizeA], *arrB = new int[sizeB];
+
+ bool even = true;
+ int temp;
+ std::cin >> temp;
+
+ while (temp > 0) {
+ if (even) {
+ arrA[countA++] = temp;
+ if (countA >= sizeA)
+ resizeArray(arrA, sizeA);
+ }
+ else {
+ arrB[countB++] = temp;
+ if (countB >= sizeB)
+ resizeArray(arrB, sizeB);
+ }
+
+ even = !even;
+ std::cin >> temp;
+ }
+
+ unsigned int count = (countA > countB) ? countA : countB;
+ for (unsigned int i = 0; i < count; i++) {
+ if (i < countB)
+ std::cout << arrB[countB - 1 - i] << ' ';
+ if (i < countA)
+ std::cout << arrA[i] << ' ';
+ }
+ std::cout << std::endl;
+
+ delete[] arrA;
+ delete[] arrB;
+
+ return 0;
+}