Skip to content

Commit 4f7b480

Browse files
committed
test01
1 parent d4a25d6 commit 4f7b480

File tree

13 files changed

+324
-0
lines changed

13 files changed

+324
-0
lines changed

group05/1094051862/test01/.classpath

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.junit.JUNIT_CONTAINER/4"/>
5+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>

group05/1094051862/test01/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/

group05/1094051862/test01/.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>test01</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+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
4+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
5+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6+
org.eclipse.jdt.core.compiler.compliance=1.7
7+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
9+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12+
org.eclipse.jdt.core.compiler.source=1.7
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/ArrayList.java
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.coding1094051862.basic;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
public class ArrayListTest {
7+
8+
@Test
9+
public void test() {
10+
ArrayList list = new ArrayList();
11+
for(int i = 0; i < 10; i++) {
12+
list.add(i);
13+
}
14+
Assert.assertEquals(10, list.size());
15+
list.add(11);
16+
list.add(3,99);
17+
Assert.assertEquals(99, list.get(3));
18+
Assert.assertEquals(12, list.size());
19+
Assert.assertEquals(99, list.remove(3));
20+
Assert.assertEquals(11, list.size());
21+
}
22+
23+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.coding1094051862.basic;
2+
3+
public class BinaryTreeNode {
4+
5+
private Object data;
6+
private BinaryTreeNode left;
7+
private BinaryTreeNode right;
8+
9+
public Object getData() {
10+
return data;
11+
}
12+
public void setData(Object data) {
13+
this.data = data;
14+
}
15+
public BinaryTreeNode getLeft() {
16+
return left;
17+
}
18+
public void setLeft(BinaryTreeNode left) {
19+
this.left = left;
20+
}
21+
public BinaryTreeNode getRight() {
22+
return right;
23+
}
24+
public void setRight(BinaryTreeNode right) {
25+
this.right = right;
26+
}
27+
28+
public BinaryTreeNode insert(Object o){
29+
return null;
30+
}
31+
32+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.coding1094051862.basic;
2+
3+
public interface Iterator {
4+
public boolean hasNext();
5+
public Object next();
6+
7+
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
package com.coding1094051862.basic;
2+
3+
public class LinkedList implements List {
4+
5+
private Node head;
6+
private Node last;
7+
private int size = 0;
8+
9+
public void add(Object o){
10+
if (head == null) {
11+
head = new Node(o, null);
12+
size ++;
13+
return;
14+
}
15+
Node n = new Node(o, null);
16+
if (last == null) {
17+
last = n;
18+
head.next = last;
19+
}
20+
last.next = n;
21+
last = n;
22+
size ++;
23+
}
24+
public void add(int index , Object o){
25+
if (index < 0 || index > size) {
26+
System.out.println("linkedList.add: index < 0 || index > size");
27+
return;
28+
}
29+
if (index == size) {
30+
add(o);
31+
return;
32+
}
33+
if (index == 0) {
34+
addFirst(o);
35+
return;
36+
}
37+
Node pre = head;
38+
for (int i = 1; i < index; i++) {
39+
pre = pre.next;
40+
}
41+
Node post = pre.next;
42+
Node n = new Node(o,post);
43+
pre.next = n;
44+
size ++;
45+
}
46+
public Object get(int index){
47+
if (index == 0) {
48+
return head.data;
49+
}
50+
Node n = head;
51+
for (int i = 1; i <= index; i++) {
52+
n = n.next;
53+
}
54+
return n.data;
55+
}
56+
public Object remove(int index){
57+
if (index < 0 || index >= size) {
58+
System.out.println("remove :index < 0 || index >= size");
59+
return null;
60+
}
61+
if (index == 0) {
62+
return removeFirst();
63+
}
64+
if (index == size - 1) {
65+
return removeLast();
66+
}
67+
Node pre = head;
68+
for (int i = 1; i < index; i++) {
69+
pre = pre.next;
70+
}
71+
Node n = pre.next;
72+
Node post = n.next;
73+
n.next = null;
74+
pre.next = post;
75+
size --;
76+
return n.data;
77+
}
78+
79+
public int size(){
80+
return size;
81+
}
82+
83+
public void addFirst(Object o){
84+
Node n = new Node(o,head);
85+
head = n;
86+
size ++;
87+
return;
88+
}
89+
public void addLast(Object o){
90+
Node n = new Node(o,null);
91+
last.next = n;
92+
last = n;
93+
size ++;
94+
return;
95+
}
96+
public Object removeFirst(){
97+
Object o = head.data;
98+
Node n = head.next;
99+
head.next = null;
100+
head = n;
101+
size --;
102+
return o;
103+
}
104+
public Object removeLast(){
105+
Node preLast = head;
106+
for (int i = 1; i < size; i++) {
107+
preLast = preLast.next;
108+
}
109+
preLast.next = null;
110+
Object o = last.data;
111+
last = preLast;
112+
size --;
113+
return o;
114+
}
115+
public Iterator iterator(){
116+
return new Iterator() {
117+
@Override
118+
public Object next() {
119+
// TODO Auto-generated method stub
120+
return null;
121+
}
122+
123+
@Override
124+
public boolean hasNext() {
125+
// TODO Auto-generated method stub
126+
return false;
127+
}
128+
};
129+
}
130+
131+
132+
private static class Node {
133+
134+
Object data;
135+
Node next;
136+
137+
public Node (Object data, Node next) {
138+
this.data = data;
139+
this.next = next;
140+
}
141+
}
142+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.coding1094051862.basic;
2+
3+
import junit.framework.Assert;
4+
5+
import org.junit.Test;
6+
7+
public class LinkedListTest extends LinkedList {
8+
9+
@Test
10+
public void test() {
11+
List list = new LinkedList();
12+
list.add(0);
13+
list.add(1);
14+
list.add(2);
15+
list.add(3);
16+
list.add(4);
17+
list.add(5);
18+
list.add(3, 33);
19+
list.add(0, 100);
20+
list.add(8,800);
21+
Assert.assertEquals(9, list.size());
22+
Assert.assertEquals(100, list.get(0));
23+
Assert.assertEquals(0, list.get(1));
24+
Assert.assertEquals(1, list.get(2));
25+
Assert.assertEquals(2, list.get(3));
26+
Assert.assertEquals(33, list.get(4));
27+
Assert.assertEquals(3, list.get(5));
28+
Assert.assertEquals(4, list.get(6));
29+
Assert.assertEquals(800, list.get(8));
30+
}
31+
32+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.coding1094051862.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+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.coding1094051862.basic;
2+
3+
public class Queue {
4+
5+
public void enQueue(Object o){
6+
}
7+
8+
public Object deQueue(){
9+
return null;
10+
}
11+
12+
public boolean isEmpty(){
13+
return false;
14+
}
15+
16+
public int size(){
17+
return -1;
18+
}
19+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.coding1094051862.basic;
2+
3+
public class Stack {
4+
private ArrayList elementData = new ArrayList();
5+
6+
public void push(Object o){
7+
}
8+
9+
public Object pop(){
10+
return null;
11+
}
12+
13+
public Object peek(){
14+
return null;
15+
}
16+
public boolean isEmpty(){
17+
return false;
18+
}
19+
public int size(){
20+
return -1;
21+
}
22+
}

0 commit comments

Comments
 (0)