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 #12 from wangxuan007/master
firstcommit
- Loading branch information
Showing
10 changed files
with
155 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>1906242834Learning</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,71 @@ | ||
package com.coding.basic; | ||
|
||
public class ArrayList implements List { | ||
|
||
private int size = 0; | ||
|
||
private Object[] elementData = new Object[100]; | ||
|
||
public void add(Object o){ | ||
//若插入元素后会溢出,则对数组进行扩容,在这里只把空间加1 | ||
if ((size()+1)>elementData.length) { | ||
System.arraycopy(elementData, 0, elementData, 0, elementData.length+1); | ||
elementData[size] = o; | ||
}else { | ||
//若插入元素后不出现溢出,则直接添加在末尾 | ||
elementData[size] = o; | ||
} | ||
} | ||
//index在length范围之内正常插入,若index大于length则抛出异常 | ||
public void add(int index, Object o){ | ||
Object temp; | ||
if (index<elementData.length) { | ||
System.arraycopy(elementData, 0, elementData, 0, elementData.length+1); | ||
temp = elementData[elementData.length-1]; | ||
elementData[elementData.length] = temp; | ||
for (int i = elementData.length; i > index; i--) { | ||
elementData[i-1] = elementData[i-2]; | ||
} | ||
elementData[index] = o; | ||
}else if (index==elementData.length) { | ||
add(o); | ||
}else{ | ||
System.out.println("ArrayIndexOutOfBoundsException"); | ||
} | ||
} | ||
|
||
public Object get(int index){ | ||
if (index<=elementData.length-1) { | ||
return elementData[index]; | ||
}else { | ||
System.out.println("ArrayIndexOutOfBoundsException"); | ||
} | ||
return elementData; | ||
} | ||
|
||
public Object remove(int index){ | ||
if (index<elementData.length) { | ||
for (int i = index; i < elementData.length; i++) { | ||
elementData[i] = elementData[i+1]; | ||
} | ||
return elementData; | ||
}else { | ||
System.out.println("ArrayIndexOutOfBoundsException"); | ||
} | ||
return elementData; | ||
} | ||
|
||
public int size(){ | ||
for (Object object : elementData) { | ||
if (object!=null) { | ||
size += 1; | ||
} | ||
} | ||
return size; | ||
} | ||
|
||
public Iterator iterator(){ | ||
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,5 @@ | ||
package com.coding.basic; | ||
|
||
public class BinaryTreeNode { | ||
|
||
} |
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,5 @@ | ||
package com.coding.basic; | ||
|
||
public class Iterator { | ||
|
||
} |
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,5 @@ | ||
package com.coding.basic; | ||
|
||
public class LinkedList { | ||
|
||
} |
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,5 @@ | ||
package com.coding.basic; | ||
|
||
public interface List { | ||
|
||
} |
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,5 @@ | ||
package com.coding.basic; | ||
|
||
public class Queue { | ||
|
||
} |
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,35 @@ | ||
package com.coding.basic; | ||
|
||
public class Stack { | ||
private ArrayList elementData = new ArrayList(); | ||
|
||
public void push(Object o){ | ||
for (int i = 0; i < elementData.size(); i++) { | ||
if(elementData.get(i)==null){ | ||
elementData.add(i, o); | ||
} | ||
} | ||
} | ||
|
||
|
||
public Object pop(){ | ||
int length = elementData.size(); | ||
elementData.remove(length-1); | ||
return elementData.get(length-1); | ||
} | ||
|
||
public Object peek(){ | ||
int length = elementData.size(); | ||
return elementData.get(length-1); | ||
} | ||
public boolean isEmpty(){ | ||
if(elementData.size()==0){ | ||
return true; | ||
}else{ | ||
return false; | ||
} | ||
} | ||
public int size(){ | ||
return elementData.size(); | ||
} | ||
} |