Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/BlindingDark/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Lizhny committed Mar 14, 2017
2 parents 4971372 + ff697c0 commit fd89763
Show file tree
Hide file tree
Showing 25 changed files with 1,518 additions and 7 deletions.
2 changes: 2 additions & 0 deletions group26/1778842360/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bin
/.project/.classpath
149 changes: 149 additions & 0 deletions group26/1778842360/first heomework/src/ArrayList.java
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];
}
}




}

27 changes: 27 additions & 0 deletions group26/1778842360/first heomework/src/ArrayTest.java
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 group26/1778842360/first heomework/src/BinaryTreeNode.java
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;
}

}

7 changes: 7 additions & 0 deletions group26/1778842360/first heomework/src/Iterator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

public interface Iterator {

public boolean hasNext();
public Object next();

}
Loading

0 comments on commit fd89763

Please sign in to comment.