Skip to content

Commit

Permalink
格式整理
Browse files Browse the repository at this point in the history
  • Loading branch information
BlindingDark committed Mar 11, 2017
1 parent 9beee2d commit c4e4c7c
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 73 deletions.
137 changes: 69 additions & 68 deletions group26/1515345281/src/Collection/ArrayList.java
Original file line number Diff line number Diff line change
@@ -1,72 +1,73 @@
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];
}

}

}
5 changes: 0 additions & 5 deletions group26/zhuakuang2017/Main.java

This file was deleted.

7 changes: 7 additions & 0 deletions group26/zhuakuang2017/src/zhuakuang/homework/first/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package zhuakuang.homework.first;

public class Main {
public static void main(String[] args) {
System.out.println(1);
}
}

0 comments on commit c4e4c7c

Please sign in to comment.