Skip to content

Commit 8b50476

Browse files
committed
0206
1 parent ce0c358 commit 8b50476

File tree

11 files changed

+464
-0
lines changed

11 files changed

+464
-0
lines changed

group07/1536161030/.classpath

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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="output" path="bin"/>
6+
</classpath>

group07/1536161030/.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Compiled class file
2+
*.class
3+
4+
# Log file
5+
*.log
6+
7+
# BlueJ files
8+
*.ctxt
9+
10+
# Mobile Tools for Java (J2ME)
11+
.mtj.tmp/
12+
13+
# Package Files #
14+
*.jar
15+
*.war
16+
*.ear
17+
*.zip
18+
*.tar.gz
19+
*.rar
20+
21+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
22+
hs_err_pid*

group07/1536161030/.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>homework</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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
������ڲ���Ҫ���������CPU���ڴ棬Ӳ�̣�ָ�
2+
CPU��Ҳ�д��������˿�����˼�������Կ�CPU���㡣CPU��Ҫ�������Ϳ��ƵIJ��֣�����˼�壬���ǿ��Ƶ�Ԫ�����㵥Ԫ�����֣������˵Ĵ��Խ��м��������һ����
3+
�����Եļ����������һ��ģ����������ÿ�����ܵ�Ԫ���Ƿֹ���ȷ�ġ����п��Ƶ�Ԫ���ݳ���ͨ��ָ�����������㵥Ԫ����������ó������Ȼ����ƴ洢��Ԫ���洢�м�Ľ����
4+
�ڴ��Ǵ洢CPU��Ҫ���������ϣ���Ҫ�����У�����ϵͳ�е���ʱ���ݣ������Ӳ�̶�ȡ�����ݣ��ṩ��CPUʹ�á�
5+
Ӳ���Ǹ���洢������Ҫ���ô洢�����ݣ��������ǵij�������ݣ��ŵ��Ƿdz��̶���������׼ȷ���������Դ洢����Ϣ��������ʱ���������
6+
�ڴ��ȡ���ݵ��ٶȱ�Ӳ�̵Ĵ�ȡ�ٶȿ���10���� ��ijЩ��������ܻ����
7+
CPU���ٶȱ��ڴ治֪Ҫ����ٱ��������ǰѳ����Ӳ�̷ŵ��ڴ��Ժ�CPU��ֱ�����ڴ����г���������CPUֱ����Ӳ�����г����Ҫ��ܶࡣ
8+
�����ڴ�����һ����CPU���й��죬��Ӳ�����ݴ�ȡ̫�������⡣ ��������ǵĵ��Ե������ٶȡ�
9+
���������г����ʱ��CPU���Ƚ��ܵ����ǵ����֮��CPU�Ǹ���Ӳ�̣���Ҫ������洢�ij���A����ѳ���A�͵��ڴ�ȥ��CPU���ڴ�˵������Ӳ�̰ѳ���A�͵����������ˣ��㱣��һ�¡� �ȳ���A���������͵��ڴ�֮��CPU�Ϳ�ʼִ�г���A����CPU������㣬���ȡ������δ洢���ݣ�������ζ������������й�ͨ�������Ҫָ���ˡ�
10+
ָ��Ҳ���ǻ������Ե�һ������䣬�൱��CPU���ڴ棬Ӳ��֮������ԡ�����ָ�Ӽ�������������������������ݵ����㣬�߼����㣬���ݴ��ͣ�����Ŀ��ƣ��������ָ��ȡ�
11+
12+
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.coding.basic;
2+
3+
public class ArrayList implements List{
4+
5+
private int size = 0;
6+
7+
private Object[] elementData;
8+
9+
public ArrayList(int size) {
10+
this.elementData = new Object[size];
11+
}
12+
13+
public ArrayList() {
14+
this.elementData = new Object[100];
15+
}
16+
17+
public void add(Object o) {
18+
if(isFull())
19+
resize();
20+
elementData[size++] = o;
21+
}
22+
23+
public void add(int index, Object o) {
24+
rangeCheckForAdd(index);
25+
System.arraycopy(elementData, index, elementData, index + 1, size - index);
26+
elementData[index] = o;
27+
size++;
28+
29+
}
30+
31+
public Object get(int index) {
32+
rangeCheckForAdd(index);
33+
return elementData[index];
34+
}
35+
36+
public Object remove(int index) {
37+
rangeCheckForAdd(index);
38+
Object o = elementData[index];
39+
System.arraycopy(elementData, index + 1, elementData, index, size - index);
40+
elementData[--size] = null;
41+
return o;
42+
}
43+
44+
public int size() {
45+
return elementData.length;
46+
}
47+
48+
public com.coding.basic.Iterator iterator() {
49+
return new Itr();
50+
}
51+
52+
private class Itr implements com.coding.basic.Iterator {
53+
int cursor;
54+
55+
@Override
56+
public boolean hasNext() {
57+
return cursor != size;
58+
}
59+
60+
@Override
61+
public Object next() {
62+
int i = cursor;
63+
if (i < elementData.length) {
64+
cursor = i + 1;
65+
return elementData[i];
66+
}
67+
return null;
68+
}
69+
}
70+
71+
//檢查下表越界
72+
public void rangeCheckForAdd(int index) {
73+
if (index < 0 || index > size)
74+
throw new RuntimeException("下标越界");
75+
}
76+
77+
//数组是否满
78+
public boolean isFull(){
79+
return size == elementData.length;
80+
}
81+
82+
//扩容
83+
public void resize(){
84+
Object[] newElementData = new Object[elementData.length * 2];
85+
System.arraycopy(elementData, 0, newElementData, 0, size);
86+
this.elementData = newElementData;
87+
newElementData = null;
88+
}
89+
90+
91+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package com.coding.basic;
2+
3+
public class BinaryTreeNode <Object extends Comparable<Object>> {
4+
5+
private Object data;
6+
7+
private BinaryTreeNode left;
8+
9+
private BinaryTreeNode right;
10+
11+
public BinaryTreeNode(Object data){
12+
this.data = data;
13+
this.left=null;
14+
this.right =null;
15+
}
16+
17+
public BinaryTreeNode root;
18+
19+
public Object getData() {
20+
return data;
21+
}
22+
23+
public void setData(Object data) {
24+
this.data = data;
25+
}
26+
27+
public BinaryTreeNode getLeft() {
28+
return left;
29+
}
30+
31+
public void setLeft(BinaryTreeNode left) {
32+
this.left = left;
33+
}
34+
35+
public BinaryTreeNode getRight() {
36+
return right;
37+
}
38+
39+
public void setRight(BinaryTreeNode right) {
40+
this.right = right;
41+
}
42+
/*
43+
* 二叉树 b 插入对象 o 父节点 pnode
44+
* 若b为空树,插入节点作为根
45+
* o 等于根节点 直接返回
46+
* o 小于根节点 pnode = 左子树
47+
* else pnode = 右子树
48+
*
49+
*/
50+
public BinaryTreeNode insert(Object o) {
51+
BinaryTreeNode current = root;
52+
53+
if(current == null){
54+
return new BinaryTreeNode(o);
55+
}
56+
if (o.compareTo((Object) current.data)<0){
57+
if(current.left !=null){
58+
current = current.left;
59+
}else{
60+
current.left = new BinaryTreeNode(o);
61+
return current;
62+
}
63+
}else if(o.compareTo((Object) current.data)==0){
64+
return current;
65+
}else{
66+
if(current.right !=null){
67+
current = current.right;
68+
}else{
69+
current.right = new BinaryTreeNode(o);
70+
return current;
71+
}
72+
}
73+
return current;
74+
}
75+
}
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+
boolean hasNext();
5+
6+
Object next();
7+
8+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package com.coding.basic;
2+
3+
public class LinkedList implements List {
4+
5+
private Node head;
6+
int size;
7+
8+
public void add(Object o) {
9+
Node newNode = new Node(o);
10+
newNode.next = head.next;
11+
head.next = newNode;
12+
size++;
13+
}
14+
15+
public void add(int index, Object o) {
16+
Node indexNode = node(index);
17+
Node newNode = new Node(o);
18+
newNode.next = indexNode.next;
19+
indexNode.next = newNode;
20+
size++;
21+
}
22+
23+
public Object get(int index) {
24+
return node(index).data;
25+
}
26+
27+
public Object remove(int index) {
28+
Node indexNode = node(index);
29+
Node preNode = node(index);
30+
preNode.next = indexNode.next;
31+
indexNode.next = null;
32+
size--;
33+
return indexNode.data;
34+
}
35+
36+
public int size() {
37+
return size;
38+
}
39+
40+
public void addFirst(Object o) {
41+
if(o == null){
42+
throw new RuntimeException("不能加入null元素");
43+
}
44+
Node newNode = new Node(o);
45+
newNode.next = head;
46+
size++;
47+
}
48+
49+
public void addLast(Object o) {
50+
Node newNode = new Node(o);
51+
Node last = node(size);
52+
53+
newNode.next = last.next;
54+
last.next = newNode;
55+
size++;
56+
}
57+
58+
public Object removeFirst() {
59+
Node oldNode = head;
60+
head = head.next;
61+
head.next = null;
62+
size--;
63+
return oldNode.data;
64+
}
65+
66+
public Object removeLast() {
67+
Node oldNode = node(size);
68+
Node preNode = node(size - 1);
69+
preNode.next = null;
70+
size--;
71+
return oldNode.data;
72+
}
73+
74+
public Iterator iterator(int index) {
75+
return new Itr(index);
76+
}
77+
78+
// TODO: 2017/2/24
79+
private class Itr implements com.coding.basic.Iterator {
80+
private int nextIndex;
81+
82+
public Itr(int index) {
83+
this.nextIndex = index;
84+
}
85+
86+
@Override
87+
public boolean hasNext() {
88+
return nextIndex < size;
89+
}
90+
91+
@Override
92+
public Object next() {
93+
return null;
94+
}
95+
}
96+
97+
98+
private static class Node {
99+
public Object data;
100+
public Node next;
101+
102+
public Node(Object data) {
103+
this.data = data;
104+
this.next = null;
105+
}
106+
107+
}
108+
109+
Node node(int index) {
110+
Node x = head;
111+
for (int i = 0; i < index; i++)
112+
x = x.next;
113+
return x;
114+
}
115+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.coding.basic;
2+
3+
public interface List {
4+
public void add(Object o);
5+
6+
public void add(int index, Object o);
7+
8+
public Object get(int index);
9+
10+
public Object remove(int index);
11+
12+
public int size();
13+
}

0 commit comments

Comments
 (0)