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 51075907/master
Master
- Loading branch information
Showing
8 changed files
with
263 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 exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre1.8.0_60"/> | ||
<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,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>HomeWork</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
group17/51075907/HomeWork/.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=disabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.4 | ||
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=warning | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning | ||
org.eclipse.jdt.core.compiler.source=1.3 |
75 changes: 75 additions & 0 deletions
75
group17/51075907/HomeWork/src/day1_HomeWork/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,75 @@ | ||
package day1_HomeWork; | ||
|
||
|
||
public class ArrayList implements List { | ||
|
||
private int size = 0; | ||
|
||
private Object[] elementData = new Object[100]; | ||
|
||
//如果数组空间超过当前大小,保证容量 | ||
public void ensureCapacity( int newCapacity) | ||
{ | ||
if ( newCapacity < size) | ||
return; | ||
|
||
Object [] old =elementData; | ||
elementData =(Object []) new Object[newCapacity]; | ||
for (int i=0; i<size(); i++ ) | ||
elementData[i] =old[i]; | ||
} | ||
|
||
public void add(Object o){ | ||
add(size(),o); | ||
return; | ||
} | ||
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 Object get(int index){ | ||
if ( index<0 || index >=size()) | ||
throw new ArrayIndexOutOfBoundsException(); | ||
return elementData[index]; | ||
} | ||
|
||
public Object remove(int index){ | ||
Object remove_elementData=elementData[index]; | ||
for ( int i=index;i<size()-1;i++) | ||
elementData[i]= elementData[i+1]; | ||
size --; | ||
return remove_elementData; | ||
} | ||
|
||
public int size(){ | ||
return size; | ||
} | ||
|
||
public java.util.Iterator iterator(){ | ||
return null; | ||
} | ||
|
||
private class ArrayListIterator implements java.util.Iterator | ||
{ | ||
private int current =0; | ||
|
||
public boolean hasNext() | ||
{ | ||
return current <size(); | ||
} | ||
|
||
public Object next() | ||
{ | ||
if (!hasNext()) | ||
throw new java.util.NoSuchElementException(); | ||
return elementData[current++]; | ||
} | ||
} | ||
|
||
} |
103 changes: 103 additions & 0 deletions
103
group17/51075907/HomeWork/src/day1_HomeWork/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,103 @@ | ||
package day1_HomeWork; | ||
|
||
|
||
public class LinkedList implements List { | ||
|
||
private Node head; | ||
|
||
private int size = 0; | ||
|
||
private int modCount = 0; | ||
|
||
public void add(Object o){ | ||
add( size(),o); | ||
return true; | ||
} | ||
public void add(int index , Object o){ | ||
|
||
} | ||
public Object get(int index){ | ||
Node p; | ||
if ( index <0||index> size()) | ||
throw new IndexOutOfBoundsException(); | ||
|
||
if (index < size()/2) | ||
{ | ||
p=beginMarker.next; | ||
for (int i =0;i<index;i++) | ||
p=p.next; | ||
} | ||
else | ||
{ | ||
p=endMarker; | ||
for (int i=size();i>index;i--) | ||
p=p.prev; | ||
} | ||
return p; | ||
} | ||
public Object remove(Node p){ | ||
p.next.prev =p.prev; | ||
p.prev.next=p.next; | ||
int size; | ||
size--; | ||
int modCount; | ||
modCount++; | ||
return p.data; | ||
} | ||
|
||
public int size(){ | ||
return -1; | ||
} | ||
|
||
public void addFirst(Node p,Object o){ | ||
Node newNode= new Node (o,p.prev,p); | ||
newNode.prev.next= newNode; | ||
p.prev =newNode; | ||
size++; | ||
modCount++; | ||
} | ||
public void addLast(Object o){ | ||
|
||
} | ||
public Object removeFirst(int index){ | ||
return remove( get(index)); | ||
} | ||
public Object removeLast(){ | ||
return null; | ||
} | ||
public java.util.Iterator iterator(){ | ||
return new LinkedListIterator(); | ||
} | ||
|
||
private class LinkedListIterator implements java.util.Iterator{ | ||
private Node current=beginMarker.next; | ||
private int expectedModCount=modCount; | ||
private boolean okTORemove=false; | ||
|
||
public boolean haNext() | ||
{ | ||
return current!= endMarker; | ||
} | ||
public Object next() | ||
{ | ||
if (modCount !=expectedModCount) | ||
throw new java.util.ConcurrentModificationException(); | ||
if (!=hasNext()) | ||
throw new java.util.NoSuchElementException(); | ||
|
||
|
||
} | ||
} | ||
|
||
|
||
private static class Node{ | ||
public Node(Object o, Node p, Node n) | ||
{ | ||
data =o; next=n; prev=p; | ||
} | ||
public Object data; | ||
public Node next; | ||
public Node prev; | ||
|
||
} | ||
} |
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 day1_HomeWork; | ||
|
||
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,19 @@ | ||
package day1_HomeWork; | ||
|
||
public class Queue { | ||
|
||
public void enQueue(Object o){ | ||
} | ||
|
||
public Object deQueue(){ | ||
return null; | ||
} | ||
|
||
public boolean isEmpty(){ | ||
return false; | ||
} | ||
|
||
public int size(){ | ||
return -1; | ||
} | ||
} |
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 day1_HomeWork; | ||
|
||
|
||
public class Stack { | ||
private ArrayList elementData = new ArrayList(); | ||
|
||
public void push(Object o){ | ||
} | ||
|
||
public Object pop(){ | ||
return null; | ||
} | ||
|
||
public Object peek(){ | ||
return null; | ||
} | ||
public boolean isEmpty(){ | ||
return false; | ||
} | ||
public int size(){ | ||
return -1; | ||
} | ||
} |