forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'refs/remotes/BlindingDark/master'
- Loading branch information
Showing
25 changed files
with
1,518 additions
and
7 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,2 @@ | ||
/bin | ||
/.project/.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,149 @@ | ||
|
||
//package javaTest; | ||
|
||
import java.util.Arrays; | ||
|
||
public class ArrayList { | ||
|
||
private Object[] elementData=new Object[2]; | ||
int size; | ||
//添加元素 | ||
public void add(Object o) | ||
{ | ||
if(size<elementData.length) | ||
{ | ||
elementData[size]=o; | ||
} | ||
else{ | ||
elementData=grow(elementData); | ||
elementData[size]=o; | ||
} | ||
size++; | ||
|
||
} | ||
//通过索引添加元素 | ||
public void add(int index,Object o){ | ||
if(size<elementData.length) | ||
{ | ||
addInner(elementData,index,o); | ||
} | ||
else{ | ||
elementData=grow(elementData); | ||
addInner(elementData,index,o); | ||
} | ||
size++; | ||
} | ||
//通过索引获取元素 | ||
public Object get(int index) | ||
{ | ||
Object o=null; | ||
for(int i=0;i<size;i++) | ||
{ | ||
if(i==index) | ||
{ | ||
o= elementData[i]; | ||
} | ||
} | ||
return o; | ||
} | ||
//通过索引删除元素 | ||
public Object remove(int index){ | ||
Object o=null; | ||
if(index==size) | ||
{ | ||
o=elementData[size]; | ||
} | ||
else{ | ||
for(int i=0;i<size;i++) | ||
{ | ||
if(i==index) | ||
{ | ||
o=elementData[index]; | ||
for(int x=index;x<size-1;x++) | ||
{ | ||
elementData[x]=elementData[x+1]; | ||
} | ||
} | ||
|
||
} | ||
} | ||
size--; | ||
return o; | ||
} | ||
//删除最后一个元素 | ||
/*public Object removeLast() | ||
{ | ||
int size=this.size(); | ||
Object o=this.get(size-1); | ||
size--; | ||
return o; | ||
}*/ | ||
//获取当前元素的数目 | ||
public int size() | ||
{ | ||
return size; | ||
} | ||
//数组扩容函数 | ||
public Object[] grow(Object[] elementData) | ||
{ | ||
return Arrays.copyOf(elementData, elementData.length*2); | ||
} | ||
//通过索引添加元素的内部函数 | ||
public void addInner(Object[] elementData,int index,Object o) | ||
{ | ||
for(int i=0;i<size;i++) | ||
{ | ||
if(i==index) | ||
{ | ||
Object t=elementData[i]; | ||
elementData[i]=o; | ||
for(int x=size;x>i;x--) | ||
{ | ||
if(x==index+1) | ||
{ | ||
elementData[x]=t; | ||
} | ||
else | ||
{ | ||
elementData[x]=elementData[x-1]; | ||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
public Iterator iterator() | ||
{ | ||
return new ArrayListIterator(this); | ||
} | ||
private class ArrayListIterator implements Iterator | ||
{ | ||
ArrayList l=null; | ||
int pos=0; | ||
private ArrayListIterator(ArrayList l) | ||
{ | ||
this.l=l; | ||
} | ||
public boolean hasNext() { | ||
// TODO Auto-generated method stub | ||
boolean flag=true; | ||
pos++; | ||
if(pos>size) | ||
{ | ||
flag=false; | ||
} | ||
return flag; | ||
} | ||
|
||
public Object next() { | ||
// TODO Auto-generated method stub | ||
|
||
return elementData[pos-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,27 @@ | ||
|
||
//package javaTest; | ||
|
||
public class ArrayTest { | ||
|
||
/** | ||
* @param args | ||
* 模拟ArrayList实现对元素的增删查找 | ||
*/ | ||
public static void main(String[] args) { | ||
// TODO Auto-generated method stub | ||
ArrayList a=new ArrayList(); | ||
a.add("hello"); | ||
a.add("java"); | ||
a.add("world"); | ||
a.add("hello"); | ||
// a.add(2,"hello"); | ||
Iterator it=a.iterator(); | ||
while(it.hasNext()) | ||
{ | ||
System.out.print(it.next()+" "); | ||
} | ||
System.out.println(a.size()); | ||
} | ||
|
||
} | ||
|
34 changes: 34 additions & 0 deletions
34
group26/1778842360/first heomework/src/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,34 @@ | ||
|
||
//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,7 @@ | ||
|
||
public interface Iterator { | ||
|
||
public boolean hasNext(); | ||
public Object next(); | ||
|
||
} |
Oops, something went wrong.