forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from core2for/master
my work
- Loading branch information
Showing
11 changed files
with
340 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>1787597051</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.7 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.7 |
32 changes: 32 additions & 0 deletions
32
group18/1787597051/src/com/coding/basic/BinaryTreeNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.coding.basic; | ||
|
||
public class BinaryTreeNode { | ||
|
||
private Object data; | ||
private BinaryTreeNode left; | ||
private BinaryTreeNode right; | ||
|
||
public Object getData() { | ||
return data; | ||
} | ||
public void setData(Object data) { | ||
this.data = data; | ||
} | ||
public BinaryTreeNode getLeft() { | ||
return left; | ||
} | ||
public void setLeft(BinaryTreeNode left) { | ||
this.left = left; | ||
} | ||
public BinaryTreeNode getRight() { | ||
return right; | ||
} | ||
public void setRight(BinaryTreeNode right) { | ||
this.right = right; | ||
} | ||
|
||
public BinaryTreeNode insert(Object o){ | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.coding.basic; | ||
|
||
import java.util.Arrays; | ||
|
||
public class MyArrayList implements MyList { | ||
private final int GROW = 4; | ||
private int size = 0; | ||
|
||
private Object[] elementData = new Object[4]; | ||
|
||
public void add(Object o) { | ||
if (size > elementData.length - 1) { | ||
elementData = Arrays.copyOf(elementData, elementData.length + GROW); | ||
elementData[size] = o; | ||
} else { | ||
elementData[size] = o; | ||
} | ||
size++; | ||
} | ||
|
||
public void add(int index, Object o) { | ||
Object[] target = new Object[elementData.length - index]; | ||
for (int x = index, y = 0; x < elementData.length; x++, y++) { | ||
target[y] = elementData[x]; | ||
} | ||
elementData = Arrays.copyOf(elementData, elementData.length + 1); | ||
size = index; | ||
// elementData[index] = o; | ||
elementData[size] = o; | ||
size++; | ||
for (int y = 0; y < target.length; y++) { | ||
// add(target[y]); | ||
elementData[size] = target[y]; | ||
size++; | ||
} | ||
} | ||
|
||
public Object get(int index) { | ||
return elementData[index]; | ||
} | ||
|
||
public Object remove(int index) { | ||
Object removeData = elementData[index]; | ||
elementData[index] = null; | ||
Object[] target = Arrays.copyOfRange(elementData, index + 1, elementData.length); | ||
for (int x = index, y = 0; y < target.length; y++, x++) { | ||
elementData[x] = target[y]; | ||
} | ||
size--; | ||
return removeData; | ||
} | ||
|
||
public int size() { | ||
return size; | ||
} | ||
|
||
public MyIteratorImpl iterator() { | ||
return new MyIteratorImpl(); | ||
} | ||
|
||
private class MyIteratorImpl implements MyIterator { | ||
int index; | ||
|
||
public boolean hasNext() { | ||
return index != size; | ||
} | ||
|
||
public Object next() { | ||
int i = index; | ||
index = i + 1; | ||
return elementData[i]; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.coding.basic; | ||
|
||
public interface MyIterator { | ||
public abstract boolean hasNext(); | ||
public abstract Object next(); | ||
} |
125 changes: 125 additions & 0 deletions
125
group18/1787597051/src/com/coding/basic/MyLinkedList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package com.coding.basic; | ||
|
||
public class MyLinkedList implements MyList { | ||
private int size; | ||
private Node head; | ||
|
||
public MyLinkedList() { | ||
head = new Node(); | ||
head.data = "͡˝áľă"; | ||
head.next = null; | ||
} | ||
|
||
public void add(Object o) { | ||
Node p = head; | ||
while (p.next != null) { | ||
p = p.next; | ||
} | ||
Node p3 = new Node(); | ||
p3.data = o; | ||
p.next = p3; | ||
size++; | ||
} | ||
|
||
public void add(int index, Object o) { | ||
int num = 0; | ||
Node p = head; | ||
while (p.next != null) { | ||
if (num == index) { | ||
Node p2 = new Node(); | ||
p2.data = o; | ||
p2.next = p.next; | ||
p.next = p2; | ||
size++; | ||
} | ||
p = p.next; | ||
num++; | ||
} | ||
} | ||
|
||
public Object get(int index) { | ||
int num = 0; | ||
Node p = head.next; | ||
while (p != null) { | ||
if (num == index) { | ||
return p.data; | ||
} | ||
p = p.next; | ||
num++; | ||
} | ||
return null; | ||
} | ||
|
||
public Object remove(int index) { | ||
int num = 0; | ||
Node p = head; | ||
while (p.next != null) { | ||
if (num == index) { | ||
Node p2 = p.next; | ||
p.next = p.next.next; | ||
size--; | ||
return p2.data; | ||
} | ||
p = p.next; | ||
num++; | ||
} | ||
return null; | ||
} | ||
|
||
public int size() { | ||
return size; | ||
} | ||
|
||
public void addFirst(Object o) { | ||
Node p = new Node(); | ||
p.data = o; | ||
p.next = head.next; | ||
head.next = p; | ||
size++; | ||
} | ||
|
||
public void addLast(Object o) { | ||
Node p = head; | ||
while (p.next != null) { | ||
p = p.next; | ||
} | ||
Node p2 = new Node(); | ||
p2.data = o; | ||
p.next = p2; | ||
size++; | ||
} | ||
|
||
public Object removeFirst() { | ||
Node p = head; | ||
if (p.next != null) { | ||
Node p2 = head.next; | ||
p.next = p.next.next; | ||
size--; | ||
return p2.data; | ||
} | ||
return null; | ||
} | ||
|
||
public Object removeLast() { | ||
Node p = head; | ||
if (p.next != null) { | ||
while (p.next.next != null) { | ||
p = p.next; | ||
} | ||
Node p2 = new Node(); | ||
p2 = p.next; | ||
p.next = null; | ||
size--; | ||
return p2.data; | ||
} | ||
return null; | ||
} | ||
/* | ||
* public Iterator iterator(){ return null; } | ||
*/ | ||
|
||
private static class Node { | ||
Object data; | ||
Node next; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.coding.basic; | ||
|
||
public interface MyList { | ||
public abstract void add(Object o); | ||
public abstract void add(int index, Object o); | ||
public abstract Object get(int index); | ||
public abstract Object remove(int index); | ||
public abstract int size(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.coding.basic; | ||
|
||
public class MyQueue { | ||
private int size; | ||
MyLinkedList mll = new MyLinkedList(); | ||
public MyQueue() { | ||
} | ||
public void enQueue(Object o){ | ||
mll.add(o); | ||
size++; | ||
} | ||
|
||
public Object deQueue(){ | ||
size--; | ||
return mll.removeFirst(); | ||
} | ||
|
||
public boolean isEmpty(){ | ||
return size == 0; | ||
} | ||
|
||
public int size(){ | ||
return size; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.coding.basic; | ||
|
||
public class MyStack { | ||
private MyArrayList elementData = new MyArrayList(); | ||
|
||
public void push(Object o) { | ||
elementData.add(o); | ||
} | ||
|
||
public Object pop() { | ||
if (elementData.size() > 0) { | ||
Object data = elementData.get(elementData.size() - 1); | ||
elementData.remove(elementData.size() - 1); | ||
return data; | ||
} | ||
return null; | ||
} | ||
|
||
public Object peek() { | ||
if (elementData.size() > 0) { | ||
return elementData.get(elementData.size() - 1); | ||
} | ||
return null; | ||
} | ||
|
||
public boolean isEmpty() { | ||
return elementData.size() == 0; | ||
} | ||
|
||
public int size() { | ||
return elementData.size(); | ||
} | ||
} |