-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjPosArrayList.cpp
More file actions
82 lines (71 loc) · 1.63 KB
/
Copy pathobjPosArrayList.cpp
File metadata and controls
82 lines (71 loc) · 1.63 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
#include "objPosArrayList.h"
// Paste your CUTE Tested implementation here.
// Paste your CUTE Tested implementation here.
// Paste your CUTE Tested implementation here.
objPosArrayList::objPosArrayList()
{
sizeList = 0;
sizeArray = ARRAY_MAX_CAP;
aList = new objPos[sizeArray];
}
objPosArrayList::~objPosArrayList()
{
delete[] aList;
}
int objPosArrayList::getSize()
{
return sizeList;
}
void objPosArrayList::insertHead(objPos thisPos)
{
if (sizeList < sizeArray) {
for (int i = sizeList; i > 0; --i) { // element shift for head
aList[i] = aList[i - 1];
}
aList[0] = thisPos;
++sizeList;
}
// case where the array is full, and resizing is needed
}
void objPosArrayList::insertTail(objPos thisPos)
{
if (sizeList < sizeArray) {
aList[sizeList] = thisPos;
++sizeList;
}
// case where the array is full, and resizing is needed
}
void objPosArrayList::removeHead()
{
if (sizeList > 0) {
for (int i = 0; i < sizeList - 1; ++i) {
aList[i] = aList[i + 1];
}
--sizeList;
}
}
void objPosArrayList::removeTail()
{
if (sizeList > 0) {
--sizeList;
}
}
void objPosArrayList::getHeadElement(objPos &returnPos)
{
if (sizeList > 0) {
returnPos = aList[0];
}
}
void objPosArrayList::getTailElement(objPos &returnPos)
{
if (sizeList > 0) {
returnPos = aList[sizeList - 1];
}
}
void objPosArrayList::getElement(objPos &returnPos, int index)
{
if (index >= 0 && index < sizeList) {
returnPos = aList[index];
}
// case where the index is out of bounds
}