forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 15
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 #12 from xqfGit/master
dataStructure
- Loading branch information
Showing
10 changed files
with
333 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"/> | ||
<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>xqfGit</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,73 @@ | ||
package xqfGit.dataStructure; | ||
|
||
import java.util.Arrays; | ||
|
||
public class ArrayList implements List { | ||
|
||
private int size = 0; | ||
|
||
private Object[] elementData = new Object[100]; | ||
|
||
|
||
public void add(Object o){ | ||
if(this.size >= elementData.length){ | ||
elementData = Arrays.copyOf(elementData, size+1); | ||
elementData[size] = o; | ||
size++; | ||
} | ||
else{ | ||
elementData[size-1] = o; | ||
size++; | ||
} | ||
|
||
} | ||
|
||
public void add(int index, Object o){ | ||
if(index<0 || index>elementData.length){ | ||
throw new ArrayIndexOutOfBoundsException("OutOfBounds"); | ||
} | ||
else{ | ||
System.arraycopy(elementData, index, elementData, index+1, elementData.length+1); | ||
elementData[index] = o; | ||
size++; | ||
} | ||
} | ||
|
||
|
||
public Object get(int index){ | ||
if(index<0 || index>elementData.length){ | ||
throw new ArrayIndexOutOfBoundsException("OutOfBounds"); | ||
} | ||
else{ | ||
return elementData[index]; | ||
} | ||
} | ||
|
||
|
||
public Object remove(int index){ | ||
if(index<0 || index>elementData.length){ | ||
throw new ArrayIndexOutOfBoundsException("OutOfBounds"); | ||
} | ||
else{ | ||
Object reObject = elementData[index]; | ||
System.arraycopy(elementData, index+1, elementData, index, elementData.length-1); | ||
size--; | ||
return reObject; | ||
} | ||
} | ||
|
||
public int size(){ | ||
if(this.size < elementData.length){ | ||
return size; | ||
}else{ | ||
elementData = Arrays.copyOf(elementData, size); | ||
return size; | ||
} | ||
} | ||
|
||
|
||
public Iterator iterator(){ | ||
return null; | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
group01/360176196/src/xqfGit/dataStructure/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,49 @@ | ||
package xqfGit.dataStructure; | ||
|
||
import com.sun.swing.internal.plaf.basic.resources.basic; | ||
|
||
public class BinaryTreeNode { | ||
|
||
private Integer data; | ||
private BinaryTreeNode left; | ||
private BinaryTreeNode right; | ||
|
||
|
||
|
||
|
||
public Integer getData() { | ||
return data; | ||
} | ||
public void setData(Integer 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(Integer i){ | ||
|
||
return null; | ||
} | ||
|
||
public BinaryTreeNode (){ | ||
|
||
} | ||
|
||
|
||
|
||
public BinaryTreeNode(BinaryTreeNode b1,BinaryTreeNode b2){ | ||
this.left = b1; | ||
this.right = b2; | ||
} | ||
|
||
} |
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 xqfGit.dataStructure; | ||
|
||
public interface Iterator { | ||
public boolean hasNext(); | ||
public Object next(); | ||
|
||
} |
116 changes: 116 additions & 0 deletions
116
group01/360176196/src/xqfGit/dataStructure/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,116 @@ | ||
package xqfGit.dataStructure; | ||
|
||
public class LinkedList implements List { | ||
|
||
private Node first; | ||
private Node last; | ||
private int size; | ||
|
||
public void add(Object o){ | ||
Node l = new Node(o); | ||
l = last.next; | ||
size++; | ||
} | ||
|
||
public void add(int index , Object o){ | ||
Node l = new Node(o); | ||
Node n = first; | ||
if(size == index){ | ||
l = last.next; | ||
l = last; | ||
size++; | ||
}else{ | ||
Node m = first; | ||
for(int i =0;i<index-1;i++){ | ||
m = m.next; | ||
} | ||
for(int i =0;i<index;i++){ | ||
n = n.next; | ||
} | ||
l = m.next; | ||
n = l.next; | ||
size++; | ||
} | ||
} | ||
public Object get(int index){ | ||
Node n = first; | ||
for(int i =0;i<index;i++){ | ||
n = n.next; | ||
} | ||
return n; | ||
} | ||
public Object remove(int index){ | ||
Node n = first; | ||
for(int i =0;i<index-1;i++){ | ||
n = n.next; | ||
} | ||
Node m = first; | ||
for(int i =0;i<index;i++){ | ||
m = m.next; | ||
} | ||
Node l = first; | ||
for(int i =0;i<index+1;i++){ | ||
l = l.next; | ||
} | ||
l = n.next; | ||
size--; | ||
return m; | ||
} | ||
|
||
public int size(){ | ||
Node n = first; | ||
int i=0; | ||
for(i =0;i<size;i++){ | ||
n = n.next; | ||
} | ||
return i; | ||
} | ||
|
||
public void addFirst(Object o){ | ||
Node n = new Node(o); | ||
first = n.next; | ||
size++; | ||
} | ||
public void addLast(Object o){ | ||
Node n = first; | ||
for(int i =0;i<size;i++){ | ||
n = n.next; | ||
} | ||
n = new Node(o); | ||
last = n; | ||
size++; | ||
} | ||
public Object removeFirst(){ | ||
Node n = first.next; | ||
Node m = first; | ||
first = n; | ||
size--; | ||
return m; | ||
} | ||
public Object removeLast(){ | ||
Node n = first; | ||
for(int i =0;i<size-1;i++){ | ||
n = n.next; | ||
} | ||
last = n; | ||
size--; | ||
return n.next; | ||
} | ||
|
||
public Iterator iterator(){ | ||
return null; | ||
} | ||
|
||
|
||
private static class Node{ | ||
Object data; | ||
Node next; | ||
|
||
public Node(){ | ||
|
||
} | ||
public Node(Object o ){ | ||
this.data = o; | ||
} | ||
} | ||
} |
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 xqfGit.dataStructure; | ||
|
||
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,27 @@ | ||
package xqfGit.dataStructure; | ||
import java.util.LinkedList; | ||
|
||
public class Queue { | ||
LinkedList list = new LinkedList(); | ||
|
||
public void enQueue(Object o){ | ||
list.addLast(o); | ||
} | ||
|
||
public Object deQueue(){ | ||
Object o =list.getFirst(); | ||
list.removeFirst(); | ||
return o; | ||
} | ||
|
||
public boolean isEmpty(){ | ||
if(list.size() == 0){ | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public int size(){ | ||
return list.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,28 @@ | ||
package xqfGit.dataStructure; | ||
|
||
public class Stack { | ||
private ArrayList elementData = new ArrayList(); | ||
|
||
public void push(Object o){ | ||
elementData.add(o); | ||
} | ||
|
||
public Object pop(){ | ||
Object o = elementData.get(elementData.size()-1); | ||
elementData.remove(elementData.size()-1); | ||
return o; | ||
} | ||
|
||
public Object peek(){ | ||
return elementData.get(elementData.size()-1); | ||
} | ||
public boolean isEmpty(){ | ||
if(elementData.size() == 0){ | ||
return true; | ||
} | ||
return false; | ||
} | ||
public int size(){ | ||
return elementData.size(); | ||
} | ||
} |