-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathList.cpp
93 lines (85 loc) · 1.7 KB
/
List.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include "List.h"
#include "Node.h"
#include <string>
using namespace std;
///////////////////////////////////////////////////////////////////////////////////////
// Public methods
//////////////////////////////////////////////////////////////////////////////////////
List::List()
{
root = NULL;
lenght = 0;
lastNode = NULL;
currentNode = NULL;
beforeCurrentNode = NULL;
}
List::~List()
{
if ((this->root) != NULL)
delete (root);
}
//List::List(string[] elements){}
int List::getLenght()
{
return lenght;
}
void List::add(string element)
{
Node *newNode = new Node();
newNode->setElement(element);
if (this->List::lastNode == NULL)
{
this->currentNode = newNode;
this->root = newNode;
this->lastNode = root;
}
else
{
lastNode->setNextNode(newNode);
}
this->lenght++;
}
bool List::isEmpty()
{
if ((this->root) == NULL)
return true;
else
return false;
}
bool List::deleteCurrent()
{
if (!isEmpty())
{
Node *nextNode = this->currentNode->getNextNode();
this->beforeCurrentNode->setNextNode(nextNode);
delete (currentNode);
return true;
}
else
return false;
}
bool List::editCurrent(string element)
{
if (element != "")
{
this->currentNode->setElement(element);
return true;
}
else
return false;
}
string List::getCurrent()
{
return this->currentNode->getElement();
}
void List::next()
{
this->beforeCurrentNode = this->currentNode;
this->currentNode = this->currentNode->getNextNode();
}
void List::reset()
{
this->currentNode = NULL;
this->beforeCurrentNode = NULL;
}