-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkedListNode.java
60 lines (48 loc) · 1.06 KB
/
LinkedListNode.java
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
public class LinkedListNode<Anytype> {
private Anytype head;
private LinkedListNode<Anytype> next;
private int listCount;
public LinkedListNode(){
this.head = null;
this.next = null;
this.listCount = 0;
}
public LinkedListNode(Anytype head){
this.head = head;
this.next = null;
this.listCount = 0;
}
public void add(Anytype data){
LinkedListNode<Anytype> newLink = new LinkedListNode<>();
LinkedListNode<Anytype> temporalLink = this;
newLink.setHead(data);
if (this.head == null) {
this.head = data;
}
else{
while (temporalLink.getNext() != null) {
temporalLink = temporalLink.getNext();
}
temporalLink.setNext(newLink);
}
this.listCount++;
}
public Anytype getHead() {
return head;
}
public void setHead(Anytype head) {
this.head = head;
}
public LinkedListNode<Anytype> getNext() {
return next;
}
public void setNext(LinkedListNode<Anytype> next) {
this.next = next;
}
public int getListCount() {
return listCount;
}
public void setListCount(int listCount) {
this.listCount = listCount;
}
}