Website Summary Files Commits Branches @commit @diff @stats
path: root / Week02 / Exercise03 / intarray.cpp
blob: 3d8853d2d642f0e622751342198daa67a602fc8a (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
#include "intarray.h"

void IntArray::deleteSelf() {
	delete[] elems;

	size = 0;
	elems = nullptr;
}

int IntArray::sum() {
	int totalSum = 0;
	for (unsigned i = 0; i < size; ++i)
		totalSum += elems[i];
	return totalSum;
}

IntArray newIntArray(unsigned size) {
	IntArray ia;
	ia.size = size;
	ia.elems = new int[size];

	return ia;
}

void deleteIntArray(IntArray& arr) {
	arr.deleteSelf();
}