Skip to content

Commit fa0a05f

Browse files
authored
Merge pull request onlyliuxin#35 from 844028312/master
第四组小组作业
2 parents b7f3f10 + 594705e commit fa0a05f

File tree

211 files changed

+9432
-0
lines changed

Some content is hidden

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

211 files changed

+9432
-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"/>
5+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/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>1020483199Learning</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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
eclipse.preferences.version=1
2+
encoding//src/com/coding/basic=UTF-8
3+
encoding/<project>=UTF-8
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: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package com.coding.basic;
2+
3+
import java.util.Arrays;
4+
import java.util.ConcurrentModificationException;
5+
import java.util.NoSuchElementException;
6+
7+
public class ArrayList implements List {
8+
9+
10+
private int size = 0;
11+
12+
private transient Object[] elementData = new Object[100];
13+
/**
14+
* 向数组中添加某个元素
15+
*/
16+
public void add(Object o){
17+
/**
18+
* 数组扩容判断
19+
*/
20+
ensureSize(size+1);
21+
elementData[size++] = o;
22+
}
23+
/**
24+
* 向指定位置数组中添加某个元素
25+
*/
26+
public void add(int index, Object o){
27+
if(index<0||index>size){
28+
throw new IndexOutOfBoundsException("数组越界");
29+
}
30+
ensureSize(size+1);
31+
System.arraycopy(elementData, index, elementData, index+1, size-index);
32+
elementData[index] = o;
33+
}
34+
/**
35+
* 获取数组中某个位置元素
36+
*/
37+
public Object get(int index){
38+
if(index<0||index>elementData.length){
39+
return null;
40+
}else{
41+
return elementData[index];
42+
}
43+
44+
}
45+
/**
46+
* 移除数组中指定位置元素
47+
*/
48+
public Object remove(int index){
49+
if(index<0||index>elementData.length){
50+
return null;
51+
}else{
52+
int newLength = size-index-1;
53+
if (newLength>0)
54+
System.arraycopy(elementData, index+1, elementData, index, size-index-1);
55+
elementData[--size] = null;
56+
return elementData;
57+
}
58+
}
59+
/**
60+
* 获取当前数组的大小
61+
*/
62+
public int size(){
63+
if(size>0){
64+
return this.size;
65+
}else{
66+
return 0;
67+
}
68+
}
69+
/**
70+
* 利用arraylist实现迭代器
71+
* @return
72+
*/
73+
public Iterator iterator(){
74+
75+
return new ArrayListIterator();
76+
}
77+
private class ArrayListIterator implements Iterator{
78+
int cursor;
79+
int lastReset = -1;
80+
@Override
81+
public boolean hasNext() {
82+
return size!=cursor;
83+
}
84+
85+
@Override
86+
public Object next() {
87+
//标记索引当前位置
88+
int i = cursor;
89+
if(i>size){
90+
throw new NoSuchElementException();
91+
}
92+
Object[] newData = elementData;
93+
if(i>newData.length){
94+
throw new ConcurrentModificationException();
95+
}
96+
cursor = i + 1;
97+
return newData[lastReset = i];
98+
}
99+
100+
}
101+
102+
103+
/**
104+
* @author sulei
105+
* @param minCapcity
106+
*/
107+
public void ensureSize(int minCapcity){
108+
if(minCapcity>elementData.length){
109+
grow(minCapcity);
110+
}
111+
}
112+
113+
/**
114+
* @author sulei
115+
* @param autoCapcity
116+
*/
117+
public void grow(int autoCapcity){
118+
int oldLength = elementData.length;
119+
if(autoCapcity>oldLength){
120+
Object[] oldData = elementData;
121+
int newLength = (oldLength * 3)/2 + 1;
122+
if(autoCapcity>newLength){
123+
newLength=autoCapcity;
124+
}
125+
elementData = Arrays.copyOf(elementData, newLength);
126+
}
127+
}
128+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.coding.basic;
2+
3+
public class BinaryTreeNode {
4+
5+
private Object data;
6+
private BinaryTreeNode left;
7+
private BinaryTreeNode right;
8+
//存放当前树
9+
private BinaryTreeNode primary;
10+
11+
public BinaryTreeNode getPrimary() {
12+
return primary;
13+
}
14+
15+
public void setPrimary(BinaryTreeNode primary) {
16+
this.primary = primary;
17+
}
18+
19+
20+
public Object getData() {
21+
return data;
22+
}
23+
public void setData(Object data) {
24+
this.data = data;
25+
}
26+
public BinaryTreeNode getLeft() {
27+
return left;
28+
}
29+
public void setLeft(BinaryTreeNode left) {
30+
this.left = left;
31+
}
32+
public BinaryTreeNode getRight() {
33+
return right;
34+
}
35+
public void setRight(BinaryTreeNode right) {
36+
this.right = right;
37+
}
38+
/**
39+
* 在二叉树中插入
40+
* @param o
41+
* @return
42+
*/
43+
public BinaryTreeNode insert(Object o){
44+
if(o==null){
45+
throw new IllegalArgumentException("二叉树的元素不能为空!");
46+
}
47+
//新建要插入的节点
48+
BinaryTreeNode bt = new BinaryTreeNode();
49+
bt.setData(o);
50+
int value = (int)o;
51+
//当原始二叉树为空时
52+
if(primary==null){
53+
primary = bt;
54+
}else{
55+
BinaryTreeNode bi = primary;
56+
while(true){
57+
if(value<(int)bi.data){
58+
if(bi.left==null){
59+
bi.setLeft(bt);
60+
break;
61+
}else{
62+
bi=bi.left;
63+
}
64+
}else if(value>(int)bi.data){
65+
if(bi.right==null){
66+
bi.setRight(bt);
67+
break;
68+
}else{
69+
bi=bi.right;
70+
}
71+
72+
}else{
73+
System.out.println("当前元素在二叉树已存在");
74+
break;
75+
}
76+
}
77+
}
78+
79+
return bt;
80+
}
81+
82+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.coding.basic;
2+
3+
public interface Iterator {
4+
public boolean hasNext();
5+
public Object next();
6+
7+
}

0 commit comments

Comments
 (0)