Skip to content

Commit 067521b

Browse files
authored
Merge pull request onlyliuxin#9 from core2for/master
my work
2 parents ccc6ceb + 21c7401 commit 067521b

File tree

11 files changed

+340
-0
lines changed

11 files changed

+340
-0
lines changed

group18/1787597051/.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/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>

group18/1787597051/.gitignore

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

group18/1787597051/.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>1787597051</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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
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: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package com.coding.basic;
2+
3+
import java.util.Arrays;
4+
5+
public class MyArrayList implements MyList {
6+
private final int GROW = 4;
7+
private int size = 0;
8+
9+
private Object[] elementData = new Object[4];
10+
11+
public void add(Object o) {
12+
if (size > elementData.length - 1) {
13+
elementData = Arrays.copyOf(elementData, elementData.length + GROW);
14+
elementData[size] = o;
15+
} else {
16+
elementData[size] = o;
17+
}
18+
size++;
19+
}
20+
21+
public void add(int index, Object o) {
22+
Object[] target = new Object[elementData.length - index];
23+
for (int x = index, y = 0; x < elementData.length; x++, y++) {
24+
target[y] = elementData[x];
25+
}
26+
elementData = Arrays.copyOf(elementData, elementData.length + 1);
27+
size = index;
28+
// elementData[index] = o;
29+
elementData[size] = o;
30+
size++;
31+
for (int y = 0; y < target.length; y++) {
32+
// add(target[y]);
33+
elementData[size] = target[y];
34+
size++;
35+
}
36+
}
37+
38+
public Object get(int index) {
39+
return elementData[index];
40+
}
41+
42+
public Object remove(int index) {
43+
Object removeData = elementData[index];
44+
elementData[index] = null;
45+
Object[] target = Arrays.copyOfRange(elementData, index + 1, elementData.length);
46+
for (int x = index, y = 0; y < target.length; y++, x++) {
47+
elementData[x] = target[y];
48+
}
49+
size--;
50+
return removeData;
51+
}
52+
53+
public int size() {
54+
return size;
55+
}
56+
57+
public MyIteratorImpl iterator() {
58+
return new MyIteratorImpl();
59+
}
60+
61+
private class MyIteratorImpl implements MyIterator {
62+
int index;
63+
64+
public boolean hasNext() {
65+
return index != size;
66+
}
67+
68+
public Object next() {
69+
int i = index;
70+
index = i + 1;
71+
return elementData[i];
72+
}
73+
74+
}
75+
}
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 MyIterator {
4+
public abstract boolean hasNext();
5+
public abstract Object next();
6+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
package com.coding.basic;
2+
3+
public class MyLinkedList implements MyList {
4+
private int size;
5+
private Node head;
6+
7+
public MyLinkedList() {
8+
head = new Node();
9+
head.data = "͡˝áľă";
10+
head.next = null;
11+
}
12+
13+
public void add(Object o) {
14+
Node p = head;
15+
while (p.next != null) {
16+
p = p.next;
17+
}
18+
Node p3 = new Node();
19+
p3.data = o;
20+
p.next = p3;
21+
size++;
22+
}
23+
24+
public void add(int index, Object o) {
25+
int num = 0;
26+
Node p = head;
27+
while (p.next != null) {
28+
if (num == index) {
29+
Node p2 = new Node();
30+
p2.data = o;
31+
p2.next = p.next;
32+
p.next = p2;
33+
size++;
34+
}
35+
p = p.next;
36+
num++;
37+
}
38+
}
39+
40+
public Object get(int index) {
41+
int num = 0;
42+
Node p = head.next;
43+
while (p != null) {
44+
if (num == index) {
45+
return p.data;
46+
}
47+
p = p.next;
48+
num++;
49+
}
50+
return null;
51+
}
52+
53+
public Object remove(int index) {
54+
int num = 0;
55+
Node p = head;
56+
while (p.next != null) {
57+
if (num == index) {
58+
Node p2 = p.next;
59+
p.next = p.next.next;
60+
size--;
61+
return p2.data;
62+
}
63+
p = p.next;
64+
num++;
65+
}
66+
return null;
67+
}
68+
69+
public int size() {
70+
return size;
71+
}
72+
73+
public void addFirst(Object o) {
74+
Node p = new Node();
75+
p.data = o;
76+
p.next = head.next;
77+
head.next = p;
78+
size++;
79+
}
80+
81+
public void addLast(Object o) {
82+
Node p = head;
83+
while (p.next != null) {
84+
p = p.next;
85+
}
86+
Node p2 = new Node();
87+
p2.data = o;
88+
p.next = p2;
89+
size++;
90+
}
91+
92+
public Object removeFirst() {
93+
Node p = head;
94+
if (p.next != null) {
95+
Node p2 = head.next;
96+
p.next = p.next.next;
97+
size--;
98+
return p2.data;
99+
}
100+
return null;
101+
}
102+
103+
public Object removeLast() {
104+
Node p = head;
105+
if (p.next != null) {
106+
while (p.next.next != null) {
107+
p = p.next;
108+
}
109+
Node p2 = new Node();
110+
p2 = p.next;
111+
p.next = null;
112+
size--;
113+
return p2.data;
114+
}
115+
return null;
116+
}
117+
/*
118+
* public Iterator iterator(){ return null; }
119+
*/
120+
121+
private static class Node {
122+
Object data;
123+
Node next;
124+
}
125+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.coding.basic;
2+
3+
public interface MyList {
4+
public abstract void add(Object o);
5+
public abstract void add(int index, Object o);
6+
public abstract Object get(int index);
7+
public abstract Object remove(int index);
8+
public abstract int size();
9+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.coding.basic;
2+
3+
public class MyQueue {
4+
private int size;
5+
MyLinkedList mll = new MyLinkedList();
6+
public MyQueue() {
7+
}
8+
public void enQueue(Object o){
9+
mll.add(o);
10+
size++;
11+
}
12+
13+
public Object deQueue(){
14+
size--;
15+
return mll.removeFirst();
16+
}
17+
18+
public boolean isEmpty(){
19+
return size == 0;
20+
}
21+
22+
public int size(){
23+
return size;
24+
}
25+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.coding.basic;
2+
3+
public class MyStack {
4+
private MyArrayList elementData = new MyArrayList();
5+
6+
public void push(Object o) {
7+
elementData.add(o);
8+
}
9+
10+
public Object pop() {
11+
if (elementData.size() > 0) {
12+
Object data = elementData.get(elementData.size() - 1);
13+
elementData.remove(elementData.size() - 1);
14+
return data;
15+
}
16+
return null;
17+
}
18+
19+
public Object peek() {
20+
if (elementData.size() > 0) {
21+
return elementData.get(elementData.size() - 1);
22+
}
23+
return null;
24+
}
25+
26+
public boolean isEmpty() {
27+
return elementData.size() == 0;
28+
}
29+
30+
public int size() {
31+
return elementData.size();
32+
}
33+
}

0 commit comments

Comments
 (0)