forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from honokaBiu/master
Sync
- Loading branch information
Showing
37 changed files
with
1,082 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>333</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>L365689789</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
175 changes: 175 additions & 0 deletions
175
...p20/1107837739/1107837739Learning/src/org/korben/coding/basic/list/KDoubleLinkedList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
package org.korben.coding.basic.list; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Korben's LinkedList | ||
* | ||
* Created by Korben on 18/02/2017. | ||
*/ | ||
public class KDoubleLinkedList<T> implements KList<T> { | ||
|
||
private int size; | ||
|
||
private Node<T> head; | ||
|
||
private Node<T> last; | ||
|
||
public KDoubleLinkedList() { | ||
this.head = new Node<>(null); | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return this.size; | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return this.size == 0; | ||
} | ||
|
||
@Override | ||
public boolean contains(Object o) { | ||
Node node = this.head; | ||
while (node.next != null) { | ||
node = node.next; | ||
if (Objects.equals(node.data, o)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public Object[] toArray() { | ||
return new Object[0]; | ||
} | ||
|
||
@Override | ||
public boolean add(T o) { | ||
if (this.last == null) { | ||
this.last = new Node<>(o); | ||
this.last.pre = this.head; | ||
this.head.next = this.last; | ||
} else { | ||
Node<T> oldLast = this.last; | ||
this.last = new Node<>(o); | ||
this.last.pre = oldLast; | ||
oldLast.next = this.last; | ||
} | ||
this.size++; | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean remove(T o) { | ||
Node node = this.head; | ||
while (node.next != null) { | ||
node = node.next; | ||
if (Objects.equals(node.data, o)) { | ||
node.pre.next = node.next; | ||
if (node.next != null) { | ||
node.next.pre = node.pre; | ||
} | ||
this.size--; | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
this.head.next = null; | ||
this.last = null; | ||
|
||
this.size = 0; | ||
} | ||
|
||
@Override | ||
public T get(int index) { | ||
return getNode(index).data; | ||
} | ||
|
||
@Override | ||
public T set(int index, T element) { | ||
Node<T> node = getNode(index); | ||
node.data = element; | ||
return element; | ||
} | ||
|
||
@Override | ||
public void add(int index, T element) { | ||
if (index <= 0 || index >= this.size) { | ||
throw new IndexOutOfBoundsException(); | ||
} | ||
Node<T> node = this.head; | ||
for (int i = 0; i <= index; i++) { | ||
node = node.next; | ||
} | ||
Node<T> pre = node.pre; | ||
Node<T> newNode = new Node<>(element); | ||
pre.next = newNode; | ||
newNode.pre = pre; | ||
newNode.next = node; | ||
node.pre = newNode; | ||
|
||
this.size++; | ||
} | ||
|
||
@Override | ||
public T remove(int index) { | ||
Node<T> node = getNode(index); | ||
Node<T> pre = node.pre; | ||
Node<T> next = node.next; | ||
pre.next = next; | ||
if (next != null) { | ||
next.pre = pre; | ||
} | ||
|
||
this.size--; | ||
return node.data; | ||
} | ||
|
||
@Override | ||
public int indexOf(T o) { | ||
Node node = this.head; | ||
int index = 0; | ||
while (node.next != null) { | ||
node = node.next; | ||
if (Objects.equals(node.data, o)) { | ||
return index; | ||
} | ||
index++; | ||
} | ||
return -1; | ||
} | ||
|
||
@Override | ||
public KIterator<T> iterator() { | ||
throw new UnsupportedOperationException("方法未实现"); | ||
} | ||
|
||
private Node<T> getNode(int index) { | ||
if (index < 0 || index >= size) { | ||
throw new IndexOutOfBoundsException(); | ||
} | ||
|
||
Node<T> node = this.head; | ||
for (int i = 0; i <= index; i++) { | ||
node = node.next; | ||
} | ||
return node; | ||
} | ||
|
||
private static class Node<T> { | ||
T data; | ||
Node<T> pre; | ||
Node<T> next; | ||
|
||
Node(T data) { | ||
this.data = data; | ||
} | ||
} | ||
} |
Oops, something went wrong.