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 #8 from YouHmilyForProgramming/master
作业
- Loading branch information
Showing
8 changed files
with
286 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
group10/706097141/learning/src/com/hmily/learning/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,31 @@ | ||
package com.hmily.learning; | ||
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; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
group10/706097141/learning/src/com/hmily/learning/Iterator.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,7 @@ | ||
package com.hmily.learning; | ||
|
||
public interface Iterator { | ||
public boolean hasNext(); | ||
public Object next(); | ||
|
||
} |
91 changes: 91 additions & 0 deletions
91
group10/706097141/learning/src/com/hmily/learning/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,91 @@ | ||
package com.hmily.learning; | ||
/** | ||
* 不会写 | ||
* @author zyzhmily | ||
* | ||
*/ | ||
public class LinkedList implements List { | ||
|
||
//链表头 | ||
private Node head; | ||
//链表尾 | ||
private Node tail; | ||
//链表大小 | ||
private int size; | ||
|
||
public void add(Object o){ | ||
Node t = tail; | ||
Node node = new Node(o, null); | ||
tail = node; | ||
if (t == null) { | ||
head = node; | ||
} else { | ||
t.next = node; | ||
} | ||
size++; | ||
} | ||
public void add(int index , Object o){ | ||
if(index<0||index>size()){ | ||
throw new IndexOutOfBoundsException(); | ||
} | ||
if (index == size) { | ||
add(o); | ||
} else { | ||
Node node = head; | ||
for (int i = 0; i < index-1; i++) { | ||
node = node.next; | ||
} | ||
Node newNode = new Node(o, node); | ||
node.next = newNode; | ||
newNode.next = node; | ||
size++; | ||
} | ||
} | ||
public Object get(int index){ | ||
if(index<0||index>size()){ | ||
throw new IndexOutOfBoundsException(); | ||
} | ||
Node node=head; | ||
for(int i=0;i<index;i++){ | ||
node=node.next; | ||
} | ||
return node.data; | ||
} | ||
public Object remove(int index){ | ||
if(index<0||index>size()){ | ||
throw new IndexOutOfBoundsException(); | ||
} | ||
return null; | ||
} | ||
|
||
public int size(){ | ||
return this.size; | ||
} | ||
|
||
public void addFirst(Object o){ | ||
Node newNode = new Node(o,null); | ||
newNode.next=head.next; | ||
} | ||
public void addLast(Object o){ | ||
add(o); | ||
} | ||
public Object removeFirst(){ | ||
return null; | ||
} | ||
public Object removeLast(){ | ||
return null; | ||
} | ||
public Iterator iterator(){ | ||
return null; | ||
} | ||
|
||
|
||
private static class Node{ | ||
Object data; | ||
Node next; | ||
public Node(Object data, Node next) { | ||
this.data = data; | ||
this.next = 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,8 @@ | ||
package com.hmily.learning; | ||
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(); | ||
} |
91 changes: 91 additions & 0 deletions
91
group10/706097141/learning/src/com/hmily/learning/MyArrayList.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,91 @@ | ||
package com.hmily.learning; | ||
|
||
public class MyArrayList implements List,Iterator{ | ||
|
||
private int size = 0; | ||
|
||
private Object[] elementData = new Object[100]; | ||
|
||
/** | ||
* 添加元素 | ||
*/ | ||
public void add(Object o){ | ||
if(size==elementData.length){ | ||
Object[] newElementData = new Object[elementData.length+1]; | ||
for(int i=0;i<elementData.length;i++){ | ||
newElementData[i] = elementData[i]; | ||
} | ||
newElementData[elementData.length+1]=o; | ||
elementData = newElementData; | ||
size++; | ||
}else{ | ||
elementData[size+1]=o; | ||
size++; | ||
} | ||
} | ||
/** | ||
* 在指定位置添加元素 | ||
*/ | ||
public void add(int index, Object o){ | ||
if(size()==elementData.length){ | ||
Object[] newElementData = new Object[size()*2+1]; | ||
for(int i=0;i<elementData.length;i++){ | ||
newElementData[i] = elementData[i]; | ||
} | ||
elementData = newElementData; | ||
} | ||
for(int i=size();i>index;i--){ | ||
elementData[i]=elementData[i-1]; | ||
} | ||
elementData[index]=o; | ||
size++; | ||
} | ||
/** | ||
* 获取元素 | ||
*/ | ||
public Object get(int index){ | ||
if(index>=size()||index<0){ | ||
throw new ArrayIndexOutOfBoundsException(); | ||
} | ||
return elementData[index]; | ||
} | ||
/** | ||
* 移除元素 | ||
*/ | ||
public Object remove(int index){ | ||
if(index<0||index>size()){ | ||
throw new ArrayIndexOutOfBoundsException(); | ||
} | ||
Object o=elementData[index]; | ||
for(int i=index;i<size();i++){ | ||
elementData[i]=elementData[i+1]; | ||
} | ||
return o; | ||
} | ||
|
||
public int size(){ | ||
return this.size; | ||
} | ||
/** | ||
* 数组下标 | ||
*/ | ||
private int bounds=0; | ||
|
||
public Iterator iterator(){ | ||
return this.iterator(); | ||
} | ||
/** | ||
* | ||
*/ | ||
@Override | ||
public boolean hasNext() { | ||
return bounds<size(); | ||
} | ||
@Override | ||
public Object next() { | ||
if(!hasNext()){ | ||
throw new ArrayIndexOutOfBoundsException(); | ||
} | ||
return elementData[bounds++]; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
group10/706097141/learning/src/com/hmily/learning/MyQueue.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,23 @@ | ||
package com.hmily.learning; | ||
|
||
public class MyQueue { | ||
private MyArrayList elementData = new MyArrayList(); | ||
private int size; | ||
public void enQueue(Object o){ | ||
elementData.add(o); | ||
size=elementData.size(); | ||
} | ||
|
||
public Object deQueue(){ | ||
Object o=elementData.remove(0); | ||
return o; | ||
} | ||
|
||
public boolean isEmpty(){ | ||
return size()==0; | ||
} | ||
|
||
public int size(){ | ||
return size; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
group10/706097141/learning/src/com/hmily/learning/MyStack.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,26 @@ | ||
package com.hmily.learning; | ||
public class MyStack { | ||
private MyArrayList elementData = new MyArrayList(); | ||
private int size; | ||
public void push(Object o){ | ||
elementData.add(o); | ||
size=elementData.size(); | ||
} | ||
|
||
public Object pop(){ | ||
Object o=elementData.remove(this.size()-1); | ||
size=elementData.size(); | ||
return o; | ||
} | ||
|
||
public Object peek(){ | ||
Object o=elementData.get(size()-1); | ||
return o; | ||
} | ||
public boolean isEmpty(){ | ||
return 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,9 @@ | ||
package com.hmily.test; | ||
|
||
public class MyTest { | ||
|
||
public static void main(String[] args) { | ||
System.out.println("Hello World!!!"); | ||
} | ||
|
||
} |