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 #14 from fengyuxia/master
Signed-off-by: fengyuxia <[email protected]>
- Loading branch information
Showing
13 changed files
with
441 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,7 @@ | ||
<?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/J2SE-1.5"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> | ||
<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>2017Learning</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.5 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.5 | ||
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.5 |
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,85 @@ | ||
package com.coding.basic; | ||
|
||
public class ArrayList implements List { | ||
|
||
private int size = 0; | ||
private int length = 1; | ||
|
||
private Object[] elementData = new Object[length]; | ||
|
||
public void add(Object o){ | ||
System.out.println("进行add方法"); | ||
capacity(size+1); | ||
System.out.println(elementData.length); | ||
elementData[size++] = o; | ||
//size++; | ||
} | ||
public void add(int index, Object o){ | ||
capacity(size+1); | ||
System.arraycopy(elementData, index, elementData, index+1, size-index); | ||
elementData[index] = o ; | ||
} | ||
|
||
public Object get(int index){ | ||
System.out.println("进行get方法"); | ||
return elementData[index]; | ||
} | ||
|
||
public Object remove(int index){ | ||
System.out.println("进行remove方法"); | ||
if(index>size){ | ||
return elementData; | ||
} | ||
System.arraycopy(elementData, index+1, elementData, index, size-index-1); | ||
elementData[--size]=null; | ||
System.out.println(size); | ||
return elementData; | ||
} | ||
|
||
public int size(){ | ||
return this.size; | ||
} | ||
|
||
public Iterator iterator(){ | ||
return new Iterarorimp(this.elementData); | ||
} | ||
|
||
public class Iterarorimp implements Iterator{ | ||
|
||
int index; | ||
Object[] data = null; | ||
|
||
public Iterarorimp(Object[] data){ | ||
this.data = data; | ||
} | ||
|
||
|
||
public boolean hasNext() { | ||
if(index>=data.length){ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
|
||
public Object next() { | ||
|
||
return this.data[index++]; | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
|
||
public void capacity(int newlength) { | ||
System.out.println("进行扩容方法"); | ||
if(newlength>length){ | ||
Object[] newelementData = new Object[length*2]; | ||
System.arraycopy(elementData, 0, newelementData, 0, size); | ||
this.elementData = newelementData; | ||
length = length*2; | ||
} | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
group04/474772605/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,22 @@ | ||
package com.coding.basic; | ||
|
||
public class Dinkedlist { | ||
public static void main(String[] args) { | ||
LinkedList linkedlist = new LinkedList(); | ||
String o = "1234"; | ||
String a = "aaaaaaaa"; | ||
String v = "vvvvvvvv"; | ||
linkedlist.add(o); | ||
linkedlist.add(1,a); | ||
linkedlist.add(2,v); | ||
linkedlist.removeLast(); | ||
for(int i =0 ; i<linkedlist.size();i++){ | ||
System.out.println(linkedlist.get(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,7 @@ | ||
package com.coding.basic; | ||
|
||
public interface Iterator { | ||
public boolean hasNext(); | ||
public Object 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,155 @@ | ||
package com.coding.basic; | ||
|
||
public class LinkedList implements List { | ||
|
||
private Node head; | ||
private Node last; | ||
private int size =0; | ||
|
||
public void add(Object o){ | ||
|
||
if(head == null){ | ||
head = new Node(); | ||
last = new Node(); | ||
head.data=o; | ||
last = head; | ||
|
||
}else{ | ||
Node node = new Node(); | ||
node.data = o; | ||
last.next = node; | ||
last = node; | ||
} | ||
size++; | ||
} | ||
public void add(int index , Object o){ | ||
if(index == 0){ | ||
addFirst(o); | ||
} | ||
|
||
if(size >index){ | ||
Node newnode = new Node(); | ||
newnode.data = o; | ||
Node nodefirst = new Node(); | ||
Node nodelast = new Node(); | ||
int amount =1; | ||
Node first = head; | ||
while(first.next !=null){ | ||
if(amount+1 == index){ | ||
nodefirst.next = newnode; | ||
nodelast = first.next; | ||
newnode.next = nodelast; | ||
size++; | ||
} | ||
first = first.next; | ||
amount++; | ||
} | ||
} | ||
if(size==index){ | ||
|
||
Node node = new Node(); | ||
node.data = o; | ||
last.next =node; | ||
last = node; | ||
size++; | ||
|
||
} | ||
} | ||
public Object get(int index){ | ||
int amount = 0; | ||
Node newnode = head; | ||
while(newnode.next !=null){ | ||
if(amount==index){ | ||
return newnode.data; | ||
} | ||
amount++; | ||
newnode = newnode.next; | ||
} | ||
return newnode.data; | ||
} | ||
public Object remove(int index){ | ||
|
||
if(index ==0){ | ||
removeFirst(); | ||
} | ||
int amount =0; | ||
Node first = head; | ||
Node remove = new Node(); | ||
while(first.next!=null){ | ||
if(amount+1==index){ | ||
remove = first.next; | ||
first.next = remove.next; | ||
size--; | ||
return remove.data; | ||
} | ||
first = first.next; | ||
amount++; | ||
} | ||
return null; | ||
} | ||
|
||
public int size(){ | ||
return this.size; | ||
} | ||
|
||
public void addFirst(Object o){ | ||
Node newhead =new Node(); | ||
newhead.data=o; | ||
newhead.next = head; | ||
head = newhead; | ||
size++; | ||
|
||
} | ||
public void addLast(Object o){ | ||
add(o); | ||
|
||
} | ||
public Object removeFirst(){ | ||
Object removedata = new Object(); | ||
removedata = head.data; | ||
head = head.next; | ||
size--; | ||
return removedata; | ||
|
||
} | ||
public Object removeLast(){ | ||
Node last = head; | ||
Node cache =new Node(); | ||
while(last.next !=null){ | ||
cache = last; | ||
last = last.next; | ||
} | ||
cache.next =null; | ||
size--; | ||
return last.data; | ||
|
||
} | ||
public Iterator iterator(){ | ||
return new Iteratorimp(this.head); | ||
} | ||
public class Iteratorimp implements Iterator{ | ||
Node newnode = new Node(); | ||
public Iteratorimp(Node node){ | ||
this.newnode = node; | ||
} | ||
|
||
public boolean hasNext() { | ||
if(newnode.next ==null){ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public Object next() { | ||
newnode = newnode.next; | ||
return newnode.data; | ||
} | ||
} | ||
|
||
|
||
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,42 @@ | ||
package com.coding.basic; | ||
|
||
import java.util.NoSuchElementException; | ||
|
||
public class Queue { | ||
Object[] elementData; | ||
int maxsize; | ||
int size =0; | ||
int head=0; | ||
int last=-1; | ||
public Queue(int i){ | ||
maxsize = i; | ||
elementData = new Object[maxsize]; | ||
} | ||
|
||
public void enQueue(Object o){ | ||
|
||
if(size == maxsize){ | ||
throw new IllegalStateException("Queue full"); | ||
} | ||
elementData[size++]=o; | ||
last=size; | ||
|
||
} | ||
|
||
public Object deQueue(){ | ||
|
||
return null; | ||
} | ||
|
||
public boolean isEmpty(){ | ||
if(this.size==0){ | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public int size(){ | ||
return this.size; | ||
} | ||
} |
Oops, something went wrong.