Skip to content

Commit cf59ffb

Browse files
committed
update
2 parents e6aa67f + cff7fd3 commit cf59ffb

38 files changed

+1403
-98
lines changed

group07/1058267830/git命令.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

group07/1058267830/week1/.classpath

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="src" path="test"/>
5+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.7.0_80"/>
6+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
7+
<classpathentry kind="output" path="bin"/>
8+
</classpath>

group07/1058267830/week1/.project

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>week1</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.7
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.7
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.7
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package com.coding.basic;
2+
3+
public class ArrayList implements List, Iterator {
4+
5+
private Object[] obj ;
6+
private int length; // 数组总长度
7+
private int size; // 元素个数
8+
private int currentIndex; // 当前索引位置,默认为-1
9+
10+
public int getLength() {
11+
return length;
12+
}
13+
14+
public ArrayList(){
15+
this.obj = new Object[10];
16+
this.length = 10;
17+
this.size = 0;
18+
this.currentIndex = -1;
19+
}
20+
21+
public ArrayList(int initSize){
22+
this.obj = new Object[initSize];
23+
this.length = initSize;
24+
this.size = 0;
25+
this.currentIndex = -1;
26+
}
27+
28+
@Override
29+
public void add(Object o) {
30+
if(this.size < length){
31+
obj[size] = o;
32+
this.size++;
33+
34+
}else{
35+
// 扩容,add数据
36+
Object[] obj1 = new Object[length * 2];
37+
System.arraycopy(obj, 0, obj1, 0, length);
38+
this.length = this.length * 2;
39+
this.obj = obj1;
40+
obj[this.size] = o;
41+
this.size++;
42+
}
43+
}
44+
45+
@Override
46+
public void add(int index, Object o) {
47+
if(index < length){
48+
// 容量扩1,add数据
49+
Object[] obj1 = new Object[length + 1];
50+
System.arraycopy(obj, 0, obj1, 0, index);
51+
System.arraycopy(obj, index, obj1, index+1, length-index);
52+
obj1[index] = o;
53+
this.obj = obj1;
54+
this.length++;
55+
this.size++;
56+
}else{
57+
// 容量扩到index+1, add数据
58+
Object[] obj1 = new Object[index + 1];
59+
System.arraycopy(obj, 0, obj1, 0, length);
60+
obj1[index] = o;
61+
this.obj = obj1;
62+
this.length = index + 1;
63+
this.size++;
64+
}
65+
}
66+
67+
@Override
68+
public Object get(int index) {
69+
if(index >= length)
70+
throw new RuntimeException("数组越界了...");
71+
return this.obj[index];
72+
}
73+
74+
@Override
75+
public Object remove(int index) {
76+
if(index >= length)
77+
throw new RuntimeException("数组越界了...");
78+
Object tmp = obj[index];// 取值,最后返回
79+
Object[] obj1 = new Object[length -1];
80+
System.arraycopy(obj, 0, obj1, 0, index);
81+
System.arraycopy(obj, index+1, obj1, index, length-index-1);
82+
this.obj = obj1;
83+
this.length--;
84+
this.size--;
85+
return tmp;
86+
}
87+
88+
@Override
89+
public int size() {
90+
return this.size;
91+
}
92+
93+
@Override
94+
public boolean hasNext() {
95+
if(currentIndex == length-1){
96+
return false;
97+
}else{
98+
currentIndex++;
99+
return true;
100+
}
101+
}
102+
103+
@Override
104+
public Object next() {
105+
return this.get(currentIndex);
106+
}
107+
108+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.coding.basic;
2+
3+
public class BinaryTree {
4+
private BinaryTreeNode root; // 根节点
5+
public BinaryTree( ){
6+
BinaryTreeNode node = new BinaryTreeNode();
7+
this.root = node;
8+
}
9+
10+
public boolean isEmpty(){
11+
return this.root == null;
12+
}
13+
14+
public void insert(Object o){
15+
// 如果是第一次添加节点,就是root节点
16+
if(root.data == null){
17+
BinaryTreeNode bnode = new BinaryTreeNode(o, null, null);
18+
root = bnode;
19+
}else{
20+
insert(o, root);
21+
}
22+
}
23+
24+
// 递归添加非root节点
25+
private BinaryTreeNode insert(Object o, BinaryTreeNode node) {
26+
if(node == null){
27+
BinaryTreeNode bnode = new BinaryTreeNode(o, null, null);
28+
return bnode;
29+
}
30+
if((int)o <= (int)node.data){
31+
node.left = insert(o, node.left);
32+
}else{
33+
node.right = insert(o, node.right);
34+
}
35+
36+
return node;
37+
}
38+
39+
// 中序遍历
40+
public void middlePrint(){
41+
middleOrder(this.root);
42+
}
43+
44+
private void middleOrder(BinaryTreeNode node) {
45+
if(node != null){
46+
middleOrder(node.left);
47+
System.out.print(node.data + " ");
48+
middleOrder(node.right);
49+
}
50+
}
51+
52+
// 前序遍历
53+
public void prePrint(){
54+
preOrder(this.root);
55+
}
56+
57+
private void preOrder(BinaryTreeNode node) {
58+
if(node != null){
59+
System.out.print(node.data + " ");
60+
preOrder(node.left);
61+
preOrder(node.right);
62+
}
63+
}
64+
65+
// 后序遍历
66+
public void postPrint(){
67+
postOrder(this.root);
68+
}
69+
70+
private void postOrder(BinaryTreeNode node) {
71+
if(node != null){
72+
postOrder(node.right);
73+
System.out.print(node.data + " ");
74+
postOrder(node.left);
75+
}
76+
}
77+
78+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.coding.basic;
2+
3+
public class BinaryTreeNode {
4+
5+
protected Object data;
6+
protected BinaryTreeNode left;
7+
protected BinaryTreeNode right;
8+
9+
public BinaryTreeNode(){}
10+
public BinaryTreeNode(Object data, BinaryTreeNode left, BinaryTreeNode right){
11+
this.data = data;
12+
this.left = left;
13+
this.right = right;
14+
}
15+
16+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.coding.basic;
2+
3+
public interface Iterator {
4+
5+
public boolean hasNext();
6+
7+
public Object next();
8+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package com.coding.basic;
2+
3+
public class LinkedList implements List, Iterator{
4+
private Node head;
5+
private Node tail;
6+
private Node currentNode;
7+
private int size;
8+
9+
public LinkedList(){
10+
this.head = new Node(null);
11+
this.tail = head;
12+
this.currentNode = head;
13+
this.size = 0;
14+
}
15+
16+
@Override
17+
public void add(Object o) {
18+
Node node = new Node(o, null);
19+
tail.setNext(node);
20+
tail = node;
21+
size++;
22+
}
23+
24+
@Override
25+
public void add(int index, Object o) {
26+
if(index < 0 || index > size+1){
27+
throw new RuntimeException("插入的位置错误...");
28+
}
29+
Node pre = head; // 得到待插入位置的前一个节点
30+
for(int i=0; i<index; i++){
31+
pre = pre.getNext();
32+
}
33+
Node behind = pre.getNext(); // 得到待插入位置的节点
34+
Node node = new Node(o, behind); // 构造当前节点并使当前节点的next指向behind
35+
pre.setNext(node);
36+
size++;
37+
}
38+
39+
@Override
40+
public Object get(int index) {
41+
if(index < 0 || index >= size){
42+
throw new RuntimeException("index参数错误...");
43+
}
44+
Node node = head; // 得到待插入位置的前一个节点
45+
for(int i=0; i<=index; i++){
46+
node = node.getNext();
47+
}
48+
return node;
49+
}
50+
51+
@Override
52+
public Object remove(int index) {
53+
if(index < 0 || index >= size){
54+
throw new RuntimeException("index参数错误...");
55+
}
56+
Node pre = head; // 得到待删除位置的前一个节点
57+
for(int i=0; i<index; i++){
58+
pre = pre.getNext();
59+
}
60+
Node node = pre.getNext(); // 得到待删除位置的节点并返回
61+
Node behind = node.getNext(); // 得到待删除位置的后一个节点
62+
pre.setNext(behind);
63+
size--;
64+
return node;
65+
}
66+
67+
@Override
68+
public int size() {
69+
return size;
70+
}
71+
72+
// 按顺序打印节点值
73+
public void printData(){
74+
Node node = head.getNext();
75+
while(node != null){
76+
System.out.println(node.getData());
77+
node = node.getNext();
78+
}
79+
}
80+
81+
@Override
82+
public boolean hasNext() {
83+
if(currentNode == tail){
84+
return false;
85+
}else{
86+
currentNode = currentNode.getNext();
87+
return true;
88+
}
89+
90+
}
91+
92+
@Override
93+
public Object next() {
94+
return currentNode;
95+
}
96+
97+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.coding.basic;
2+
3+
public interface List {
4+
5+
public void add(Object o);
6+
7+
public void add(int index, Object o);
8+
9+
public Object get(int index);
10+
11+
public Object remove(int index);
12+
13+
public int size();
14+
}

0 commit comments

Comments
 (0)