forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 11
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 #1 from 844028312/master
fork synchronize
- Loading branch information
Showing
865 changed files
with
42,489 additions
and
7 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
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"/> | ||
<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>1020483199Learning</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> |
3 changes: 3 additions & 0 deletions
3
group04/1020483199/1020483199Learning/.settings/org.eclipse.core.resources.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,3 @@ | ||
eclipse.preferences.version=1 | ||
encoding//src/com/coding/basic=UTF-8 | ||
encoding/<project>=UTF-8 |
11 changes: 11 additions & 0 deletions
11
group04/1020483199/1020483199Learning/.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 |
128 changes: 128 additions & 0 deletions
128
group04/1020483199/1020483199Learning/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,128 @@ | ||
package com.coding.basic; | ||
|
||
import java.util.Arrays; | ||
import java.util.ConcurrentModificationException; | ||
import java.util.NoSuchElementException; | ||
|
||
public class ArrayList implements List { | ||
|
||
|
||
private int size = 0; | ||
|
||
private transient Object[] elementData = new Object[100]; | ||
/** | ||
* 向数组中添加某个元素 | ||
*/ | ||
public void add(Object o){ | ||
/** | ||
* 数组扩容判断 | ||
*/ | ||
ensureSize(size+1); | ||
elementData[size++] = o; | ||
} | ||
/** | ||
* 向指定位置数组中添加某个元素 | ||
*/ | ||
public void add(int index, Object o){ | ||
if(index<0||index>size){ | ||
throw new IndexOutOfBoundsException("数组越界"); | ||
} | ||
ensureSize(size+1); | ||
System.arraycopy(elementData, index, elementData, index+1, size-index); | ||
elementData[index] = o; | ||
} | ||
/** | ||
* 获取数组中某个位置元素 | ||
*/ | ||
public Object get(int index){ | ||
if(index<0||index>elementData.length){ | ||
return null; | ||
}else{ | ||
return elementData[index]; | ||
} | ||
|
||
} | ||
/** | ||
* 移除数组中指定位置元素 | ||
*/ | ||
public Object remove(int index){ | ||
if(index<0||index>elementData.length){ | ||
return null; | ||
}else{ | ||
int newLength = size-index-1; | ||
if (newLength>0) | ||
System.arraycopy(elementData, index+1, elementData, index, size-index-1); | ||
elementData[--size] = null; | ||
return elementData; | ||
} | ||
} | ||
/** | ||
* 获取当前数组的大小 | ||
*/ | ||
public int size(){ | ||
if(size>0){ | ||
return this.size; | ||
}else{ | ||
return 0; | ||
} | ||
} | ||
/** | ||
* 利用arraylist实现迭代器 | ||
* @return | ||
*/ | ||
public Iterator iterator(){ | ||
|
||
return new ArrayListIterator(); | ||
} | ||
private class ArrayListIterator implements Iterator{ | ||
int cursor; | ||
int lastReset = -1; | ||
@Override | ||
public boolean hasNext() { | ||
return size!=cursor; | ||
} | ||
|
||
@Override | ||
public Object next() { | ||
//标记索引当前位置 | ||
int i = cursor; | ||
if(i>size){ | ||
throw new NoSuchElementException(); | ||
} | ||
Object[] newData = elementData; | ||
if(i>newData.length){ | ||
throw new ConcurrentModificationException(); | ||
} | ||
cursor = i + 1; | ||
return newData[lastReset = i]; | ||
} | ||
|
||
} | ||
|
||
|
||
/** | ||
* @author sulei | ||
* @param minCapcity | ||
*/ | ||
public void ensureSize(int minCapcity){ | ||
if(minCapcity>elementData.length){ | ||
grow(minCapcity); | ||
} | ||
} | ||
|
||
/** | ||
* @author sulei | ||
* @param autoCapcity | ||
*/ | ||
public void grow(int autoCapcity){ | ||
int oldLength = elementData.length; | ||
if(autoCapcity>oldLength){ | ||
Object[] oldData = elementData; | ||
int newLength = (oldLength * 3)/2 + 1; | ||
if(autoCapcity>newLength){ | ||
newLength=autoCapcity; | ||
} | ||
elementData = Arrays.copyOf(elementData, newLength); | ||
} | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
group04/1020483199/1020483199Learning/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,82 @@ | ||
package com.coding.basic; | ||
|
||
public class BinaryTreeNode { | ||
|
||
private Object data; | ||
private BinaryTreeNode left; | ||
private BinaryTreeNode right; | ||
//存放当前树 | ||
private BinaryTreeNode primary; | ||
|
||
public BinaryTreeNode getPrimary() { | ||
return primary; | ||
} | ||
|
||
public void setPrimary(BinaryTreeNode primary) { | ||
this.primary = primary; | ||
} | ||
|
||
|
||
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; | ||
} | ||
/** | ||
* 在二叉树中插入 | ||
* @param o | ||
* @return | ||
*/ | ||
public BinaryTreeNode insert(Object o){ | ||
if(o==null){ | ||
throw new IllegalArgumentException("二叉树的元素不能为空!"); | ||
} | ||
//新建要插入的节点 | ||
BinaryTreeNode bt = new BinaryTreeNode(); | ||
bt.setData(o); | ||
int value = (int)o; | ||
//当原始二叉树为空时 | ||
if(primary==null){ | ||
primary = bt; | ||
}else{ | ||
BinaryTreeNode bi = primary; | ||
while(true){ | ||
if(value<(int)bi.data){ | ||
if(bi.left==null){ | ||
bi.setLeft(bt); | ||
break; | ||
}else{ | ||
bi=bi.left; | ||
} | ||
}else if(value>(int)bi.data){ | ||
if(bi.right==null){ | ||
bi.setRight(bt); | ||
break; | ||
}else{ | ||
bi=bi.right; | ||
} | ||
|
||
}else{ | ||
System.out.println("当前元素在二叉树已存在"); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
return bt; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
group04/1020483199/1020483199Learning/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(); | ||
|
||
} |
Oops, something went wrong.