Skip to content

Commit 4116f15

Browse files
authored
Merge pull request onlyliuxin#7 from honokaBiu/master
Sync
2 parents b8c763d + b36c1e0 commit 4116f15

37 files changed

+1082
-45
lines changed

group17/333333/.classpath

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>

group17/333333/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/

group17/333333/.project

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>333</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

group17/365689789/.classpath

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>

group17/365689789/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/

group17/365689789/.project

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>L365689789</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
package org.korben.coding.basic.list;
2+
3+
import java.util.Objects;
4+
5+
/**
6+
* Korben's LinkedList
7+
*
8+
* Created by Korben on 18/02/2017.
9+
*/
10+
public class KDoubleLinkedList<T> implements KList<T> {
11+
12+
private int size;
13+
14+
private Node<T> head;
15+
16+
private Node<T> last;
17+
18+
public KDoubleLinkedList() {
19+
this.head = new Node<>(null);
20+
}
21+
22+
@Override
23+
public int size() {
24+
return this.size;
25+
}
26+
27+
@Override
28+
public boolean isEmpty() {
29+
return this.size == 0;
30+
}
31+
32+
@Override
33+
public boolean contains(Object o) {
34+
Node node = this.head;
35+
while (node.next != null) {
36+
node = node.next;
37+
if (Objects.equals(node.data, o)) {
38+
return true;
39+
}
40+
}
41+
return false;
42+
}
43+
44+
@Override
45+
public Object[] toArray() {
46+
return new Object[0];
47+
}
48+
49+
@Override
50+
public boolean add(T o) {
51+
if (this.last == null) {
52+
this.last = new Node<>(o);
53+
this.last.pre = this.head;
54+
this.head.next = this.last;
55+
} else {
56+
Node<T> oldLast = this.last;
57+
this.last = new Node<>(o);
58+
this.last.pre = oldLast;
59+
oldLast.next = this.last;
60+
}
61+
this.size++;
62+
return true;
63+
}
64+
65+
@Override
66+
public boolean remove(T o) {
67+
Node node = this.head;
68+
while (node.next != null) {
69+
node = node.next;
70+
if (Objects.equals(node.data, o)) {
71+
node.pre.next = node.next;
72+
if (node.next != null) {
73+
node.next.pre = node.pre;
74+
}
75+
this.size--;
76+
return true;
77+
}
78+
}
79+
return false;
80+
}
81+
82+
@Override
83+
public void clear() {
84+
this.head.next = null;
85+
this.last = null;
86+
87+
this.size = 0;
88+
}
89+
90+
@Override
91+
public T get(int index) {
92+
return getNode(index).data;
93+
}
94+
95+
@Override
96+
public T set(int index, T element) {
97+
Node<T> node = getNode(index);
98+
node.data = element;
99+
return element;
100+
}
101+
102+
@Override
103+
public void add(int index, T element) {
104+
if (index <= 0 || index >= this.size) {
105+
throw new IndexOutOfBoundsException();
106+
}
107+
Node<T> node = this.head;
108+
for (int i = 0; i <= index; i++) {
109+
node = node.next;
110+
}
111+
Node<T> pre = node.pre;
112+
Node<T> newNode = new Node<>(element);
113+
pre.next = newNode;
114+
newNode.pre = pre;
115+
newNode.next = node;
116+
node.pre = newNode;
117+
118+
this.size++;
119+
}
120+
121+
@Override
122+
public T remove(int index) {
123+
Node<T> node = getNode(index);
124+
Node<T> pre = node.pre;
125+
Node<T> next = node.next;
126+
pre.next = next;
127+
if (next != null) {
128+
next.pre = pre;
129+
}
130+
131+
this.size--;
132+
return node.data;
133+
}
134+
135+
@Override
136+
public int indexOf(T o) {
137+
Node node = this.head;
138+
int index = 0;
139+
while (node.next != null) {
140+
node = node.next;
141+
if (Objects.equals(node.data, o)) {
142+
return index;
143+
}
144+
index++;
145+
}
146+
return -1;
147+
}
148+
149+
@Override
150+
public KIterator<T> iterator() {
151+
throw new UnsupportedOperationException("方法未实现");
152+
}
153+
154+
private Node<T> getNode(int index) {
155+
if (index < 0 || index >= size) {
156+
throw new IndexOutOfBoundsException();
157+
}
158+
159+
Node<T> node = this.head;
160+
for (int i = 0; i <= index; i++) {
161+
node = node.next;
162+
}
163+
return node;
164+
}
165+
166+
private static class Node<T> {
167+
T data;
168+
Node<T> pre;
169+
Node<T> next;
170+
171+
Node(T data) {
172+
this.data = data;
173+
}
174+
}
175+
}

0 commit comments

Comments
 (0)