-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.h
More file actions
46 lines (40 loc) · 891 Bytes
/
node.h
File metadata and controls
46 lines (40 loc) · 891 Bytes
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
#include <iostream>
using namespace std;
class Node {
int data;
Node* next = nullptr;
public:
Node();
Node(int d): data(d) { }
int getData() { return data; }
void setData(int a) { data = a; }
Node* getNext() { return next; }
void setNext(Node* n) { next = n; }
void printList() {
cout << data;
if(next != nullptr) {
next->printList_();
}
cout << endl;
}
void printList_() {
cout << data;
if(next != nullptr) {
next->printList_();
}
}
void addNode(int d) {
if(next == nullptr) {
next = new Node(d);
} else {
next->addNode(d);
}
}
int getLength() {
if (next != nullptr) {
return 1 + next->getLength();
} else {
return 1;
}
}
};//class Node