Repository navigation
Expand file tree
/
Copy pathobjPosArrayList.cpp
More file actions
110 lines (79 loc) · 1.98 KB
/
Copy pathobjPosArrayList.cpp
File metadata and controls
110 lines (79 loc) · 1.98 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "objPosArrayList.h"
objPosArrayList::objPosArrayList() //constructor
{
listSize = 0;
arrayCapacity = ARRAY_MAX_CAP;
aList = new objPos [ARRAY_MAX_CAP];
}
objPosArrayList::~objPosArrayList() //destructor
{
delete[] aList;
}
objPosArrayList::objPosArrayList(const objPosArrayList &sList) //copy constructor
{
listSize = sList.listSize;
arrayCapacity = sList.arrayCapacity;
aList = new objPos [arrayCapacity];
for (int i = 0; i<listSize; i++){
aList[i] = sList.aList[i];
}
}
objPosArrayList& objPosArrayList::operator=(const objPosArrayList &sList) //copy assignment operator
{
if(this != &sList)
{
this->arrayCapacity = sList.arrayCapacity;
this->listSize = sList.listSize;
}
for (int i = 0; i< this->listSize; i++)
{
aList[i] = sList.aList[i];
}
}
int objPosArrayList::getSize() const //returns list size
{
return listSize;
}
void objPosArrayList::insertHead(objPos thisPos) //insert a head position
{
if (listSize == arrayCapacity){
return;
}
for (int i=listSize; i>0; i--){
aList[i] = aList[i-1];
}
aList[0] = thisPos;
listSize++;
}
void objPosArrayList::insertTail(objPos thisPos) //inserts a tail position
{
aList[listSize] = thisPos;
listSize++;
}
void objPosArrayList::removeHead() //removes head position
{
for (int i=0; i<listSize-2; i++)
{
aList[i] = aList[i+1];
}
listSize--;
}
void objPosArrayList::removeTail() //removes tail position
{
if (listSize == 0){
return;
}
listSize--;
}
objPos objPosArrayList::getHeadElement() const //returns what's at head position
{
return aList[0].getObjPos();
}
objPos objPosArrayList::getTailElement() const //returns what's at tail position
{
return aList[listSize-1].getObjPos();
}
objPos objPosArrayList::getElement(int index) const //returns the what's at the element position
{
return aList[index].getObjPos();
}