Skip to content

Commit

Permalink
Merge pull request #1 from BlindingDark/master
Browse files Browse the repository at this point in the history
1
  • Loading branch information
wjwzero authored Mar 19, 2017
2 parents cf252f1 + ff697c0 commit 29af255
Show file tree
Hide file tree
Showing 67 changed files with 3,884 additions and 273 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ rebel.*
.rebel.*

target
*.DS_Store
liuxin/.DS_Store
liuxin/src/.DS_Store

136 changes: 68 additions & 68 deletions group26/1515345281/src/Collection/ArrayList.java
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
package Collection;

public class ArrayList implements List {
private int size = 0;
private Object[] elementData = new Object[100];
public void add(Object o){
if(o==null)
throw new RuntimeException("插入的值不能为null");
if((size+1)>=100){
throw new RuntimeException("数组越界异常");
}
elementData[size]=o;
size++;
}

public void add(int index, Object o){
for(int i=index;i<size;i++){
elementData[i+1]=elementData[i];
}
elementData[index]=o;
}
public Object get(int index){
if(index<0 || index>=size)
throw new RuntimeException("索引异常");
return elementData[index];
}
public Object remove(int index){
if(index<0 || index>=size)
throw new RuntimeException("索引异常");
Object temp=elementData[index];
for(int i=index;i<size-1;i++){
elementData[i]=elementData[i+1];
}
return temp;
}
public int size(){
return size;
}
public Iterator iterator(){
return new Itr();
}

private class Itr implements Iterator{

private int cursor=0;
@Override
public boolean hasNext() {
return cursor!=size;
}

@Override
public Object next() {
int i=cursor;
cursor=i+1;
return elementData[i];
}
}
private int size = 0;

private Object[] elementData = new Object[100];

public void add(Object o) {

if (o == null)
throw new RuntimeException("插入的值不能为null");
if ((size + 1) >= 100) {
throw new RuntimeException("数组越界异常");
}
elementData[size] = o;
size++;
}

public void add(int index, Object o) {

for (int i = index; i < size; i++) {
elementData[i + 1] = elementData[i];
}
elementData[index] = o;
}

public Object get(int index) {

if (index < 0 || index >= size)
throw new RuntimeException("索引异常");
return elementData[index];
}

public Object remove(int index) {

if (index < 0 || index >= size)
throw new RuntimeException("索引异常");
Object temp = elementData[index];
for (int i = index; i < size - 1; i++) {
elementData[i] = elementData[i + 1];
}
return temp;
}

public int size() {
return size;
}

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

private class Itr implements Iterator {

private int cursor = 0;

@Override
public boolean hasNext() {

return cursor != size;
}

@Override
public Object next() {
int i = cursor;
cursor = i + 1;
return elementData[i];
}

}

}
Loading

0 comments on commit 29af255

Please sign in to comment.