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 #8 from yichen10/master
1259131938第一周作业
- Loading branch information
Showing
12 changed files
with
325 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,6 @@ | ||
<?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.6"/> | ||
<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>JavaLearning</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
group06/1259131938/JavaLearning/.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.6 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.6 | ||
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.6 |
32 changes: 32 additions & 0 deletions
32
group06/1259131938/JavaLearning/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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.coding.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
group06/1259131938/JavaLearning/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.coding.basic; | ||
|
||
public interface Iterator { | ||
public boolean hasNext(); | ||
public Object next(); | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
group06/1259131938/JavaLearning/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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
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(); | ||
} |
77 changes: 77 additions & 0 deletions
77
group06/1259131938/JavaLearning/src/com/coding/basic/MyArrayList.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,77 @@ | ||
package com.coding.basic; | ||
|
||
/** | ||
* @deprecated 用数组实现list | ||
* @author wang | ||
* | ||
*/ | ||
public class MyArrayList implements List { | ||
|
||
private int size = 0; | ||
|
||
private Object[] elementData = new Object[100]; | ||
|
||
public void add(Object o){ | ||
// 确保数组大小 | ||
ensureCapacity(size + 1); | ||
// 数组赋值并使得size+1; | ||
elementData[size ++] = o; | ||
size ++; | ||
} | ||
|
||
/** | ||
* 确保数组不越界,否则就扩容; | ||
* @param minCapacity list的大小; | ||
*/ | ||
public void ensureCapacity(int minCapacity) { | ||
int oldCapacity = elementData.length; | ||
int newCapacity = (oldCapacity / 3) * 2 + 1; | ||
if (minCapacity > newCapacity) { | ||
// 对数组扩容 | ||
Object[] newDate = new Object[newCapacity]; | ||
System.arraycopy(elementData, 0, newDate, 0, oldCapacity); | ||
elementData = newDate; | ||
} | ||
} | ||
|
||
public void add(int index, Object o){ | ||
// 对index进行校验: | ||
rangeCheck(index); | ||
ensureCapacity(size + 1); | ||
System.arraycopy(elementData, index, elementData, index + 1, size - index); | ||
elementData[index] = o; | ||
size ++; | ||
} | ||
|
||
/** | ||
* 边界检查: | ||
* @param index | ||
*/ | ||
private void rangeCheck(int index) { | ||
if (index < 0 || index >= size) { | ||
throw new IndexOutOfBoundsException("size" + size + ", index:" | ||
+ index); | ||
} | ||
} | ||
|
||
public Object get(int index){ | ||
rangeCheck(index); | ||
return elementData[index]; | ||
} | ||
|
||
public Object remove(int index){ | ||
rangeCheck(index); | ||
Object oldValue = elementData[index]; | ||
System.arraycopy(elementData, index, elementData, index - 1, size - index); | ||
return oldValue; | ||
} | ||
|
||
public int size(){ | ||
return size; | ||
} | ||
|
||
public Iterator iterator(){ | ||
return null; | ||
} | ||
|
||
} |
97 changes: 97 additions & 0 deletions
97
group06/1259131938/JavaLearning/src/com/coding/basic/MyLinkedList.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,97 @@ | ||
package com.coding.basic; | ||
|
||
|
||
public class MyLinkedList implements List { | ||
|
||
private Node headNode; | ||
|
||
private Node endNode; | ||
|
||
private int size; | ||
|
||
public void add(Object o){ | ||
add(size,o); | ||
} | ||
public void add(int index , Object o){ | ||
addBefore(getNode(index),o); | ||
} | ||
|
||
// 执行添加元素: | ||
private void addBefore(Node node,Object o) { | ||
Node newNode = new Node(o, node.prev, node.next); | ||
newNode.prev.next = newNode; | ||
newNode.next.prev = newNode; | ||
size ++; | ||
} | ||
|
||
// 获得元素; | ||
private Node getNode(int index) { | ||
Node rtnNode; | ||
if (index > size || index < 0) { | ||
throw new IndexOutOfBoundsException(); | ||
} | ||
if (index < size / 2) { | ||
rtnNode = headNode.next; | ||
for (int i = 0; i < index; i++) { | ||
rtnNode = rtnNode.next; | ||
} | ||
} else { | ||
rtnNode = endNode; | ||
for (int i = size; i > index; i--) { | ||
rtnNode = rtnNode.prev; | ||
} | ||
} | ||
return rtnNode; | ||
} | ||
|
||
public Object get(int index){ | ||
return getNode(index).data; | ||
} | ||
public Object remove(int index){ | ||
return remove(getNode(index)); | ||
} | ||
|
||
private Object remove(Node node) { | ||
node.prev.next = node.next; | ||
node.next.prev = node.prev; | ||
size --; | ||
return node.data; | ||
} | ||
public int size(){ | ||
return size; | ||
} | ||
|
||
public void addFirst(Object o){ | ||
add(headNode.prev); | ||
} | ||
public void addLast(Object o){ | ||
add(endNode.next); | ||
} | ||
public Object removeFirst(){ | ||
remove(headNode); | ||
return headNode.data; | ||
} | ||
public Object removeLast(){ | ||
remove(endNode); | ||
return endNode.data; | ||
} | ||
public Iterator iterator(){ | ||
return null; | ||
} | ||
|
||
public boolean isEmpty(){ | ||
return size == 0; | ||
} | ||
|
||
private static class Node{ | ||
//当前元素,下一个及前一个; | ||
Object data; | ||
Node next; | ||
Node prev; | ||
public Node(Object data,Node prev, Node next) { | ||
this.data = data; | ||
this.next = next; | ||
this.prev = prev; | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
group06/1259131938/JavaLearning/src/com/coding/basic/MyStack.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,36 @@ | ||
package com.coding.basic; | ||
|
||
public class MyStack { | ||
private MyArrayList elementData = new MyArrayList(); | ||
|
||
/** | ||
* 入栈 | ||
* @param o | ||
*/ | ||
public void push(Object o){ | ||
elementData.add(o); | ||
} | ||
|
||
/** | ||
* 出栈 | ||
* @return | ||
*/ | ||
public Object pop(){ | ||
Object oldValue = elementData.get(elementData.size()); | ||
elementData.remove(elementData.size()); | ||
return oldValue; | ||
} | ||
/** | ||
* 查看栈顶元素; | ||
* @return | ||
*/ | ||
public Object peek(){ | ||
return elementData.get(elementData.size()); | ||
} | ||
public boolean isEmpty(){ | ||
return elementData.size() == 0; | ||
} | ||
public int size(){ | ||
return elementData.size(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
group06/1259131938/JavaLearning/src/com/coding/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,20 @@ | ||
package com.coding.basic; | ||
|
||
public class Queue { | ||
MyLinkedList elementData = new MyLinkedList(); | ||
public void enQueue(Object o){ | ||
elementData.add(o); | ||
} | ||
|
||
public Object deQueue(){ | ||
return elementData.remove(elementData.size()); | ||
} | ||
|
||
public boolean isEmpty(){ | ||
return elementData.size() == 0; | ||
} | ||
|
||
public int size(){ | ||
return elementData.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,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>RemoteSystemsTempFiles</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.rse.ui.remoteSystemsTempNature</nature> | ||
</natures> | ||
</projectDescription> |