-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayList.cpp
77 lines (60 loc) · 1.31 KB
/
ArrayList.cpp
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef ARRAYLIST_CPP_INCLUDED
#define ARRAYLIST_CPP_INCLUDED
#include "ArrayList.h"
template <class T>
ArrayList<T>::ArrayList()
{
TotalSize = DEFAULT_SIZE;
data = new T[TotalSize];
}
template <class T>
ArrayList<T>::ArrayList(int size)
{
TotalSize = size;
data = new T[TotalSize];
}
template <class T>
ArrayList<T>::ArrayList(T* arr, int size)
{
TotalSize = size;
data = new T[TotalSize];
for (int i = 0; i < TotalSize; i++)
data[i] = arr[i];
}
template <class T>
ArrayList<T>::~ArrayList()
{
delete [] data;
}
template <class T>
ArrayList<T>::ArrayList(const ArrayList<T>& Other)
{
this->TotalSize = Other.TotalSize;
this->data = new T[TotalSize];
int i;
for (i = 0; i < TotalSize; i++)
data[i] = Other.data[i];
}
template <class T>
ArrayList<T>& ArrayList<T>::operator=(const ArrayList<T>& rhs)
{
delete [] data;
this->TotalSize = rhs.TotalSize;
this->data = new T[rhs.TotalSize];
int i;
for (i = 0; i < TotalSize; i++)
data[i] = rhs.data[i];
return *this;
}
template <class T>
void ArrayList<T>::expand()
{
int NewSize = TotalSize * INCREASE_FACTOR;
T* temp = new T[NewSize];
for (int i = 0; i < TotalSize; i++)
temp[i] = data[i];
delete [] data;
data = temp;
TotalSize = NewSize;
}
#endif