Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0ec1d53

Browse files
Update List.java
1 parent 24270e3 commit 0ec1d53

File tree

1 file changed

+20
-22
lines changed
  • algorithms/src/main/java/ivanmarkovic/algorithms/linkedlists/circulardoublylinkedlist

1 file changed

+20
-22
lines changed

‎algorithms/src/main/java/ivanmarkovic/algorithms/linkedlists/circulardoublylinkedlist/List.java

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,29 @@ public void printAll() {
4242
System.out.println();
4343
}
4444

45-
public void addToHead(int payload) {
46-
if(this.isEmpty()) {
47-
this.head = this.tail = new Node(payload);
48-
this.head.prev = this.tail;
49-
this.tail.next = this.head;
45+
public void addToHead(int val){
46+
if(this.isEmpty()){
47+
this.head = this.tail = new Node(val);
48+
this.head.prev = this.tail;
5049
}
5150
else {
52-
this.head = new Node(payload, this.tail, this.head);
53-
this.head.next.prev = this.head;
54-
this.tail.next = this.head;
51+
this.head = new Node(val, this.tail, this.head);
52+
this.head.next.prev = this.head;
5553
}
56-
}
57-
58-
publicvoidaddToTail(intpayload) {
59-
if(this.isEmpty()) {
60-
this.head = this.tail = newNode(payload);
61-
this.head.prev = this.tail;
62-
this.tail.next = this.head;
63-
}
64-
else {
65-
this.tail.next = new Node(payload, this.tail, this.head);
66-
this.tail = this.tail.next;
67-
this.head.prev = this.tail;
68-
}
69-
}
54+
this.tail.next = this.head;
55+
}
56+
57+
publicvoidaddToTail(intval){
58+
if(this.isEmpty()){
59+
this.head = this.tail = newNode(val);
60+
this.tail.next = this.head;
61+
}
62+
else {
63+
this.tail.next = new Node(val, this.tail, this.head);
64+
this.tail = this.tail.next;
65+
}
66+
this.head.prev = this.tail;
67+
}
7068

7169
public Integer deleteFromHead() {
7270
if(this.isEmpty())

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /