forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 5
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 #2 from HuiZhou-Xmu/master
Master
- Loading branch information
Showing
17 changed files
with
750 additions
and
0 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,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> | ||
<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>2017Learning</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> |
11 changes: 11 additions & 0 deletions
11
group01/1814014897/zhouhui/.settings/org.eclipse.jdt.core.prefs
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,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.8 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.8 |
74 changes: 74 additions & 0 deletions
74
group01/1814014897/zhouhui/src/week01/BasicDataStructure/ArrayList.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,74 @@ | ||
package week01.BasicDataStructure; | ||
|
||
import java.util.Arrays; | ||
|
||
public class ArrayList implements List { | ||
|
||
private int size = 0; | ||
|
||
private Object[] elementData = new Object[100]; | ||
|
||
public void add(Object o){ | ||
ensureCapacity(size + 1); //size increase,in order to have enough capacity. | ||
elementData[size++] = o; //similar to: elementData[size]=o; size++; | ||
} | ||
|
||
private void ensureCapacity(int minCapacity){ | ||
if(minCapacity > elementData.length){ | ||
grow(minCapacity); | ||
} | ||
} | ||
|
||
private void grow(int minCapacity){ | ||
int oldCapacity = elementData.length; | ||
int newCapacity = oldCapacity + ( oldCapacity >> 1 ); | ||
if(newCapacity < minCapacity){ | ||
newCapacity = minCapacity; | ||
} | ||
elementData = Arrays.copyOf(elementData, newCapacity); | ||
|
||
} | ||
|
||
public void add(int index, Object o){ | ||
if(index < 0 || index > size) throw new IndexOutOfBoundsException("Index:"+index+",Size:"+size); | ||
ensureCapacity(size+1); | ||
System.arraycopy(elementData, index, elementData, index + 1, size - index); | ||
elementData[index] = o; | ||
size++; | ||
} | ||
|
||
public Object get(int index){ | ||
if(index < 0 || index >= size) throw new IndexOutOfBoundsException("Index:"+index+",Size:"+size); | ||
return elementData[index]; | ||
} | ||
|
||
public Object remove(int index){ | ||
if(index < 0 || index >= size) throw new IndexOutOfBoundsException("Index:"+index+",Size:"+size); | ||
System.arraycopy(elementData, index + 1, elementData, index, size - index - 1); | ||
elementData[size - 1] = null; | ||
size--; | ||
return elementData; | ||
} | ||
|
||
public int size(){ | ||
return size; | ||
} | ||
|
||
public Iterator iterator(){ | ||
return new ArrayListIterator(); | ||
} | ||
|
||
private class ArrayListIterator implements Iterator{ | ||
|
||
private int pos = 0; | ||
|
||
public boolean hasNext() { | ||
return pos < size; | ||
} | ||
|
||
public Object next() { | ||
return elementData[pos++]; | ||
} | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
group01/1814014897/zhouhui/src/week01/BasicDataStructure/BinaryTreeNode.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,56 @@ | ||
package week01.BasicDataStructure; | ||
|
||
public class BinaryTreeNode{ | ||
|
||
private Object data; | ||
private BinaryTreeNode left; | ||
private BinaryTreeNode right; | ||
|
||
public BinaryTreeNode(Object data){ | ||
this.data = data; | ||
left = null; | ||
right = null; | ||
} | ||
|
||
public Object getData() { | ||
return data; | ||
} | ||
public void setData(Object data) { | ||
this.data = data; | ||
} | ||
public BinaryTreeNode getLeft() { | ||
return left; | ||
} | ||
public void setLeft(BinaryTreeNode left) { | ||
this.left = left; | ||
} | ||
public BinaryTreeNode getRight() { | ||
return right; | ||
} | ||
public void setRight(BinaryTreeNode right) { | ||
this.right = right; | ||
} | ||
|
||
public BinaryTreeNode insert(Object o){ | ||
if((Integer)o < (Integer)this.data) | ||
{ | ||
if(this.left == null){ | ||
BinaryTreeNode node = new BinaryTreeNode(o); | ||
this.setLeft(node); | ||
return node; | ||
}else{ | ||
return this.left.insert(o); | ||
} | ||
}else{ | ||
if(this.right == null){ | ||
BinaryTreeNode node = new BinaryTreeNode(o); | ||
this.setRight(node); | ||
return node; | ||
}else{ | ||
return this.right.insert(o); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
7 changes: 7 additions & 0 deletions
7
group01/1814014897/zhouhui/src/week01/BasicDataStructure/Iterator.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,7 @@ | ||
package week01.BasicDataStructure; | ||
|
||
public interface Iterator { | ||
public boolean hasNext(); | ||
public Object next(); | ||
|
||
} |
113 changes: 113 additions & 0 deletions
113
group01/1814014897/zhouhui/src/week01/BasicDataStructure/LinkedList.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,113 @@ | ||
package week01.BasicDataStructure; | ||
|
||
public class LinkedList implements List { | ||
|
||
private Node head; | ||
private int size = 0; | ||
|
||
public void add(Object o){ | ||
if(head == null){ | ||
head = new Node(o); | ||
}else{ | ||
Node pos = head; | ||
while(pos.next != null){ | ||
pos = pos.next; | ||
} | ||
pos.next = new Node(o); | ||
} | ||
size++; | ||
} | ||
|
||
public void add(int index , Object o){ | ||
if(index < 0 || index >size ) throw new IndexOutOfBoundsException("Index:"+index+",Size"+size); | ||
if(index == 0) { | ||
Node node = new Node(o); | ||
node.next = head; | ||
head = node; | ||
} | ||
else{ | ||
Node pos = head; | ||
for(int i = 0;i < index-1;i++){ | ||
pos = pos.next; | ||
} | ||
Node node = new Node(o); | ||
node.next = pos.next; | ||
pos.next = node; | ||
} | ||
size++; | ||
} | ||
|
||
public Object get(int index){ | ||
if(index < 0 || index >=size ) throw new IndexOutOfBoundsException("Index:"+index+",Size"+size); | ||
Node pos = head; | ||
for(int i = 0;i < index;i++){ | ||
pos = pos.next; | ||
} | ||
return pos.data; | ||
} | ||
|
||
public Object remove(int index){ | ||
if(index < 0 || index >=size ) throw new IndexOutOfBoundsException("Index:"+index+",Size:"+size); | ||
Node element = head; | ||
if(index == 0){ | ||
head = head.next; | ||
}else{ | ||
Node pos = head; | ||
for(int i = 0;i < index - 1;i++){ | ||
pos = pos.next; | ||
} | ||
element = pos.next; | ||
pos.next = pos.next.next; | ||
} | ||
size--; | ||
return element.data; | ||
} | ||
|
||
public int size(){ | ||
return size; | ||
} | ||
|
||
public void addFirst(Object o){ | ||
add(0,o); | ||
} | ||
public void addLast(Object o){ | ||
add(size,o); | ||
} | ||
public Object removeFirst(){ | ||
return remove(0); | ||
} | ||
public Object removeLast(){ | ||
return remove(size-1); | ||
} | ||
public Iterator iterator(){ | ||
return new LinkedListIterator(); | ||
} | ||
|
||
class LinkedListIterator implements Iterator{ | ||
|
||
private Node node = head; | ||
private int pos = 0; | ||
@Override | ||
public boolean hasNext() { | ||
return pos < size; | ||
} | ||
|
||
@Override | ||
public Object next() { | ||
pos++; | ||
if(pos != 1){ | ||
node = node.next; | ||
} | ||
return node.data; | ||
} | ||
} | ||
|
||
private static class Node{ | ||
Object data; | ||
Node next; | ||
public Node(Object data){ | ||
this.data = data; | ||
next = null; | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
group01/1814014897/zhouhui/src/week01/BasicDataStructure/List.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,9 @@ | ||
package week01.BasicDataStructure; | ||
|
||
public interface List { | ||
public void add(Object o); | ||
public void add(int index, Object o); | ||
public Object get(int index); | ||
public Object remove(int index); | ||
public int size(); | ||
} |
25 changes: 25 additions & 0 deletions
25
group01/1814014897/zhouhui/src/week01/BasicDataStructure/Queue.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,25 @@ | ||
package week01.BasicDataStructure; | ||
|
||
public class Queue { | ||
|
||
private LinkedList linkedList = new LinkedList(); | ||
private int size = 0; | ||
|
||
public void enQueue(Object o){ | ||
linkedList.add(o); | ||
size++; | ||
} | ||
|
||
public Object deQueue(){ | ||
size--; | ||
return linkedList.removeFirst(); | ||
} | ||
|
||
public boolean isEmpty(){ | ||
return linkedList.size() == 0; | ||
} | ||
|
||
public int size(){ | ||
return size; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
group01/1814014897/zhouhui/src/week01/BasicDataStructure/Stack.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,25 @@ | ||
package week01.BasicDataStructure; | ||
|
||
public class Stack { | ||
private ArrayList elementData = new ArrayList(); | ||
private int size = 0; | ||
|
||
public void push(Object o){ | ||
elementData.add(o); | ||
size++; | ||
} | ||
|
||
public Object pop(){ | ||
return elementData.remove(--size); | ||
} | ||
|
||
public Object peek(){ | ||
return elementData.get(size - 1); | ||
} | ||
public boolean isEmpty(){ | ||
return elementData.size() == 0; | ||
} | ||
public int size(){ | ||
return elementData.size(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
group01/1814014897/zhouhui/src/week01/BasicDataStructureTest/AllTest.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,18 @@ | ||
package week01.BasicDataStructureTest; | ||
|
||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Suite; | ||
import org.junit.runners.Suite.SuiteClasses; | ||
|
||
@RunWith(Suite.class) | ||
@SuiteClasses({ | ||
ArrayListTest.class, | ||
BinaryTreeNodeTest.class, | ||
LinkedListTest.class, | ||
QueueTest.class, | ||
StackTest.class | ||
}) | ||
|
||
public class AllTest { | ||
|
||
} |
Oops, something went wrong.