-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParty.cpp
More file actions
106 lines (88 loc) · 2.12 KB
/
Copy pathParty.cpp
File metadata and controls
106 lines (88 loc) · 2.12 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
/*********************************************************************
** Program name: FinalProject
** Author: James Scanlon
** Date: March 19, 2019
** Description: Implementation of the Party class.
*********************************************************************/
#include "Party.hpp"
#include <iostream>
using namespace std;
// Constructor
Party::Party()
{
head = new pokemonNode(NULL);
tail = head;
}
bool Party::isEmpty()
{
return head == NULL;
}
void Party::addBack(Pokemon* pokemonInput)
{
if (head->pokemon == NULL) // empty case
{
head->pokemon = pokemonInput;
tail = head;
}
else // case for > 1 node
{
pokemonNode* newNode = head;
while (newNode->next != NULL)
{
newNode = newNode->next;
}
newNode->next = new pokemonNode(pokemonInput, newNode);
tail = newNode->next;
}
}
Pokemon* Party::getFront()
{
return this->head->pokemon;
}
void Party::removeFront()
{
if (isEmpty()) // empty check
{
return;
}
pokemonNode *deleteNode = head;
head = deleteNode->next;
if (isEmpty())
{
tail = head;
}
if (head)
{
head->prev = NULL;
if (head == tail)
{
tail->next = NULL;
}
}
delete deleteNode;
}
void Party::pokemonToBack() // used for winning fighters
{
if (!head)
return;
this->addBack(head->pokemon);
this->removeFront();
}
void Party::reversePrint() // used for printing losers
{
pokemonNode* temp = tail;
while (temp->prev != NULL)
{
std::cout << temp->pokemon->getName() << " " << "(" << temp->pokemon->getType() << ")" << endl;
temp = temp->prev;
}
std::cout << temp->pokemon->getName() << " " << "(" << temp->pokemon->getType() << ")" << endl;
}
// Deconstructor
Party::~Party()
{
while (!isEmpty()) // iterate through and remove values until isEmpty
{
removeFront();
}
}