Skip to content

Commit

Permalink
Merge pull request #2 from 844028312/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
dustheart authored Mar 7, 2017
2 parents e933d6a + 8a3b557 commit 5e28c6b
Show file tree
Hide file tree
Showing 3,436 changed files with 187,793 additions and 11,561 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
52 changes: 21 additions & 31 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
*.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

*.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
.idea/
*.iml
rebel.*
.rebel.*

target
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>coding2017</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
2 changes: 2 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2017编程提高社群

2017编程提高社群代码仓库所在地
8 changes: 8 additions & 0 deletions group01/1298552064/src/week01/basic/Iterator.java
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();

}
13 changes: 13 additions & 0 deletions group01/1298552064/src/week01/basic/List.java
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();
}
131 changes: 131 additions & 0 deletions group01/1298552064/src/week01/basic/MyArrayList.java
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) + "]" + " }";
}
}
70 changes: 70 additions & 0 deletions group01/1298552064/src/week01/basic/MyBinaryTreeNode.java
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();
}
}
}
}
}
Loading

0 comments on commit 5e28c6b

Please sign in to comment.