forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 8
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 #5 from Leon1900/master
Task01
- Loading branch information
Showing
13 changed files
with
346 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,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>RemoteSystemsTempFiles</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.rse.ui.remoteSystemsTempNature</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,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.8"/> | ||
<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>Task01</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> |
11 changes: 11 additions & 0 deletions
11
group05/515505513/Task01/.settings/org.eclipse.jdt.core.prefs
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.8 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.8 | ||
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.8 |
78 changes: 78 additions & 0 deletions
78
group05/515505513/Task01/src/com/coding/basic/ArrayList.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,78 @@ | ||
package com.coding.basic; | ||
|
||
import java.util.NoSuchElementException; | ||
|
||
public class ArrayList implements List { | ||
|
||
|
||
private int size = 0; | ||
private static final int DEFAULT_SIZE = 100; | ||
private Object[] elementData = new Object[DEFAULT_SIZE]; | ||
|
||
//添加元素 | ||
public void add(Object o){ | ||
add(size(),o); | ||
} | ||
|
||
|
||
public void add(int index, Object o){ | ||
if(elementData.length==size()){ | ||
ensureCapacity(size()*2 + 1); | ||
} | ||
for (int i = size; i > index; i--) | ||
elementData[i]=elementData[i-1]; | ||
elementData[index] = o; | ||
size++; | ||
} | ||
//扩容 | ||
public void ensureCapacity(int newCapacity){ | ||
if(newCapacity < size){ | ||
return; | ||
} | ||
Object[] oldElements = elementData; | ||
elementData = new Object[newCapacity]; | ||
for (int i = 0; i < size; i++) { | ||
elementData[i] = oldElements[i]; | ||
} | ||
} | ||
//返回固定下标的元素 | ||
public Object get(int index){ | ||
if(index<0 || index >=size){ | ||
throw new ArrayIndexOutOfBoundsException("指定的index超过界限"); | ||
} | ||
return elementData[index]; | ||
} | ||
//删除指定位置的元素 | ||
public Object remove(int index){ | ||
Object removeElement = elementData[index]; | ||
for (int i = index; i < size; i++) { | ||
elementData[i] = elementData[i+1]; | ||
} | ||
size--; | ||
return removeElement; | ||
} | ||
|
||
public int size(){ | ||
return size; | ||
} | ||
|
||
public Iterator iterator(){ | ||
return new ArrayListIterator(); | ||
} | ||
|
||
private class ArrayListIterator implements Iterator{ | ||
private int current = 0; | ||
@Override | ||
public boolean hasNext() { | ||
return current < size; | ||
} | ||
@Override | ||
public Object next() { | ||
if(!hasNext()){ | ||
throw new NoSuchElementException(); | ||
} | ||
return elementData[current+1]; | ||
} | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
group05/515505513/Task01/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,7 @@ | ||
package com.coding.basic; | ||
|
||
public interface Iterator { | ||
public boolean hasNext(); | ||
public Object next(); | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
group05/515505513/Task01/src/com/coding/basic/LinkedList.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,48 @@ | ||
package com.coding.basic; | ||
|
||
public class LinkedList implements List { | ||
|
||
private Node head;//指针 | ||
private Object element;//元素 | ||
//添加一个元素 | ||
public void add(Object o){ | ||
|
||
} | ||
//在index处添加一个元素 | ||
public void add(int index , Object o){ | ||
|
||
} | ||
|
||
public Object get(int index){ | ||
return null; | ||
} | ||
//清除一个元素 | ||
public Object remove(int index){ | ||
return null; | ||
} | ||
|
||
public int size(){ | ||
return -1; | ||
} | ||
|
||
public void addFirst(Object o){ | ||
|
||
} | ||
public void addLast(Object o){ | ||
|
||
} | ||
public Object removeFirst(){ | ||
return null; | ||
} | ||
public Object removeLast(){ | ||
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 List { | ||
public void add(Object o); | ||
public void add(int index, Object o); | ||
public Object get(int index); | ||
public Object remove(int index); | ||
public 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,49 @@ | ||
package com.coding.basic; | ||
|
||
public class Queue { | ||
private int maxSize;//队列容量 | ||
private Object[] queue;//队列 | ||
private int head;//队列头,可以删除 | ||
private int tail;//队列尾,可以插入 | ||
|
||
|
||
public Queue() { | ||
this(10); | ||
} | ||
|
||
public Queue(int maxSize) { | ||
if(maxSize >=0){ | ||
this.maxSize = maxSize; | ||
this.queue = new Object[maxSize]; | ||
head = tail = 0; | ||
}else { | ||
throw new RuntimeException("初始化大小不能小于0"); | ||
} | ||
} | ||
|
||
public void enQueue(Object o){ | ||
if(tail == maxSize){ | ||
throw new RuntimeException("队列已满,无法插入新的元素!"); | ||
}else { | ||
queue[tail++] = o; | ||
} | ||
} | ||
|
||
public Object deQueue(){ | ||
if(isEmpty()){ | ||
throw new RuntimeException("空队列异常!"); | ||
}else { | ||
Object value = queue[head]; | ||
queue[head++] = null; | ||
return value; | ||
} | ||
} | ||
//队列是否为空 | ||
public boolean isEmpty(){ | ||
return head==tail?true:false; | ||
} | ||
|
||
public int size(){ | ||
return tail-head; | ||
} | ||
} |
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,49 @@ | ||
package com.coding.basic; | ||
|
||
public class Stack { | ||
private Object[] data; | ||
private int capacity; | ||
private int size; | ||
public Stack(){ | ||
capacity = 16; | ||
size = 0; | ||
data = new Object[capacity]; | ||
} | ||
public void push(Object o){ | ||
if(size < capacity){ | ||
data[size++] = o; | ||
}else { | ||
ensureCapacity(); | ||
data[size++] = o; | ||
} | ||
} | ||
|
||
private void ensureCapacity() { | ||
capacity = capacity*2; | ||
} | ||
public Object pop(){ | ||
if(size > 0){ | ||
System.out.println(data[size-1]); | ||
//data[size--] = null; | ||
}else { | ||
System.out.println("Empty stack"); | ||
} | ||
size--; | ||
return data[size]; | ||
} | ||
|
||
public Object peek(){ | ||
if(size>0){ | ||
return data[size-1]; | ||
}else { | ||
return null; | ||
} | ||
} | ||
public boolean isEmpty(){ | ||
|
||
return size==0; | ||
} | ||
public int size(){ | ||
return size; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
group05/515505513/Task01/src/com/coding/basic/TestExample.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,27 @@ | ||
package com.coding.basic; | ||
|
||
public class TestExample { | ||
|
||
public static void main(String[] args) { | ||
/*Stack mystack = new Stack(); | ||
for (int i = 0; i < 10; i++) { | ||
mystack.push(i); | ||
} | ||
for (int i = 0; i < 10; i++) { | ||
mystack.pop(); | ||
System.out.println("==="+mystack.peek()); | ||
}*/ | ||
|
||
/*Test Queue | ||
Queue myQqueue = new Queue(10); | ||
for (int i = 0; i < 10; i++) { | ||
myQqueue.enQueue(i); | ||
} | ||
for (int i = 0; i < 10; i++) { | ||
System.out.println(myQqueue.deQueue()); | ||
}*/ | ||
|
||
|
||
} | ||
|
||
} |