Skip to content

Commit

Permalink
conflict fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
844028312 committed Mar 6, 2017
2 parents ff0984f + 6d6fd62 commit ce5fd83
Show file tree
Hide file tree
Showing 2,078 changed files with 107,705 additions and 6,885 deletions.
30 changes: 0 additions & 30 deletions .gitignore
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

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 ce5fd83

Please sign in to comment.