Skip to content

Commit

Permalink
Merge pull request #28 from onlyliuxin/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
guodongym authored Mar 5, 2017
2 parents 75d6875 + cb7fc7e commit a053bff
Show file tree
Hide file tree
Showing 322 changed files with 15,023 additions and 200 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2017编程提高社群

2017编程提高社群代码仓库所在地
2 changes: 1 addition & 1 deletion group01/group01.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@


2 changes: 1 addition & 1 deletion group02/group02.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@


2 changes: 1 addition & 1 deletion group03/group03.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@


2 changes: 1 addition & 1 deletion group04/group04.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@


2 changes: 1 addition & 1 deletion group05/group05.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@


2 changes: 1 addition & 1 deletion group06/group06.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@


2 changes: 1 addition & 1 deletion group07/group07.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@


2 changes: 1 addition & 1 deletion group08/group08.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@


19 changes: 19 additions & 0 deletions group09/1271620150/Work01/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
*.class
*.classpath
*.project

# 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
/bin/
100 changes: 100 additions & 0 deletions group09/1271620150/Work01/src/com/coding/basic/ArrayList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.coding.basic;

import java.util.Arrays;
import java.util.ConcurrentModificationException;
import java.util.NoSuchElementException;

public class ArrayList implements List {

private Object[] elements;

private int size;

public ArrayList(int initialCapacity) {
super();
if (initialCapacity < 0)
throw new IllegalArgumentException("Illegal Capacity: " + initialCapacity);
this.elements = new Object[initialCapacity];
}

public ArrayList() {
this(10);
}

public void add(Object obj) {
ensureCapacity(size + 1);
elements[size++] = obj;

}

public void add(int index, Object obj) {
rangeCheck(index);
ensureCapacity(size + 1);
System.arraycopy(elements, index, elements, index + 1, size - index);
elements[index] = obj;
size++;
}

public Object get(int index) {
rangeCheck(index);
return elements[index];
}

public Object remove(int index) {
rangeCheck(index);
Object toRemove = elements[index];
int numMoved = size - index - 1;
if (numMoved > 0)
System.arraycopy(elements, index + 1, elements, index, numMoved);
elements[--size] = null;
return toRemove;
}

public int size() {
return size;
}

public Iterator iterator() {
return new ArrayListIterator();
}

private void ensureCapacity(int minCapacity) {
int oldCapacity = elements.length;
if (minCapacity > oldCapacity) {
int newCapacity = oldCapacity * 2;
if (newCapacity < minCapacity)
newCapacity = minCapacity;
elements = Arrays.copyOf(elements, newCapacity);
}
}

private void rangeCheck(int index) {
if (index >= size)
throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
}

private String outOfBoundsMsg(int index) {
return "Index: " + index + ", Size: " + this.size;
}

private class ArrayListIterator implements Iterator{

private int pos = 0;

public boolean hasNext() {
return pos != size;
}

public Object next() {
int i = pos;
if (i >= size)
throw new NoSuchElementException();
Object[] elements = ArrayList.this.elements;
if (i >= elements.length)
throw new ConcurrentModificationException();
pos = i + 1;
return (Object) elements[i];
}
}

}
7 changes: 7 additions & 0 deletions group09/1271620150/Work01/src/com/coding/basic/Iterator.java
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();

}
Loading

0 comments on commit a053bff

Please sign in to comment.