Skip to content

Commit 15d3661

Browse files
committed
修改版
1 parent dfe7e97 commit 15d3661

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

group01/1814014897/zhouhui/src/week01/BasicDataStructure/ArrayList.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ public Object get(int index){
4444

4545
public Object remove(int index){
4646
if(index < 0 || index >= size) throw new IndexOutOfBoundsException("Index:"+index+",Size:"+size);
47+
Object data_index = elementData[index];
4748
System.arraycopy(elementData, index + 1, elementData, index, size - index - 1);
4849
elementData[size - 1] = null;
4950
size--;
50-
return elementData;
51+
return data_index;
5152
}
5253

5354
public int size(){

group01/1814014897/zhouhui/src/week01/BasicDataStructureTest/ArrayListTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,10 @@ public void testGet() {
4747

4848
@Test
4949
public void testRemove() {
50-
arrayList.remove(0);
51-
Assert.assertEquals(arrayList.get(0), 1);
52-
arrayList.remove(50);
53-
Assert.assertEquals(arrayList.get(50), 52);
54-
arrayList.remove(97);
50+
Assert.assertEquals(arrayList.remove(0), 0);
51+
Assert.assertEquals(arrayList.remove(0), 1);
52+
Assert.assertEquals(arrayList.remove(97), 99);
5553
Assert.assertEquals(arrayList.size(), 97);
56-
Assert.assertEquals(arrayList.get(96), 98);
5754
}
5855

5956
@Test

group01/1814014897/zhouhui/src/week01/BasicDataStructureTest/StackTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public void testPush() {
3030

3131
@Test
3232
public void testPop() {
33-
stack.pop();
34-
Assert.assertEquals(stack.peek(), 98);
35-
for(int i=0;i<99;i++){
33+
Assert.assertEquals(stack.pop(), 99);
34+
Assert.assertEquals(stack.pop(), 98);
35+
for(int i=0;i<98;i++){
3636
stack.pop();
3737
}
3838
Assert.assertEquals(stack.size(), 0);
@@ -46,6 +46,7 @@ public void testPeek() {
4646
}
4747
stack.pop();
4848
Assert.assertEquals(stack.peek(), 98);
49+
Assert.assertEquals(stack.peek(), 98);
4950
}
5051

5152
@Test

0 commit comments

Comments
 (0)