Website Summary Files Commits Branches @commit @diff @stats
path: root / Week10 / Exercise08.cpp
blob: 3d558e10cb83f93fec1dd3e5231f992203200401 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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;
}