forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 9
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 #9 from Kandde/master
重新提交
- Loading branch information
Showing
15 changed files
with
215 additions
and
53 deletions.
There are no files selected for viewing
Empty file.
79 changes: 79 additions & 0 deletions
79
group05/1094051862/test01/src/com/coding/basic/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,79 @@ | ||
package com.coding.basic; | ||
|
||
import java.util.Arrays; | ||
|
||
public class ArrayList implements List { | ||
|
||
private int size = 0; | ||
|
||
private Object[] elementData = new Object[10]; | ||
|
||
private int increaseSize = 3; | ||
private void increaseArray() { | ||
Object[] newData = Arrays.copyOf(elementData, elementData.length + increaseSize); | ||
elementData = newData; | ||
} | ||
public void add(Object o){ | ||
if (size == elementData.length) { | ||
increaseArray(); | ||
elementData[size++] = o; | ||
} else { | ||
elementData[size++] = o; | ||
} | ||
} | ||
public void add(int index, Object o){ | ||
if (index < 0 || index > size) { | ||
System.out.println("错误提示:index > size || index < 0"); | ||
return; | ||
} | ||
Object temp; | ||
for (int i = index; i < size; i++) { | ||
temp = elementData[i]; | ||
elementData[i] = o; | ||
o = temp; | ||
} | ||
elementData[size ++] = o; | ||
} | ||
|
||
public Object get(int index){ | ||
if (index < 0 || index > size ){ | ||
return null; | ||
} | ||
return elementData[index]; | ||
} | ||
|
||
public Object remove(int index){ | ||
if (index < 0 || index > size ){ | ||
return null; | ||
} | ||
Object result = elementData[index]; | ||
for (int i = index; i < size-1; i++) { | ||
elementData[i] = elementData[i + 1]; | ||
} | ||
elementData[size-1] = null; | ||
size --; | ||
return result; | ||
} | ||
|
||
public int size(){ | ||
return size; | ||
} | ||
|
||
public Iterator iterator(){ | ||
return new Iterator() { | ||
private int cusor = 0; | ||
@Override | ||
public Object next() { | ||
if (!hasNext()) { | ||
System.out.println("next: !hasNext"); | ||
return null; | ||
} | ||
return elementData[cusor ++]; | ||
} | ||
@Override | ||
public boolean hasNext() { | ||
return cusor < size; | ||
} | ||
}; | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...oding1094051862/basic/BinaryTreeNode.java → .../src/com/coding/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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.coding1094051862.basic; | ||
package com.coding.basic; | ||
|
||
public class BinaryTreeNode { | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
.../com/coding1094051862/basic/Iterator.java → ...test01/src/com/coding/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
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
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
3 changes: 2 additions & 1 deletion
3
.../src/com/coding1094051862/basic/List.java → ...862/test01/src/com/coding/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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
package com.coding1094051862.basic; | ||
package com.coding.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(); | ||
public Iterator iterator(); | ||
} |
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 com.coding.basic; | ||
|
||
public class Queue { | ||
private List list = new ArrayList(); | ||
private int size = 0; | ||
public void enQueue(Object o){ | ||
list.add(o); | ||
size ++; | ||
} | ||
|
||
public Object deQueue(){ | ||
if (size == 0) | ||
return null; | ||
size --; | ||
return list.remove(0); | ||
} | ||
|
||
public boolean isEmpty(){ | ||
return size == 0; | ||
} | ||
|
||
public int size(){ | ||
return size; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
group05/1094051862/test01/src/com/coding/basic/QueueTest.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,26 @@ | ||
package com.coding.basic; | ||
|
||
import static org.junit.Assert.*; | ||
import junit.framework.Assert; | ||
|
||
import org.junit.Test; | ||
|
||
import sun.org.mozilla.javascript.internal.ast.NewExpression; | ||
|
||
public class QueueTest { | ||
|
||
@Test | ||
public void test() { | ||
Queue queue = new Queue(); | ||
for (int i = 0; i < 100; i++) { | ||
queue.enQueue(i); | ||
} | ||
Assert.assertEquals(100, queue.size()); | ||
for (int i = 0; i < 100; i++) { | ||
Assert.assertEquals(i, queue.deQueue()); | ||
} | ||
Assert.assertEquals(0, queue.size()); | ||
|
||
} | ||
|
||
} |
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,28 @@ | ||
package com.coding.basic; | ||
|
||
public class Stack { | ||
private List elementData = new ArrayList(); | ||
private int size = 0; | ||
public void push(Object o){ | ||
elementData.add(o); | ||
size ++; | ||
} | ||
|
||
public Object pop(){ | ||
if (size == 0) | ||
return null; | ||
return elementData.remove(--size); | ||
} | ||
|
||
public Object peek(){ | ||
if (size == 0) | ||
return null; | ||
return elementData.get(size - 1); | ||
} | ||
public boolean isEmpty(){ | ||
return size == 0; | ||
} | ||
public int size(){ | ||
return size; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
group05/1094051862/test01/src/com/coding/basic/StackTest.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,26 @@ | ||
package com.coding.basic; | ||
|
||
import static org.junit.Assert.*; | ||
import junit.framework.Assert; | ||
|
||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class StackTest { | ||
|
||
@Test | ||
public void test() { | ||
Stack stack = new Stack(); | ||
for (int i = 0; i < 100; i++) { | ||
stack.push(i); | ||
} | ||
Assert.assertEquals(100, stack.size()); | ||
Assert.assertEquals(99, stack.pop()); | ||
for (int i = 98; i >= 0; i--) { | ||
Assert.assertEquals(i, stack.peek()); | ||
Assert.assertEquals(i, stack.pop()); | ||
} | ||
Assert.assertEquals(0, stack.size()); | ||
} | ||
|
||
} |
1 change: 0 additions & 1 deletion
1
group05/1094051862/test01/src/com/coding1094051862/basic/.gitignore
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
group05/1094051862/test01/src/com/coding1094051862/basic/Queue.java
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
group05/1094051862/test01/src/com/coding1094051862/basic/Stack.java
This file was deleted.
Oops, something went wrong.