Skip to content

Commit c846a5c

Browse files
committed
added the LLnode implementation
1 parent 5c66689 commit c846a5c

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Linked-Lists/LinkedListNode.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Linked List Implementation
3+
4+
*/
5+
6+
class LinkedListNode {
7+
int data;
8+
LinkedListNode next;
9+
LinkedListNode prev;
10+
11+
public LinkedListNode() {
12+
13+
}
14+
15+
public LinkedListNode(int d, LinkedListNode n, LinkedListNode p) {
16+
data = d;
17+
this.setNext(n);
18+
this.setPrev(p);
19+
}
20+
21+
public void setNext(LinkedListNode n) {
22+
next = n;
23+
if(n != null && n.prev != this) {
24+
n.setPrev(this);
25+
}
26+
}
27+
public void setPrev(LinkedListNode p) {
28+
prev = p;
29+
if(p != null && p.next != this) {
30+
this.setNext(p);
31+
}
32+
}
33+
34+
public String printNode() {
35+
if(next != null) {
36+
return data + ":" + next.printNode();
37+
}
38+
else
39+
return ((Integer) data).toString();
40+
}
41+
42+
public static void main(String[] args) {
43+
LinkedListNode first = new LinkedListNode(10, null, null);
44+
LinkedListNode sec = new LinkedListNode(20, null, null);
45+
first.setNext(sec);
46+
System.out.println(first.printNode());
47+
}
48+
}

0 commit comments

Comments
 (0)