forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 8
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 #3 from 240094626/master
workspace of 240094626
- Loading branch information
Showing
9 changed files
with
619 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,22 @@ | ||
*.class | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.ear | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
|
||
#ide config | ||
.metadata | ||
.recommenders | ||
|
||
*.settings | ||
*.project | ||
*.classpath | ||
*/.settings | ||
/**/target/**/* |
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,4 @@ | ||
/bin/ | ||
*.classpath | ||
*.project | ||
/.settings/ |
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(); | ||
|
||
} |
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(); | ||
} |
166 changes: 166 additions & 0 deletions
166
group17/240094626/warm-up/src/com/coding/basic/impl/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,166 @@ | ||
package com.coding.basic.impl; | ||
|
||
import java.util.Arrays; | ||
|
||
import com.coding.basic.Iterator; | ||
import com.coding.basic.List; | ||
|
||
/** | ||
* | ||
* @描述: ArrayList简单实现 | ||
* @作者:240094626 | ||
* @创建日期:2017-2-20 | ||
*/ | ||
public class ArrayList implements List { | ||
|
||
|
||
/** | ||
* @comment:元素数组 | ||
*/ | ||
private Object data[] = null; | ||
|
||
/** | ||
* @comment:数组元素个数 | ||
*/ | ||
private int size = 0; | ||
|
||
/** | ||
* 无参构造函数,初始化容量为10的空列表 | ||
*/ | ||
public ArrayList(){ | ||
this(10); | ||
} | ||
|
||
/** | ||
* @param length | ||
* 构造函数,初始化容量为length的空列表 | ||
*/ | ||
public ArrayList(int length){ | ||
if(length < 0){ | ||
throw new IllegalArgumentException("初始容量参数非法:"+length); | ||
} | ||
data = new Object[length]; | ||
} | ||
|
||
|
||
/** | ||
* @createTime: 2017-2-21 下午1:32:28 | ||
* @param length | ||
* @return:void | ||
* @comment:列表结构扩展容量,每次增加原来的1/2容量 | ||
*/ | ||
private void grow(int length){ | ||
int oldLength = data.length; | ||
if(length > oldLength){ | ||
Object oldData[] = data; | ||
int newLength = oldLength*3/2 + 1; | ||
if(newLength < length){ | ||
newLength = length; | ||
} | ||
data = new Object[newLength]; | ||
System.arraycopy(oldData, 0, data, 0, oldLength); | ||
} | ||
} | ||
|
||
/** | ||
* @createTime: 2017-2-21 下午1:32:05 | ||
* @param index | ||
* @return:void | ||
* @comment:检验下标参数是否超限 | ||
*/ | ||
private void check(int index) { | ||
if( index >= size){ | ||
throw new IndexOutOfBoundsException("Index:"+index+",size:"+size); | ||
} | ||
} | ||
|
||
@Override | ||
public void add(Object o) { | ||
grow(size+1); | ||
data[size++]=o; | ||
} | ||
|
||
@Override | ||
public void add(int index, Object o) { | ||
if( index > size || index < 0){ | ||
throw new IndexOutOfBoundsException("Index:"+index); | ||
} | ||
grow(size+1); | ||
System.arraycopy(data, index, data, index+1, size-index); | ||
data[index] = o; | ||
size++; | ||
|
||
} | ||
|
||
@Override | ||
public Object get(int index) { | ||
check(index); | ||
return data[index]; | ||
} | ||
|
||
|
||
|
||
@Override | ||
public Object remove(int index) { | ||
check(index); | ||
Object remove = data[index]; | ||
System.arraycopy(data, index+1, data, index, size-index); | ||
data[--size] = null; | ||
return remove; | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return size; | ||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
return "ArrayList [data=" + Arrays.toString(data) + ", size=" + size | ||
+ "]"; | ||
} | ||
|
||
public Iterator iterator(){ | ||
return new ArrayListIterator(); | ||
} | ||
|
||
/** | ||
* @描述: 简单实现迭代器 | ||
* @作者:240094626 | ||
* @创建日期:2017-2-21 | ||
*/ | ||
private class ArrayListIterator implements Iterator{ | ||
|
||
/** | ||
* @column:index | ||
* @comment:当前位置下标 | ||
*/ | ||
private int index; | ||
|
||
/** | ||
* 无参构造,初始化迭代器的下标为0 | ||
*/ | ||
public ArrayListIterator(){ | ||
index = 0; | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
if(index < size){ | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public Object next() { | ||
Object o = get(index++); | ||
return o; | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
|
82 changes: 82 additions & 0 deletions
82
group17/240094626/warm-up/src/com/coding/basic/impl/BinaryTree.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.impl; | ||
|
||
|
||
/** | ||
* 二叉树简单实现(key为int类型) | ||
* @author 240094626 | ||
* | ||
*/ | ||
public class BinaryTree { | ||
private Node rootNode = null; | ||
|
||
public Node insert(int key){ | ||
return insert(key,null); | ||
} | ||
|
||
public Node insert(int key ,Object o){ | ||
Node newNode = new Node(key, o); | ||
if(rootNode == null){ | ||
rootNode = newNode; | ||
return rootNode; | ||
} | ||
Node fatherNode = rootNode; | ||
Node currentNode = rootNode; | ||
while(currentNode != null){ | ||
fatherNode = currentNode; | ||
if(key < currentNode.key){ | ||
currentNode = currentNode.left; | ||
}else{ | ||
currentNode = currentNode.right; | ||
} | ||
} | ||
if(key < fatherNode.key){ | ||
fatherNode.left = newNode; | ||
}else{ | ||
fatherNode.right = newNode; | ||
} | ||
return newNode; | ||
} | ||
|
||
public Node getNode(int key){ | ||
return get(rootNode, key); | ||
} | ||
|
||
private Node get(Node n,int key){ | ||
if(n == null){ | ||
return null; | ||
} | ||
if(key < n.key){ | ||
return get(n.left, key); | ||
}else if(key > n.key){ | ||
return get(n.left, key); | ||
} | ||
return null; | ||
} | ||
|
||
|
||
|
||
|
||
private static class Node{ | ||
|
||
int key; | ||
Object data; | ||
Node left; | ||
Node right; | ||
|
||
public Node(int key, Object data) { | ||
this.key = key; | ||
this.data = data; | ||
this.left = null; | ||
this.right = null; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Node [key=" + key + ", data=" + data + "]"; | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
} |
Oops, something went wrong.