forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 5
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 #11 from BansheeLW/master
1506作业(26号)
- Loading branch information
Showing
9 changed files
with
314 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.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>1506_1084478979</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
group15/1506_1084478979/1506_1084478979/.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 |
70 changes: 70 additions & 0 deletions
70
group15/1506_1084478979/1506_1084478979/src/banshee/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,70 @@ | ||
package banshee; | ||
|
||
import java.util.Arrays; | ||
public class ArrayList { | ||
|
||
private int size = 0; | ||
|
||
private Object[] elementData = new Object[100]; | ||
|
||
public void add(Object o){ | ||
ensureCapacity(size + 1); | ||
elementData[size++] = o; | ||
} | ||
public void add(int index, Object o){ | ||
rangeCheck(index); | ||
ensureCapacity(size+1); | ||
System.arraycopy(elementData, index, elementData, index + 1, | ||
size - index); | ||
elementData[index] = o; | ||
size++; | ||
} | ||
|
||
public Object get(int index){ | ||
rangeCheck(index); | ||
return elementData[index]; | ||
} | ||
|
||
public Object remove(int index){ | ||
rangeCheck(index); | ||
Object oldValue = elementData[index]; | ||
int numMoved = size - index - 1; | ||
if (numMoved > 0) | ||
System.arraycopy(elementData, index + 1, elementData, index, | ||
numMoved); | ||
elementData[--size] = null; | ||
return oldValue; | ||
} | ||
|
||
public int size(){ | ||
return -1; | ||
} | ||
|
||
public Iterator iterator(){ | ||
//TODO | ||
//不会。。。 | ||
return null; | ||
} | ||
|
||
|
||
private void rangeCheck( int index) { | ||
if (index >= size || index < 0){ | ||
throw new IndexOutOfBoundsException("指定的index超过界限"); | ||
} | ||
} | ||
|
||
|
||
public void ensureCapacity(int minCapacity) { | ||
int oldCapacity = elementData.length; | ||
if (minCapacity > oldCapacity) { | ||
//计算新的容量大小,为当前容量的1.5倍 | ||
int newCapacity = (oldCapacity * 3) / 2 + 1; | ||
if (newCapacity < minCapacity) | ||
newCapacity = minCapacity; | ||
elementData = Arrays.copyOf(elementData, newCapacity); | ||
} | ||
} | ||
|
||
} | ||
|
||
|
154 changes: 154 additions & 0 deletions
154
group15/1506_1084478979/1506_1084478979/src/banshee/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,154 @@ | ||
package banshee; | ||
|
||
import java.util.NoSuchElementException; | ||
|
||
public class LinkedList implements List { | ||
|
||
private Node head; | ||
private Node last; | ||
private int size = 0; | ||
|
||
public void add(Object o){ | ||
addAtLast(o); | ||
} | ||
public void add(int index , Object o){ | ||
rangeCheck(index); | ||
if (index == size) { | ||
addAtLast(o); | ||
}else{ | ||
linkBrfore(o, node(index)); | ||
} | ||
} | ||
public Object get(int index){ | ||
rangeCheck(index); | ||
return node(index); | ||
} | ||
public Object remove(int index){ | ||
Node e = node(index); | ||
remove(e); | ||
return null; | ||
} | ||
|
||
public int size(){ | ||
return size; | ||
} | ||
|
||
public void addFirst(Object o){ | ||
final Node h = head ; | ||
final Node newNode = new Node(null, o, h); | ||
if (h == null) { | ||
last = newNode; | ||
}else{ | ||
h.prev = newNode; | ||
} | ||
size++; | ||
} | ||
public void addLast(Object o){ | ||
addAtLast(o); | ||
} | ||
public Object removeFirst(){ | ||
final Node h = head; | ||
final Object e = h.data; | ||
Node next = h.next; | ||
h.data = null; | ||
h.next = null; | ||
head = next; | ||
if (next == null) | ||
last = null; | ||
else | ||
next.prev = null; | ||
size--; | ||
return e; | ||
} | ||
public Object removeLast(){ | ||
final Node l = last; | ||
final Object e = l.data; | ||
Node newL = l.prev; | ||
l.data = null; | ||
l.prev = null; | ||
last = newL; | ||
if (newL == null) | ||
head = null; | ||
else | ||
newL.next = null; | ||
size--; | ||
return e; | ||
} | ||
public Iterator iterator(){ | ||
//TODO | ||
//²»»á... | ||
return null; | ||
} | ||
|
||
|
||
private static class Node{ | ||
Object data; | ||
Node next; | ||
Node prev; | ||
|
||
Node(Node prev, Object element,Node next){ | ||
this.data = element ; | ||
this.next = next; | ||
this.prev = prev ; | ||
} | ||
} | ||
|
||
private void addAtLast(Object element){ | ||
Node l = last; | ||
Node newLink = new Node(l, element, null); | ||
last = newLink; | ||
if (l == null) { | ||
head = newLink; | ||
}else { | ||
l.next = newLink; | ||
} | ||
size++; | ||
} | ||
|
||
private void linkBrfore(Object element , Node spNode ){ | ||
final Node pred = spNode.prev; | ||
final Node newNode = new Node(pred, element, spNode); | ||
spNode.prev = newNode; | ||
if (pred == null) { | ||
head = newNode; | ||
}else{ | ||
pred.next = newNode; | ||
} | ||
size++; | ||
} | ||
|
||
private void rangeCheck(int index) { | ||
if (index > size || index < 0) { | ||
throw new IndexOutOfBoundsException("Ö¸¶¨µÄindex³¬¹ý½çÏÞ"); | ||
} | ||
} | ||
|
||
private Node node(int index) { | ||
if (index < (size >> 1)) { | ||
Node x = head; | ||
for (int i = 0; i < index; i++) | ||
x = x.next; | ||
return x; | ||
} else { | ||
Node x = last; | ||
for (int i = size - 1; i > index; i--) | ||
x = x.prev; | ||
return x; | ||
} | ||
} | ||
|
||
private Object remove(Node e) { | ||
if (e == head ) | ||
throw new NoSuchElementException(); | ||
Object result = e. data; | ||
e. prev.next = e.next; | ||
e. next.prev = e.prev; | ||
e. next = e.prev = null; | ||
e. data = null; | ||
size--; | ||
return result; | ||
} | ||
|
||
} | ||
|
||
|
20 changes: 20 additions & 0 deletions
20
group15/1506_1084478979/1506_1084478979/src/banshee/Queue.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,20 @@ | ||
package banshee; | ||
|
||
public class Queue { | ||
private LinkedList elementData = new LinkedList(); | ||
public void enQueue(Object o){ | ||
elementData.add(o); | ||
} | ||
|
||
public Object deQueue(){ | ||
return elementData.removeFirst(); | ||
} | ||
|
||
public boolean isEmpty(){ | ||
return elementData.size() == 0 ? true : false; | ||
} | ||
|
||
public int size(){ | ||
return elementData.size(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
group15/1506_1084478979/1506_1084478979/src/banshee/Stack.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,23 @@ | ||
package banshee; | ||
|
||
public class Stack { | ||
private ArrayList elementData = new ArrayList(); | ||
|
||
public void push(Object o){ | ||
elementData.add(o); | ||
} | ||
|
||
public Object pop(){ | ||
return elementData.remove(elementData.size() - 1); | ||
} | ||
|
||
public Object peek(){ | ||
return elementData.get(elementData.size()-1); | ||
} | ||
public boolean isEmpty(){ | ||
return elementData.size()==0?true:false; | ||
} | ||
public int size(){ | ||
return elementData.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,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> |