-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinked_list.cpp
56 lines (46 loc) · 947 Bytes
/
linked_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
#include <iostream>
#include "linked_list"
using namespace std;
Node::Node(int val){
this->val = val;
this->next = NULL;
return;
};
int Node::get_value(){
return this->val;
};
Node* Node::get_next(){
return this->next;
}
bool Node::set_next(Node* node){
this->next = node;
return true;
}
linked_list::linked_list(){
this->head = NULL;
this->is_empty = true;
};
linked_list::~linked_list(){
};
bool linked_list::insert_node(Node* node){
if (this->is_empty){
this->head = node;
this->is_empty = false;
return true;
}
else {
Node* curr = this->head;
while (curr->get_next())
curr = curr->get_next();
curr->set_next(node);
return true;
}
};
bool linked_list::print_list(){
Node* curr = this->head;
while (curr){
cout << curr->get_value() << endl;
curr = curr->get_next();
}
return true;
};