-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList.cpp
More file actions
89 lines (69 loc) · 1.57 KB
/
LinkedList.cpp
File metadata and controls
89 lines (69 loc) · 1.57 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
#include "LinkedList.h"
Node::Node(std::string data, Node::Node* nxtNode)
:
data_(data), nextNode_(nxtNode)
{}
Node::Node(std::string data)
:
data_(data), nextNode_(NULL)
{}
std::string Node::getData(){
return this->data_;
}
bool Node::setData(std::string data){
this->data_ = data;
return true;
}
Node::Node* Node::getNextNode(){
return this->nextNode_;
}
bool Node::setNextNode(Node* nxtNode){
this->nextNode_ = nxtNode;
return true;
}
int SingleLinkedList::insertNodeEnd(Node* insNode){
Node* curr = this->head;
while(curr){
curr = curr->getNextNode();
}
curr->setNextNode(insNode);
return 0;
}
int SingleLinkedList::insertNodeBeg(Node* insNode){
insNode->setNextNode(this->head);
this->head = insNode;
return 0;
}
int SingleLinkedList::searchNode(std::string data){
Node* curr = this->head;
while(curr){
if(!data.compare(curr->getData())) return 0;
// if(!(std::strcpm((curr->getData()).c_str(),data.c_str()))) return 0;
curr = curr->getNextNode();
}
return 1;
}
int SingleLinkedList::deleteNode(std::string data){
Node* prv = this->head;
Node* curr;
while(prv){
curr = prv->getNextNode();
if(curr && !data.compare(curr->getData())){//std::strcmp((curr->getData()).c_str(),data.c_str())){
prv->setNextNode(curr->getNextNode());
return 0;
}
prv = curr;
}
return 1;
}
Node* SingleLinkedList::returnListHead(){
return this->head;
}
SingleLinkedList::SingleLinkedList()
:
head(NULL)
{}
SingleLinkedList::SingleLinkedList(Node* headNode)
:
head(headNode)
{}