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 #5 from shaofriend/master
重新提交 by shaofriend
- Loading branch information
Showing
8 changed files
with
236 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 @@ | ||
/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,98 @@ | ||
package com.coding.basic; | ||
|
||
public class ArrayList implements List { | ||
|
||
private int size=0; | ||
|
||
private Object[] elementData =new Object[10]; | ||
|
||
|
||
//数组扩容 | ||
private void ensureCapacityInternal(){ | ||
if(size==elementData.length){ | ||
Object[] newArray = new Object[size*2]; | ||
System.arraycopy(elementData, 0, newArray, 0, elementData.length); | ||
elementData=newArray; | ||
} | ||
} | ||
|
||
public void add(Object o){ | ||
ensureCapacityInternal(); | ||
elementData[size]=o; | ||
size++; | ||
} | ||
|
||
public void add(int index, Object o){ | ||
ensureCapacityInternal(); | ||
if(index<0){ | ||
try { | ||
throw new Exception(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
System.arraycopy(elementData, index, elementData, index+1,size-index ); | ||
elementData[index]=o; | ||
size++; | ||
} | ||
|
||
public Object get(int index){ | ||
if(index<0||index>=size){ | ||
try { | ||
throw new Exception(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
return elementData[index]; | ||
} | ||
|
||
public Object remove(int index){ | ||
if(index>=size){ | ||
try { | ||
throw new Exception(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
}else{ | ||
|
||
int numMoved=size-index-1; | ||
if(numMoved>0){ | ||
System.arraycopy(elementData, index+1, elementData, index, numMoved); | ||
} | ||
|
||
elementData[size--] = null; | ||
} | ||
return index; | ||
|
||
} | ||
|
||
|
||
public int size(){ | ||
return size; | ||
} | ||
|
||
|
||
private class Iter implements Iterator { | ||
//计数器 | ||
private int coursor=-1; | ||
//判断是否存在下一个 | ||
public boolean hasNext(){ | ||
return coursor+1<size; | ||
} | ||
//获取下一个 | ||
public String next(){ | ||
coursor++; | ||
return (String) elementData[coursor]; | ||
} | ||
} | ||
public Iterator iterator(){ | ||
|
||
return new Iter(); | ||
|
||
} | ||
} | ||
|
||
|
||
|
32 changes: 32 additions & 0 deletions
32
group20/452472201/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,9 @@ | ||
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,46 @@ | ||
package com.coding.basic; | ||
|
||
public class LinkedList implements List { | ||
|
||
private Node head; | ||
|
||
public void add(Object o){ | ||
|
||
} | ||
public void add(int index , Object o){ | ||
|
||
} | ||
public Object get(int index){ | ||
return null; | ||
} | ||
public Object remove(int index){ | ||
return null; | ||
} | ||
|
||
public int size(){ | ||
return -1; | ||
} | ||
|
||
public void addFirst(Object o){ | ||
|
||
} | ||
public void addLast(Object o){ | ||
|
||
} | ||
public Object removeFirst(){ | ||
return null; | ||
} | ||
public Object removeLast(){ | ||
return null; | ||
} | ||
public Iterator iterator(){ | ||
return null; | ||
} | ||
|
||
|
||
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,19 @@ | ||
package com.coding.basic; | ||
|
||
public class Queue { | ||
|
||
public void enQueue(Object o){ | ||
} | ||
|
||
public Object deQueue(){ | ||
return null; | ||
} | ||
|
||
public boolean isEmpty(){ | ||
return false; | ||
} | ||
|
||
public int size(){ | ||
return -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,22 @@ | ||
package com.coding.basic; | ||
|
||
public class Stack { | ||
private ArrayList elementData = new ArrayList(); | ||
|
||
public void push(Object o){ | ||
} | ||
|
||
public Object pop(){ | ||
return null; | ||
} | ||
|
||
public Object peek(){ | ||
return null; | ||
} | ||
public boolean isEmpty(){ | ||
return false; | ||
} | ||
public int size(){ | ||
return -1; | ||
} | ||
} |