forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2,078 changed files
with
107,705 additions
and
6,885 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 |
---|---|---|
@@ -1,31 +1 @@ | ||
*.class | ||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.ear | ||
|
||
*.iml | ||
*.idea | ||
|
||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
|
||
#ide config | ||
.metadata | ||
.recommenders | ||
|
||
|
||
#macOS | ||
.DS_Store | ||
|
||
.idea/ | ||
*.iml | ||
rebel.* | ||
.rebel.* | ||
|
||
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,3 @@ | ||
## 2017编程提高社群 | ||
|
||
2017编程提高社群代码仓库所在地 |
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,8 @@ | ||
package week01.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,13 @@ | ||
package week01.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(); | ||
} |
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,131 @@ | ||
package week01.basic; | ||
|
||
import java.util.Arrays; | ||
|
||
public class MyArrayList implements List { | ||
|
||
private int size = 0; | ||
|
||
private Object[] elementData = new Object[100]; | ||
|
||
public void add(Object o) { | ||
ensureCapacity(size + 1); | ||
|
||
elementData[size++] = o; | ||
} | ||
|
||
public void add(int index, Object o) { | ||
checkPositionIndex(index); | ||
ensureCapacity(size + 1); | ||
|
||
if (index >= size) { | ||
elementData[size++] = o; | ||
} else { | ||
System.arraycopy(elementData, index, elementData, index + 1, size | ||
- index); | ||
|
||
elementData[index] = o; | ||
|
||
size++; | ||
} | ||
} | ||
|
||
public Object get(int index) { | ||
checkElementIndex(index); | ||
return elementData[index]; | ||
} | ||
|
||
public Object remove(int index) { | ||
checkElementIndex(index); | ||
Object removeElement = elementData[index]; | ||
if (index == (size - 1)) { | ||
elementData[index] = null; | ||
size--; | ||
} else { | ||
System.arraycopy(elementData, index + 1, elementData, index, size | ||
- index - 1); | ||
elementData[size - 1] = null; | ||
size--; | ||
} | ||
return removeElement; | ||
} | ||
|
||
public int size() { | ||
return size; | ||
} | ||
|
||
/** | ||
* 保证数组空间充足 | ||
* | ||
* @param minCapacity | ||
*/ | ||
private void ensureCapacity(int minCapacity) { | ||
int capacity = elementData.length; | ||
if (minCapacity > capacity) { | ||
capacity += capacity / 2; | ||
grow(capacity); | ||
} | ||
} | ||
|
||
private void checkElementIndex(int index) { | ||
if (!isElementIndex(index)) { | ||
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " | ||
+ size); | ||
} | ||
} | ||
|
||
private boolean isElementIndex(int index) { | ||
return index >= 0 && index < size; | ||
} | ||
|
||
private void checkPositionIndex(int index) { | ||
if (!isPositionIndex(index)) { | ||
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " | ||
+ size); | ||
} | ||
} | ||
|
||
private boolean isPositionIndex(int index) { | ||
return index >= 0 && index <= size; | ||
} | ||
|
||
private void grow(int newCapacity) { | ||
elementData = Arrays.copyOf(elementData, newCapacity); | ||
} | ||
|
||
public Iterator iterator() { | ||
return new ArrayListIterator(this); | ||
} | ||
|
||
private class ArrayListIterator implements Iterator { | ||
private MyArrayList list; | ||
private int position = 0; | ||
|
||
private ArrayListIterator(MyArrayList list) { | ||
this.list = list; | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
if ((position + 1) > size) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public Object next() { | ||
return list.get(position++); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String elementStr = ""; | ||
for (int i = 0; i < size; i++) { | ||
elementStr += elementData[i] + ","; | ||
} | ||
return "MyArrayList: { size=" + size + ", elementData=" + "[" | ||
+ elementStr.substring(0, elementStr.length() - 1) + "]" + " }"; | ||
} | ||
} |
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,70 @@ | ||
package week01.basic; | ||
|
||
public class MyBinaryTreeNode { | ||
|
||
private Object data; | ||
private MyBinaryTreeNode left; | ||
private MyBinaryTreeNode right; | ||
|
||
public Object getData() { | ||
return data; | ||
} | ||
|
||
public void setData(Object data) { | ||
this.data = data; | ||
} | ||
|
||
public MyBinaryTreeNode getLeft() { | ||
return left; | ||
} | ||
|
||
public void setLeft(MyBinaryTreeNode left) { | ||
this.left = left; | ||
} | ||
|
||
public MyBinaryTreeNode getRight() { | ||
return right; | ||
} | ||
|
||
public void setRight(MyBinaryTreeNode right) { | ||
this.right = right; | ||
} | ||
|
||
public MyBinaryTreeNode insert(Object o) { | ||
if(this.getData() == null && this.getLeft() == null && this.getRight() == null){ | ||
this.setData(o); | ||
this.setLeft(null); | ||
this.setRight(null); | ||
return this; | ||
} | ||
|
||
MyBinaryTreeNode node = new MyBinaryTreeNode(); | ||
MyBinaryTreeNode currentNode = this; | ||
while(true){ | ||
if((Integer) o < (Integer) getData()){ | ||
if(currentNode.getLeft() == null){ | ||
node.setData(o); | ||
node.setLeft(null); | ||
node.setRight(null); | ||
|
||
currentNode.setLeft(node); | ||
return this; | ||
}else{ | ||
currentNode = currentNode.getLeft(); | ||
} | ||
|
||
}else{ | ||
if(currentNode.getRight() == null){ | ||
node.setData(o); | ||
node.setLeft(null); | ||
node.setRight(null); | ||
|
||
currentNode.setRight(node); | ||
return this; | ||
}else{ | ||
currentNode = currentNode.getRight(); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.