forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 20
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 #1 from waking2017/master
work1
- Loading branch information
Showing
12 changed files
with
453 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>work1</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/441517454/work1/.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 |
106 changes: 106 additions & 0 deletions
106
group05/441517454/work1/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,106 @@ | ||
package com.coding.basic; | ||
|
||
public class ArrayList implements List { | ||
|
||
private int size = 0; | ||
|
||
private Object[] elementData = new Object[100]; | ||
|
||
public void add(Object o){ | ||
|
||
if(size<elementData.length) | ||
{elementData[size] = o; | ||
this.size++;} | ||
else{ | ||
elementData = grow(elementData,1); | ||
elementData[size] = o; | ||
this.size++; | ||
} | ||
|
||
|
||
} | ||
|
||
public void add(int index, Object o){ | ||
if(index<(this.size)&&this.size<elementData.length) | ||
{ | ||
for(int i=this.size;i>index;i--){ | ||
elementData[i]=elementData[i-1]; | ||
} | ||
elementData[index] = o; | ||
this.size++; | ||
} | ||
else if(index<(this.size)&&this.size==elementData.length) | ||
{ | ||
elementData = grow(elementData,1); | ||
elementData[index] = o; | ||
this.size++; | ||
} | ||
else{ | ||
System.out.println("index/>size¼ÓÈëʧ°Ü"); | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
public Object get(int index){ | ||
|
||
if(this.size>0&&index<(this.size)) | ||
return elementData[index]; | ||
else{ | ||
return null; | ||
} | ||
} | ||
|
||
public Object remove(int index){ | ||
|
||
if(this.size>0&&index<(this.size)) | ||
{ Object o= elementData[index]; | ||
for(int i=index;i<this.size;i++){ | ||
elementData[i]=elementData[i+1]; | ||
} | ||
this.size--; | ||
return o; | ||
|
||
} | ||
else{ | ||
return null; | ||
} | ||
} | ||
|
||
public int size(){ | ||
return this.size; | ||
} | ||
|
||
public Iterator iterator(){ | ||
return new ArrayListIterator(this); | ||
} | ||
|
||
private static Object[] grow (Object[]src,int size){ | ||
Object[] target = new Object[src.length+size]; | ||
System.arraycopy(src, 0, target, 0, src.length); | ||
return target; | ||
} | ||
private class ArrayListIterator implements Iterator{ | ||
private ArrayList arrayList; | ||
private int pos = 0; | ||
public ArrayListIterator(ArrayList arrayList) { | ||
this.arrayList =arrayList; | ||
|
||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
pos++; | ||
if(pos>arrayList.size){ | ||
return false; | ||
}else | ||
return true; | ||
} | ||
|
||
@Override | ||
public Object next() { | ||
|
||
return arrayList.get(pos-1); | ||
}} | ||
} |
32 changes: 32 additions & 0 deletions
32
group05/441517454/work1/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(); | ||
|
||
} |
156 changes: 156 additions & 0 deletions
156
group05/441517454/work1/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,156 @@ | ||
package com.coding.basic; | ||
|
||
|
||
|
||
public class LinkedList implements List { | ||
|
||
private Node head; | ||
private Node body; | ||
//private Node body1; | ||
private int size = 0; | ||
|
||
|
||
public void add(Object o){ | ||
if(null == head){ | ||
head = new Node(); | ||
head.data = o; | ||
head.next = null; | ||
size++; | ||
} | ||
// else if(head.next == null){ | ||
// | ||
// head.next =new Node(); | ||
// head.next.data = o; | ||
// head.next.next = null; | ||
// body=head.next; | ||
// size++; | ||
// } | ||
else { | ||
body=head; | ||
while(!(body.next ==null)) | ||
{body =body.next;} | ||
body.next =new Node(); | ||
body.next.data =o; | ||
body.next.next =null; | ||
size++; | ||
} | ||
|
||
|
||
} | ||
public void add(int index , Object o){ | ||
|
||
} | ||
public Object get(int index){ | ||
if (index<size) | ||
{body=head; | ||
for (int i=0;i<index;i++) | ||
{ | ||
body =body.next; | ||
} | ||
return body.data; | ||
}else return null; | ||
|
||
} | ||
public Object remove(int index){ | ||
if (index<size&&index>1) | ||
{body=head; | ||
for (int i=0;i<index-1;i++) | ||
{ | ||
body =body.next; | ||
} | ||
body.next=body.next.next; | ||
size--; | ||
return body.next.data; | ||
}else return null; | ||
|
||
} | ||
|
||
public int size(){ | ||
return this.size; | ||
} | ||
|
||
public void addFirst(Object o){ | ||
if(null == head){ | ||
head = new Node(); | ||
head.data = o; | ||
head.next = null; | ||
size++; | ||
}else { | ||
body =new Node(); | ||
body.data = o; | ||
body.next = head; | ||
head=body; | ||
size++; | ||
} | ||
} | ||
public void addLast(Object o){ | ||
if(!(head==null)) | ||
{ | ||
body=head; | ||
while(!(body.next ==null)) | ||
{body =body.next;} | ||
body.next =new Node(); | ||
body.next.data =o; | ||
body.next.next =body.next; | ||
size++; | ||
}else | ||
System.out.println("ÇëÏȽ¨Á¢Í·½áµã"); | ||
|
||
} | ||
public Object removeFirst(){ | ||
if(!(head==null)) | ||
{ | ||
body=head; | ||
head =head.next; | ||
size--; | ||
return body.data; | ||
}else | ||
|
||
return null; | ||
} | ||
public Object removeLast(){ | ||
if (!(head==null)) | ||
{body=head; | ||
for (int i=0;i<size-2;i++) | ||
{ | ||
body =body.next; | ||
} | ||
body.next=body.next; | ||
size--; | ||
return body.next.data; | ||
}else return null; | ||
|
||
} | ||
public Iterator iterator(){ | ||
return new LinkedListIterator(this); | ||
} | ||
|
||
|
||
private static class Node{ | ||
Object data; | ||
Node next; | ||
|
||
} | ||
private class LinkedListIterator implements Iterator{ | ||
private LinkedList linkedList; | ||
private int pos = 0; | ||
public LinkedListIterator(LinkedList linkedList) { | ||
this.linkedList =linkedList; | ||
|
||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
pos++; | ||
if(pos>linkedList.size){ | ||
return false; | ||
}else | ||
return true; | ||
} | ||
|
||
@Override | ||
public Object next() { | ||
|
||
return linkedList.get(pos-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,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,30 @@ | ||
package com.coding.basic; | ||
|
||
public class Queue { | ||
private ArrayList elementData = new ArrayList(); | ||
public void enQueue(Object o){ | ||
elementData.add(o); | ||
} | ||
|
||
public Object deQueue(){ | ||
|
||
if(elementData.size()>0) | ||
|
||
{ | ||
elementData.remove(0); | ||
return elementData.remove(0); | ||
} | ||
else return null; | ||
} | ||
|
||
public boolean isEmpty(){ | ||
if(elementData.size()>0) | ||
return false; | ||
else return true; | ||
|
||
} | ||
|
||
public int size(){ | ||
return elementData.size(); | ||
} | ||
} |
Oops, something went wrong.