forked from diliuzuzhanghao/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 0
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 diliuzuzhanghao#20 from dfjhde/master
第一周作业
- Loading branch information
Showing
10 changed files
with
325 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>1664823950</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 com.coding.basic; | ||
|
||
public class ArrayList implements List | ||
{ | ||
|
||
private int size = 0; | ||
|
||
|
||
private Object[] elementData = new Object[100]; | ||
|
||
public void add(Object o) | ||
{ | ||
elementData[size] = o; | ||
size ++; | ||
} | ||
|
||
public void add(int index, Object o) | ||
{ | ||
if(index > size || index < 0) | ||
{ | ||
return; | ||
} | ||
else | ||
{ | ||
for (int i = size-1; i > index; i--) | ||
{ | ||
elementData[i+1] = elementData[size]; | ||
} | ||
elementData[index] = o; | ||
size++; | ||
} | ||
|
||
} | ||
|
||
public Object get(int index) | ||
{ | ||
if(index < size || index >= 0) | ||
{ | ||
return elementData[index]; | ||
} | ||
return null; | ||
} | ||
|
||
public Object remove(int index) | ||
{ | ||
Object removedObj; | ||
if(index >= size || index < 0) | ||
{ | ||
removedObj = null; | ||
} | ||
else | ||
{ | ||
removedObj = elementData[index]; | ||
for (int j = index; j < elementData.length; j++) | ||
{ | ||
elementData[j] = elementData[j+1]; | ||
} | ||
size--; | ||
} | ||
return removedObj; | ||
} | ||
|
||
public int size() | ||
{ | ||
return size; | ||
} | ||
|
||
public Iterator iterator() | ||
{ | ||
return null; | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
group01/1664823950/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,45 @@ | ||
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,8 @@ | ||
package com.coding.basic; | ||
|
||
public interface Iterator | ||
{ | ||
public boolean hasNext(); | ||
public Object next(); | ||
|
||
} |
108 changes: 108 additions & 0 deletions
108
group01/1664823950/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,108 @@ | ||
package com.coding.basic; | ||
|
||
public class LinkedList implements List | ||
{ | ||
|
||
private Node head; | ||
private Node tail; | ||
|
||
public void add(Object o) | ||
{ | ||
Node n = new Node(o); | ||
tail.next = n; | ||
tail = n; | ||
} | ||
|
||
public void add(int index , Object o) | ||
{ | ||
Node n = new Node(o); | ||
getNode(index-1).next = n; | ||
n.next = getNode(index); | ||
} | ||
|
||
private Node getNode(int index) | ||
{ | ||
Node n = head; | ||
int counter = 0; | ||
while (counter <index) | ||
{ | ||
counter++; | ||
n = n.next; | ||
} | ||
return n; | ||
} | ||
|
||
public Object get(int index) | ||
{ | ||
return getNode(index).data; | ||
} | ||
|
||
public Object remove(int index) | ||
{ | ||
Object o = getNode(index).data; | ||
getNode(index-1).next = getNode(index+1); | ||
return o; | ||
} | ||
|
||
public int size() | ||
{ | ||
Node n = head; | ||
int counter = 0; | ||
while (n.next != tail) | ||
{ | ||
counter++; | ||
n = n.next; | ||
} | ||
counter++; | ||
return counter; | ||
} | ||
|
||
public void addFirst(Object o) | ||
{ | ||
Node n = new Node(o); | ||
n.next = head; | ||
head = n; | ||
} | ||
|
||
public void addLast(Object o) | ||
{ | ||
add(o); | ||
} | ||
|
||
public Object removeFirst() | ||
{ | ||
Object o = head.data; | ||
head = head.next; | ||
return o; | ||
} | ||
|
||
public Object removeLast() | ||
{ | ||
Object o = tail.data; | ||
Node n = head; | ||
while (n.next != tail) | ||
{ | ||
n = n.next; | ||
} | ||
tail = n; | ||
return o; | ||
} | ||
|
||
|
||
public Iterator iterator() | ||
{ | ||
return null; | ||
} | ||
|
||
|
||
private static class Node | ||
{ | ||
Object data; | ||
Node next; | ||
|
||
public Node(Object data) | ||
{ | ||
this.data = data; | ||
} | ||
} | ||
} |
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,10 @@ | ||
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,26 @@ | ||
package com.coding.basic; | ||
|
||
public class Queue | ||
{ | ||
private LinkedList elementData = new LinkedList(); | ||
|
||
public void enQueue(Object o) | ||
{ | ||
elementData.addLast(o); | ||
} | ||
|
||
public Object deQueue() | ||
{ | ||
return elementData.removeFirst(); | ||
} | ||
|
||
public boolean isEmpty() | ||
{ | ||
return elementData.size() == 0; | ||
} | ||
|
||
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,31 @@ | ||
package com.coding.basic; | ||
|
||
public class Stack | ||
{ | ||
private LinkedList elementData = new LinkedList(); | ||
|
||
public void push(Object o) | ||
{ | ||
elementData.addLast(o); | ||
} | ||
|
||
public Object pop() | ||
{ | ||
return elementData.removeLast(); | ||
} | ||
|
||
public Object peek() | ||
{ | ||
return elementData.get(elementData.size()); | ||
} | ||
|
||
public boolean isEmpty() | ||
{ | ||
return elementData.size() == 0; | ||
} | ||
|
||
public int size() | ||
{ | ||
return elementData.size(); | ||
} | ||
} |