Skip to content

Commit 96b7795

Browse files
authored
Merge branch 'master' into master
2 parents 0731086 + 69762a0 commit 96b7795

File tree

692 files changed

+34551
-22
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

692 files changed

+34551
-22
lines changed

.gitignore

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
*.class
2-
32
# Mobile Tools for Java (J2ME)
43
.mtj.tmp/
54

@@ -8,10 +7,27 @@
87
*.war
98
*.ear
109

10+
*.iml
11+
*.idea
12+
13+
1114
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
1215
hs_err_pid*
1316

1417
#ide config
1518
.metadata
1619
.recommenders
1720
.idea/
21+
22+
23+
24+
#macOS
25+
.DS_Store
26+
27+
.idea/
28+
*.iml
29+
rebel.*
30+
.rebel.*
31+
32+
target
33+

coding2017-1

Lines changed: 0 additions & 1 deletion
This file was deleted.

group05/1094051862/test01/src/com/coding/basic/.gitignore

Whitespace-only changes.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.coding.basic;
2+
3+
import java.util.Arrays;
4+
5+
public class ArrayList implements List {
6+
7+
private int size = 0;
8+
9+
private Object[] elementData = new Object[10];
10+
11+
private int increaseSize = 3;
12+
private void increaseArray() {
13+
Object[] newData = Arrays.copyOf(elementData, elementData.length + increaseSize);
14+
elementData = newData;
15+
}
16+
public void add(Object o){
17+
if (size == elementData.length) {
18+
increaseArray();
19+
elementData[size++] = o;
20+
} else {
21+
elementData[size++] = o;
22+
}
23+
}
24+
public void add(int index, Object o){
25+
if (index < 0 || index > size) {
26+
System.out.println("错误提示:index > size || index < 0");
27+
return;
28+
}
29+
Object temp;
30+
for (int i = index; i < size; i++) {
31+
temp = elementData[i];
32+
elementData[i] = o;
33+
o = temp;
34+
}
35+
elementData[size ++] = o;
36+
}
37+
38+
public Object get(int index){
39+
if (index < 0 || index > size ){
40+
return null;
41+
}
42+
return elementData[index];
43+
}
44+
45+
public Object remove(int index){
46+
if (index < 0 || index > size ){
47+
return null;
48+
}
49+
Object result = elementData[index];
50+
for (int i = index; i < size-1; i++) {
51+
elementData[i] = elementData[i + 1];
52+
}
53+
elementData[size-1] = null;
54+
size --;
55+
return result;
56+
}
57+
58+
public int size(){
59+
return size;
60+
}
61+
62+
public Iterator iterator(){
63+
return new Iterator() {
64+
private int cusor = 0;
65+
@Override
66+
public Object next() {
67+
if (!hasNext()) {
68+
System.out.println("next: !hasNext");
69+
return null;
70+
}
71+
return elementData[cusor ++];
72+
}
73+
@Override
74+
public boolean hasNext() {
75+
return cusor < size;
76+
}
77+
};
78+
}
79+
}

group05/1094051862/test01/src/com/coding1094051862/basic/ArrayListTest.java renamed to group05/1094051862/test01/src/com/coding/basic/ArrayListTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.coding1094051862.basic;
1+
package com.coding.basic;
22

33
import org.junit.Assert;
44
import org.junit.Test;
@@ -7,7 +7,7 @@ public class ArrayListTest {
77

88
@Test
99
public void test() {
10-
ArrayList list = new ArrayList();
10+
List list = new ArrayList();
1111
for(int i = 0; i < 10; i++) {
1212
list.add(i);
1313
}
@@ -18,6 +18,14 @@ public void test() {
1818
Assert.assertEquals(12, list.size());
1919
Assert.assertEquals(99, list.remove(3));
2020
Assert.assertEquals(11, list.size());
21+
Iterator iterator = list.iterator();
22+
for (int i = 0; i< list.size(); i++) {
23+
System.out.println(list.get(i));
24+
}
25+
System.out.println("======");
26+
while (iterator.hasNext()) {
27+
System.out.println(iterator.next());
28+
}
2129
}
2230

2331
}

group05/1094051862/test01/src/com/coding1094051862/basic/BinaryTreeNode.java renamed to group05/1094051862/test01/src/com/coding/basic/BinaryTreeNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.coding1094051862.basic;
1+
package com.coding.basic;
22

33
public class BinaryTreeNode {
44

group05/1094051862/test01/src/com/coding1094051862/basic/Iterator.java renamed to group05/1094051862/test01/src/com/coding/basic/Iterator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.coding1094051862.basic;
1+
package com.coding.basic;
22

33
public interface Iterator {
44
public boolean hasNext();

group05/1094051862/test01/src/com/coding1094051862/basic/LinkedList.java renamed to group05/1094051862/test01/src/com/coding/basic/LinkedList.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.coding1094051862.basic;
1+
package com.coding.basic;
22

33
public class LinkedList implements List {
44

@@ -114,16 +114,23 @@ public Object removeLast(){
114114
}
115115
public Iterator iterator(){
116116
return new Iterator() {
117+
int cusor = 0;
118+
Node current = head;
117119
@Override
118120
public Object next() {
119-
// TODO Auto-generated method stub
120-
return null;
121+
if (!hasNext()) {
122+
System.out.println("next : !hasNext");
123+
return null;
124+
}
125+
Object o = current.data;
126+
current = current.next;
127+
cusor ++;
128+
return o;
121129
}
122130

123131
@Override
124132
public boolean hasNext() {
125-
// TODO Auto-generated method stub
126-
return false;
133+
return cusor < size;
127134
}
128135
};
129136
}

group05/1094051862/test01/src/com/coding1094051862/basic/LinkedListTest.java renamed to group05/1094051862/test01/src/com/coding/basic/LinkedListTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.coding1094051862.basic;
1+
package com.coding.basic;
22

33
import junit.framework.Assert;
44

@@ -27,6 +27,10 @@ public void test() {
2727
Assert.assertEquals(3, list.get(5));
2828
Assert.assertEquals(4, list.get(6));
2929
Assert.assertEquals(800, list.get(8));
30+
Iterator iterator = list.iterator();
31+
while (iterator.hasNext()) {
32+
System.out.println(iterator.next());
33+
}
3034
}
3135

3236
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.coding.basic;
2+
3+
public interface List {
4+
public void add(Object o);
5+
public void add(int index, Object o);
6+
public Object get(int index);
7+
public Object remove(int index);
8+
public int size();
9+
public Iterator iterator();
10+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.coding.basic;
2+
3+
public class Queue {
4+
private List list = new ArrayList();
5+
private int size = 0;
6+
public void enQueue(Object o){
7+
list.add(o);
8+
size ++;
9+
}
10+
11+
public Object deQueue(){
12+
if (size == 0)
13+
return null;
14+
size --;
15+
return list.remove(0);
16+
}
17+
18+
public boolean isEmpty(){
19+
return size == 0;
20+
}
21+
22+
public int size(){
23+
return size;
24+
}
25+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.coding.basic;
2+
3+
import static org.junit.Assert.*;
4+
import junit.framework.Assert;
5+
6+
import org.junit.Test;
7+
8+
import sun.org.mozilla.javascript.internal.ast.NewExpression;
9+
10+
public class QueueTest {
11+
12+
@Test
13+
public void test() {
14+
Queue queue = new Queue();
15+
for (int i = 0; i < 100; i++) {
16+
queue.enQueue(i);
17+
}
18+
Assert.assertEquals(100, queue.size());
19+
for (int i = 0; i < 100; i++) {
20+
Assert.assertEquals(i, queue.deQueue());
21+
}
22+
Assert.assertEquals(0, queue.size());
23+
24+
}
25+
26+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.coding.basic;
2+
3+
public class Stack {
4+
private List elementData = new ArrayList();
5+
private int size = 0;
6+
public void push(Object o){
7+
elementData.add(o);
8+
size ++;
9+
}
10+
11+
public Object pop(){
12+
if (size == 0)
13+
return null;
14+
return elementData.remove(--size);
15+
}
16+
17+
public Object peek(){
18+
if (size == 0)
19+
return null;
20+
return elementData.get(size - 1);
21+
}
22+
public boolean isEmpty(){
23+
return size == 0;
24+
}
25+
public int size(){
26+
return size;
27+
}
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.coding.basic;
2+
3+
import static org.junit.Assert.*;
4+
import junit.framework.Assert;
5+
6+
import org.junit.BeforeClass;
7+
import org.junit.Test;
8+
9+
public class StackTest {
10+
11+
@Test
12+
public void test() {
13+
Stack stack = new Stack();
14+
for (int i = 0; i < 100; i++) {
15+
stack.push(i);
16+
}
17+
Assert.assertEquals(100, stack.size());
18+
Assert.assertEquals(99, stack.pop());
19+
for (int i = 98; i >= 0; i--) {
20+
Assert.assertEquals(i, stack.peek());
21+
Assert.assertEquals(i, stack.pop());
22+
}
23+
Assert.assertEquals(0, stack.size());
24+
}
25+
26+
}

group05/1094051862/test01/src/com/coding1094051862/basic/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

group05/1377699408/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/bin
2+
.classpath
3+
.project
4+
.settings/
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package list;
2+
3+
import java.util.Arrays;
4+
5+
public class ArrayList<E> {
6+
private transient static int INITIAL_SIZE = 10;
7+
private transient int arrayLength;
8+
private transient int size;
9+
private transient E[] array;
10+
public ArrayList(){
11+
array = (E[]) new Object[INITIAL_SIZE];
12+
arrayLength = INITIAL_SIZE;
13+
}
14+
public ArrayList(int size){
15+
if(size<=0){
16+
throw new IllegalArgumentException("参数不可以小于0");
17+
}
18+
array = (E[])new Object[size];
19+
arrayLength = array.length;
20+
ensureCapacity(size);
21+
this.size = size;
22+
}
23+
public int size(){
24+
return size;
25+
}
26+
public void add(E e){
27+
ensureCapacity(size+1);
28+
array[size] = e;
29+
size++;
30+
}
31+
public E get(int index){
32+
if(index<0 || index > size){
33+
throw new IllegalArgumentException("索引越界");
34+
}
35+
return array[index];
36+
37+
}
38+
public E set(int index, E e){
39+
if(index<0 || index>size){
40+
throw new IllegalArgumentException("索引越界");
41+
}
42+
E result = array[index];
43+
array[index] = e;
44+
return result;
45+
}
46+
private void ensureCapacity(int size){
47+
E[] oldArray = array;
48+
int oldSize = arrayLength;
49+
while(size>arrayLength){
50+
arrayLength = arrayLength + (arrayLength >> 1);
51+
array = Arrays.copyOf(oldArray, arrayLength);
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)