-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayList.h
57 lines (48 loc) · 1.18 KB
/
ArrayList.h
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
51
52
53
54
55
#pragma once
namespace MyLib
{
template <typename T>
struct ArrayList
{
public:
ArrayList();
/// Append the specified element, |elem| to the end of this list
void add(T elem);
/// Return the element at the specified position, |index| in this list
T get(int index);
/// Return the number of elements in this list
int size();
private:
T* _elements; //< array of elements
int _capacity; //< length of array
int _size; //< number of elements added
};
/// Construct a new empty list
template <typename T>
inline ArrayList<T>::ArrayList()
{
_elements = new T[10]();
_size = 0;
_capacity = 10;
}
/// TODO
template <typename T>
inline void ArrayList<T>::add( T elem )
{
// TODO: Check size
_elements[_size] = elem;
_size++;
}
/// TODO
template <typename T>
inline T ArrayList<T>::get( int index )
{
// TODO: Check for valid index
return _elements[index];
}
template <typename T>
inline int ArrayList<T>::size()
{
return _size;
}
}