Skip to content

Commit 4b19a0b

Browse files
committed
Tennyson's task
1 parent d4a25d6 commit 4b19a0b

File tree

12 files changed

+772
-0
lines changed

12 files changed

+772
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
5+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/bin/
2+
/bin/
3+
/bin/
4+
/bin/
5+
/bin/
6+
/bin/
7+
/bin/
8+
/bin/
9+
/bin/
10+
/bin/
11+
/bin/
12+
/bin/
13+
/bin/
14+
/bin/
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>2017Learning</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.8
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.8
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
package com.coding.basic;
2+
3+
import java.util.Arrays;
4+
5+
/**
6+
* ArrayList 实现 第14小组 296933284
7+
*
8+
* @author Tonnyson
9+
*
10+
*/
11+
public class ArrayList implements List {
12+
13+
private int size;
14+
private static final int DEFAULT_CAPACITY = 10;
15+
private Object[] elementData;
16+
17+
18+
public ArrayList() {
19+
elementData = new Object[DEFAULT_CAPACITY];
20+
}
21+
22+
public ArrayList(int initCapacity) {
23+
elementData = new Object[initCapacity];
24+
}
25+
26+
/**
27+
* 在数组末尾添加指定元素,若数组已满,则自动扩展为原来长度的两倍
28+
*/
29+
public void add(Object obj) {
30+
31+
ensureCapacityInternal(size);
32+
33+
elementData[size] = obj;
34+
size++;
35+
}
36+
37+
38+
/**
39+
* 在数组的指定位置插入元素
40+
*/
41+
public void add(int index, Object obj) {
42+
43+
rangCheckForAdd(index);
44+
ensureCapacityInternal(size + 1);
45+
46+
for (int i = size - 1; i >= index; i--)
47+
elementData[i + 1] = elementData[i];
48+
49+
elementData[index] = obj;
50+
size++;
51+
}
52+
53+
/**
54+
* 给数组扩容
55+
*/
56+
private void ensureCapacityInternal(int minCapacity) {
57+
if (minCapacity - elementData.length > 0) {
58+
int newCapacity = elementData.length * 2;
59+
elementData = Arrays.copyOf(elementData, newCapacity);
60+
// elementData = tempElementData;
61+
}
62+
}
63+
64+
/**
65+
* 用于在 add() 中检查数组下表是否越界
66+
*/
67+
private void rangCheckForAdd(int index) {
68+
if (index > size || index < 0)
69+
throw new IndexOutOfBoundsException();
70+
}
71+
72+
/**
73+
* 返回指定索引位置的元素值
74+
*/
75+
public Object get(int index) {
76+
77+
rangCheck(index);
78+
79+
return elementData[index];
80+
}
81+
82+
/**
83+
* 删除指定索引位置的元素,并返回该值
84+
*/
85+
public Object remove(int index) {
86+
rangCheck(index);
87+
88+
Object obj = elementData[index];
89+
90+
for (int i = index; i < size; i++)
91+
elementData[i] = elementData[i + 1];
92+
93+
size--;
94+
95+
return obj;
96+
}
97+
98+
/**
99+
* 检查数组下表是否越界
100+
*
101+
* @param index
102+
*/
103+
private void rangCheck(int index) {
104+
if (index >= size)
105+
throw new IndexOutOfBoundsException();
106+
}
107+
108+
/**
109+
* 返回数组长度
110+
*/
111+
public int size() {
112+
return size;
113+
}
114+
115+
/**
116+
* 迭代器
117+
*
118+
* @return
119+
*/
120+
public Iterator iterator() {
121+
return new Iter();
122+
}
123+
124+
//迭代器内部类
125+
private class Iter implements Iterator {
126+
int current;
127+
128+
@Override
129+
public boolean hasNext() {
130+
return current != size;
131+
}
132+
133+
@Override
134+
public Object next() {
135+
136+
int i = current;
137+
rangCheck(i);
138+
current++;
139+
140+
return elementData[i];
141+
}
142+
143+
}
144+
145+
}
146+
147+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.coding.basic;
2+
3+
public class BinaryTreeNode implements Comparable {
4+
5+
private Object data;
6+
private BinaryTreeNode leftChild;
7+
private BinaryTreeNode rightChild;
8+
9+
public BinaryTreeNode() {
10+
super();
11+
this.data = null;
12+
this.leftChild = null;
13+
this.rightChild = null;
14+
}
15+
16+
public BinaryTreeNode(Object data) {
17+
super();
18+
this.data = data;
19+
}
20+
21+
public Object getData() {
22+
return data;
23+
}
24+
25+
public void setData(Object data) {
26+
this.data = data;
27+
}
28+
29+
public BinaryTreeNode getLeftChild() {
30+
return leftChild;
31+
}
32+
33+
public void setLeftChild(BinaryTreeNode leftChild) {
34+
this.leftChild = leftChild;
35+
}
36+
37+
public BinaryTreeNode getRightChild() {
38+
return rightChild;
39+
}
40+
41+
public void setRightChild(BinaryTreeNode rightChild) {
42+
this.rightChild = rightChild;
43+
}
44+
45+
/**
46+
* ÏòÊ÷ÖвåÈë½Úµã
47+
*
48+
* @param i
49+
*/
50+
public void insert(int i) {
51+
52+
}
53+
54+
// ...
55+
@Override
56+
public int compareTo(Object obj) {
57+
58+
return 0;
59+
}
60+
61+
62+
}
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+
74+
75+
76+
77+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.coding.basic;
2+
3+
public interface Iterator {
4+
public boolean hasNext();
5+
public Object next();
6+
}

0 commit comments

Comments
 (0)