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 #6 from Kandde/master
1094051862
- Loading branch information
Showing
13 changed files
with
324 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.junit.JUNIT_CONTAINER/4"/> | ||
<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>test01</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> |
12 changes: 12 additions & 0 deletions
12
group05/1094051862/test01/.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,12 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.7 | ||
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.7 |
1 change: 1 addition & 0 deletions
1
group05/1094051862/test01/src/com/coding1094051862/basic/.gitignore
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 @@ | ||
/ArrayList.java |
23 changes: 23 additions & 0 deletions
23
group05/1094051862/test01/src/com/coding1094051862/basic/ArrayListTest.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,23 @@ | ||
package com.coding1094051862.basic; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class ArrayListTest { | ||
|
||
@Test | ||
public void test() { | ||
ArrayList list = new ArrayList(); | ||
for(int i = 0; i < 10; i++) { | ||
list.add(i); | ||
} | ||
Assert.assertEquals(10, list.size()); | ||
list.add(11); | ||
list.add(3,99); | ||
Assert.assertEquals(99, list.get(3)); | ||
Assert.assertEquals(12, list.size()); | ||
Assert.assertEquals(99, list.remove(3)); | ||
Assert.assertEquals(11, list.size()); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
group05/1094051862/test01/src/com/coding1094051862/basic/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,32 @@ | ||
package com.coding1094051862.basic; | ||
|
||
public class BinaryTreeNode { | ||
|
||
private Object data; | ||
private BinaryTreeNode left; | ||
private BinaryTreeNode right; | ||
|
||
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){ | ||
return null; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
group05/1094051862/test01/src/com/coding1094051862/basic/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 com.coding1094051862.basic; | ||
|
||
public interface Iterator { | ||
public boolean hasNext(); | ||
public Object next(); | ||
|
||
} |
142 changes: 142 additions & 0 deletions
142
group05/1094051862/test01/src/com/coding1094051862/basic/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,142 @@ | ||
package com.coding1094051862.basic; | ||
|
||
public class LinkedList implements List { | ||
|
||
private Node head; | ||
private Node last; | ||
private int size = 0; | ||
|
||
public void add(Object o){ | ||
if (head == null) { | ||
head = new Node(o, null); | ||
size ++; | ||
return; | ||
} | ||
Node n = new Node(o, null); | ||
if (last == null) { | ||
last = n; | ||
head.next = last; | ||
} | ||
last.next = n; | ||
last = n; | ||
size ++; | ||
} | ||
public void add(int index , Object o){ | ||
if (index < 0 || index > size) { | ||
System.out.println("linkedList.add: index < 0 || index > size"); | ||
return; | ||
} | ||
if (index == size) { | ||
add(o); | ||
return; | ||
} | ||
if (index == 0) { | ||
addFirst(o); | ||
return; | ||
} | ||
Node pre = head; | ||
for (int i = 1; i < index; i++) { | ||
pre = pre.next; | ||
} | ||
Node post = pre.next; | ||
Node n = new Node(o,post); | ||
pre.next = n; | ||
size ++; | ||
} | ||
public Object get(int index){ | ||
if (index == 0) { | ||
return head.data; | ||
} | ||
Node n = head; | ||
for (int i = 1; i <= index; i++) { | ||
n = n.next; | ||
} | ||
return n.data; | ||
} | ||
public Object remove(int index){ | ||
if (index < 0 || index >= size) { | ||
System.out.println("remove :index < 0 || index >= size"); | ||
return null; | ||
} | ||
if (index == 0) { | ||
return removeFirst(); | ||
} | ||
if (index == size - 1) { | ||
return removeLast(); | ||
} | ||
Node pre = head; | ||
for (int i = 1; i < index; i++) { | ||
pre = pre.next; | ||
} | ||
Node n = pre.next; | ||
Node post = n.next; | ||
n.next = null; | ||
pre.next = post; | ||
size --; | ||
return n.data; | ||
} | ||
|
||
public int size(){ | ||
return size; | ||
} | ||
|
||
public void addFirst(Object o){ | ||
Node n = new Node(o,head); | ||
head = n; | ||
size ++; | ||
return; | ||
} | ||
public void addLast(Object o){ | ||
Node n = new Node(o,null); | ||
last.next = n; | ||
last = n; | ||
size ++; | ||
return; | ||
} | ||
public Object removeFirst(){ | ||
Object o = head.data; | ||
Node n = head.next; | ||
head.next = null; | ||
head = n; | ||
size --; | ||
return o; | ||
} | ||
public Object removeLast(){ | ||
Node preLast = head; | ||
for (int i = 1; i < size; i++) { | ||
preLast = preLast.next; | ||
} | ||
preLast.next = null; | ||
Object o = last.data; | ||
last = preLast; | ||
size --; | ||
return o; | ||
} | ||
public Iterator iterator(){ | ||
return new Iterator() { | ||
@Override | ||
public Object next() { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
// TODO Auto-generated method stub | ||
return false; | ||
} | ||
}; | ||
} | ||
|
||
|
||
private static class Node { | ||
|
||
Object data; | ||
Node next; | ||
|
||
public Node (Object data, Node next) { | ||
this.data = data; | ||
this.next = next; | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
group05/1094051862/test01/src/com/coding1094051862/basic/LinkedListTest.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,32 @@ | ||
package com.coding1094051862.basic; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.junit.Test; | ||
|
||
public class LinkedListTest extends LinkedList { | ||
|
||
@Test | ||
public void test() { | ||
List list = new LinkedList(); | ||
list.add(0); | ||
list.add(1); | ||
list.add(2); | ||
list.add(3); | ||
list.add(4); | ||
list.add(5); | ||
list.add(3, 33); | ||
list.add(0, 100); | ||
list.add(8,800); | ||
Assert.assertEquals(9, list.size()); | ||
Assert.assertEquals(100, list.get(0)); | ||
Assert.assertEquals(0, list.get(1)); | ||
Assert.assertEquals(1, list.get(2)); | ||
Assert.assertEquals(2, list.get(3)); | ||
Assert.assertEquals(33, list.get(4)); | ||
Assert.assertEquals(3, list.get(5)); | ||
Assert.assertEquals(4, list.get(6)); | ||
Assert.assertEquals(800, list.get(8)); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
group05/1094051862/test01/src/com/coding1094051862/basic/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 com.coding1094051862.basic; | ||
|
||
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(); | ||
} |
19 changes: 19 additions & 0 deletions
19
group05/1094051862/test01/src/com/coding1094051862/basic/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,19 @@ | ||
package com.coding1094051862.basic; | ||
|
||
public class Queue { | ||
|
||
public void enQueue(Object o){ | ||
} | ||
|
||
public Object deQueue(){ | ||
return null; | ||
} | ||
|
||
public boolean isEmpty(){ | ||
return false; | ||
} | ||
|
||
public int size(){ | ||
return -1; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
group05/1094051862/test01/src/com/coding1094051862/basic/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,22 @@ | ||
package com.coding1094051862.basic; | ||
|
||
public class Stack { | ||
private ArrayList elementData = new ArrayList(); | ||
|
||
public void push(Object o){ | ||
} | ||
|
||
public Object pop(){ | ||
return null; | ||
} | ||
|
||
public Object peek(){ | ||
return null; | ||
} | ||
public boolean isEmpty(){ | ||
return false; | ||
} | ||
public int size(){ | ||
return -1; | ||
} | ||
} |