diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index 1a08aba0c8..0000000000
--- a/.gitignore
+++ /dev/null
@@ -1,30 +0,0 @@
-*.class
-# Mobile Tools for Java (J2ME)
-.mtj.tmp/
-
-# Package Files #
-*.jar
-*.war
-*.ear
-target
-
-# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
-hs_err_pid*
-
-#ide config
-.metadata
-.recommenders
-.idea/
-
-
-
-#macOS
-.DS_Store
-
-
-*.iml
-rebel.*
-.rebel.*
-
-target
-
diff --git a/README.md b/README.md
new file mode 100644
index 0000000000..a7d23c04cf
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+## 2017编程提高社群
+
+2017编程提高社群代码仓库所在地
\ No newline at end of file
diff --git a/group01/1298552064/.classpath b/group01/1298552064/.classpath
new file mode 100644
index 0000000000..05cf0dba9e
--- /dev/null
+++ b/group01/1298552064/.classpath
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/group04/564451732/.gitignore b/group01/1298552064/.gitignore
similarity index 100%
rename from group04/564451732/.gitignore
rename to group01/1298552064/.gitignore
diff --git a/group01/1298552064/.project b/group01/1298552064/.project
new file mode 100644
index 0000000000..ddbb7719d0
--- /dev/null
+++ b/group01/1298552064/.project
@@ -0,0 +1,17 @@
+
+
+ 1298552064Learning
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group01/1298552064/src/week01/basic/MyLinkedList.java b/group01/1298552064/src/week01/basic/MyLinkedList.java
index 4894c5ff6c..88db213864 100644
--- a/group01/1298552064/src/week01/basic/MyLinkedList.java
+++ b/group01/1298552064/src/week01/basic/MyLinkedList.java
@@ -124,7 +124,7 @@ public Object removeLast() {
Node p = head;
for (int i = 0; i < size; i++) {
if (p.next.next == null) {
- removeObject = p.next;
+ removeObject = p.next.data;
p.next = null;
break;
} else {
diff --git a/group01/1298552064/src/week02/array/ArrayUtil.java b/group01/1298552064/src/week02/array/ArrayUtil.java
new file mode 100644
index 0000000000..9b6c0bebaf
--- /dev/null
+++ b/group01/1298552064/src/week02/array/ArrayUtil.java
@@ -0,0 +1,245 @@
+package week02.array;
+
+import java.util.Arrays;
+
+public class ArrayUtil {
+
+ // 工具类,不予许创建实例
+ private ArrayUtil() {
+ }
+
+ /**
+ * 给定一个整形数组a , 对该数组的值进行置换 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7] 如果 a =
+ * [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7]
+ *
+ * @param origin
+ * @return
+ */
+ public static void reverseArray(int[] origin) {
+ if (origin != null && origin.length > 0) {
+ int temp = 0;
+
+ // 数组首尾元素置换
+ for (int i = 0; i < origin.length / 2; i++) {
+ temp = origin[i];
+ origin[i] = origin[origin.length - i - 1];
+ origin[origin.length - i - 1] = temp;
+ }
+ }
+ }
+
+ /**
+ * 现在有如下的一个数组: int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5}
+ * 要求将以上数组中值为0的项去掉,将不为0的值存入一个新的数组,生成的新数组为: {1,3,4,5,6,6,5,4,7,6,7,5}
+ *
+ * @param oldArray
+ * @return
+ */
+
+ public static int[] removeZero(int[] oldArray) {
+ int[] newArray = null;
+ if (oldArray != null) {
+ newArray = new int[oldArray.length];
+ int size = 0;
+ for (int i = 0; i < oldArray.length; i++) {
+ if (oldArray[i] != 0) {
+ newArray[size] = oldArray[i];
+ size++;
+ }
+ }
+ newArray = Arrays.copyOf(newArray, size);
+ }
+ return newArray;
+ }
+
+ /**
+ * 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的 例如 a1 =
+ * [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复
+ *
+ * @param array1
+ * @param array2
+ * @return
+ */
+
+ public static int[] merge(int[] array1, int[] array2) {
+ int[] newArray = null;
+ if (array1 != null && array2 != null) {
+ int size = 0;
+
+ // index1、index2表示array1和array2数组的比较索引
+ int index1 = 0, index2 = 0;
+ newArray = new int[array1.length + array2.length];
+
+ while (index1 < array1.length && index2 < array2.length) {
+ if (array1[index1] == array2[index2]) {
+ newArray[size++] = array1[index1];
+ index1++;
+ index2++;
+ } else if (array1[index1] < array2[index2]) {
+ // 数组array1去重
+ if (size > 0 && array1[index1] == newArray[size - 1]) {
+ size--;
+ }
+ newArray[size++] = array1[index1];
+ index1++;
+ } else {
+ // 数组array2去重
+ if (size > 0 && array2[index2] == newArray[size - 1]) {
+ size--;
+ }
+ newArray[size++] = array2[index2];
+ index2++;
+ }
+ }
+
+ // 将数组array1剩下的元素放入
+ while (index1 < array1.length) {
+ newArray[size++] = array1[index1++];
+ }
+
+ // 将数组array2剩下的元素放入
+ while (index2 < array2.length) {
+ newArray[size++] = array2[index2++];
+ }
+
+ // 合并后有序数组
+ newArray = Arrays.copyOf(newArray, size);
+ }
+ return newArray;
+ }
+
+ /**
+ * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
+ * 注意,老数组的元素在新数组中需要保持 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
+ * [2,3,6,0,0,0]
+ *
+ * @param oldArray
+ * @param size
+ * @return
+ */
+ public static int[] grow(int[] oldArray, int size) {
+ int[] newArray = null;
+ if (oldArray != null) {
+ newArray = new int[oldArray.length + size];
+ for (int i = 0; i < oldArray.length; i++) {
+ newArray[i] = oldArray[i];
+ }
+ }
+ return newArray;
+ }
+
+ /**
+ * 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列 例如, max = 15 ,
+ * 则返回的数组应该为 [1,1,2,3,5,8,13] max = 1, 则返回空数组 []
+ *
+ * @param max
+ * @return
+ */
+ public static int[] fibonacci(int max) {
+
+ // 计算方法:f(n) = f(n-1) + f(n-2) 采用数组计算
+ int[] result = null;
+ if (max <= 1) {
+ result = new int[] {};
+ } else {
+ int i = 2;
+ result = new int[max];
+ result[0] = result[1] = 1;
+ for (; i < max; i++) {
+ if (result[i - 1] + result[i - 2] < max) {
+ result[i] = result[i - 1] + result[i - 2];
+ } else {
+ break;
+ }
+ }
+ result = Arrays.copyOf(result, i);
+ }
+ return result;
+ }
+
+ /**
+ * 返回小于给定最大值max的所有素数数组 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ *
+ * @param max
+ * @return
+ */
+ public static int[] getPrimes(int max) {
+ int[] newArray = new int[] {};
+ if (max > 2) {
+ newArray = new int[max];
+ int size = 0, j = 0;
+ for (int i = 2; i < max; i++) {
+ for (j = 2; j < i / 2 + 1; j++) {
+ if (i % j == 0) {
+ break;
+ }
+ }
+
+ if (j == i / 2 + 1) {
+ newArray[size++] = i;
+ }
+ }
+ newArray = Arrays.copyOf(newArray, size);
+ }
+ return newArray;
+ }
+
+ /**
+ * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
+ *
+ * @param max
+ * @return
+ */
+ public static int[] getPerfectNumbers(int max) {
+ int[] newArray = new int[] {};
+ if (max > 0) {
+ newArray = new int[max];
+ int size = 0, sum = 0;
+ for (int i = 1; i < max; i++) {
+ sum = 0;
+ for (int j = 1; j < i / 2 + 1; j++) {
+ if (i % j == 0) {
+ sum += j;
+ }
+ }
+ if (i == sum) {
+ newArray[size++] = i;
+ }
+ }
+ newArray = Arrays.copyOf(newArray, size);
+ }
+ return newArray;
+ }
+
+ /**
+ * 用seperator 把数组 array给连接起来 例如array= [3,8,9], seperator = "-" 则返回值为"3-8-9"
+ *
+ * @param array
+ * @param seperator
+ * @return
+ */
+ public static String join(int[] array, String seperator) {
+ String joinResult = null;
+ if (array != null) {
+ joinResult = "";
+ for (int i = 0; i < array.length; i++) {
+ joinResult += array[i] + seperator;
+ }
+ joinResult = joinResult.equals("") ? "" : joinResult.substring(0, joinResult.length() - 1);
+ }
+ return joinResult;
+ }
+
+ public static void main(String[] args) {
+ int[] a = new ArrayUtil().getPerfectNumbers(1000);
+ for (int i = 0; i < a.length; i++) {
+ System.out.println(a[i]);
+ }
+
+ // [2,3,5,7,11,13,17,19]
+ a = new ArrayUtil().getPrimes(20);
+ for (int i = 0; i < a.length; i++) {
+ System.out.println(a[i]);
+ }
+ }
+}
diff --git a/group01/1298552064/src/week02/litestruts/LoginAction.java b/group01/1298552064/src/week02/litestruts/LoginAction.java
new file mode 100644
index 0000000000..aec243dd1b
--- /dev/null
+++ b/group01/1298552064/src/week02/litestruts/LoginAction.java
@@ -0,0 +1,42 @@
+package week02.litestruts;
+
+/**
+ * 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。
+ *
+ * @author liuxin
+ *
+ */
+public class LoginAction {
+ private String name;
+ private String password;
+ private String message;
+
+ public String getName() {
+ return name;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String execute() {
+ if ("test".equals(name) && "1234".equals(password)) {
+ this.message = "login successful";
+ return "success";
+ }
+ this.message = "login failed,please check your user/pwd";
+ return "fail";
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getMessage() {
+ return this.message;
+ }
+}
diff --git a/group01/1298552064/src/week02/litestruts/Struts.java b/group01/1298552064/src/week02/litestruts/Struts.java
new file mode 100644
index 0000000000..3cef26c396
--- /dev/null
+++ b/group01/1298552064/src/week02/litestruts/Struts.java
@@ -0,0 +1,106 @@
+package week02.litestruts;
+
+import java.io.InputStream;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.dom4j.Document;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+
+public class Struts {
+
+ public static View runAction(String actionName, Map parameters) {
+
+ /*
+ *
+ * 0. 读取配置文件struts.xml
+ *
+ * 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
+ * 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是 ("name"="test" ,
+ * "password"="1234") , 那就应该调用 setName和setPassword方法
+ *
+ * 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
+ *
+ * 3. 通过反射找到对象的所有getter方法(例如 getMessage), 通过反射来调用, 把值和属性形成一个HashMap , 例如
+ * {"message": "登录成功"} , 放到View对象的parameters
+ *
+ * 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
+ * 放到View对象的jsp字段中。
+ *
+ */
+
+ try {
+
+ // 0. 读取配置文件struts.xml
+ SAXReader reader = new SAXReader();
+ InputStream in = Struts.class.getResourceAsStream("struts.xml");
+ Document document = reader.read(in);
+ Element root = document.getRootElement();
+
+ // 与actionName匹配的Element
+ Element actionElement = null;
+ String className = null;
+
+ for (Iterator iterator = root.elementIterator("action"); iterator.hasNext();) {
+ Element e = iterator.next();
+ if (e.attributeValue("name").equals(actionName)) {
+ actionElement = e;
+ className = e.attributeValue("class");
+ break;
+ }
+ }
+
+ Class> clazz = Class.forName(className);
+ Object action = clazz.newInstance();
+
+ // 1. 反射设置属性
+ if (parameters != null) {
+ for (Map.Entry entry : parameters.entrySet()) {
+ String fieldName = entry.getKey();
+ String methodName = "set" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
+ Class> fieldType = clazz.getDeclaredField(fieldName).getType();
+ Method method = clazz.getDeclaredMethod(methodName, fieldType);
+ method.invoke(action, entry.getValue());
+ }
+ }
+
+ // 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
+ Method execute = clazz.getDeclaredMethod("execute");
+ String result = (String) execute.invoke(action);
+
+ // 3. 通过反射找到对象的所有getter方法(例如 getMessage), 通过反射来调用, 把值和属性形成一个HashMap
+ Method[] methods = clazz.getDeclaredMethods();
+ Map param = new HashMap();
+ for (Method method : methods) {
+ String methodName = method.getName();
+ if (method.getName().startsWith("get")) {
+ String fieldName = methodName.substring(3, 4).toLowerCase() + methodName.substring(4);
+ Object fieldValue = method.invoke(action);
+ param.put(fieldName, fieldValue);
+ }
+ }
+
+ View view = new View();
+ view.setParameters(param);
+
+ // 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
+ // 放到View对象的jsp字段中。
+ for (Iterator iterator = actionElement.elementIterator("result"); iterator.hasNext();) {
+ Element resultElement = iterator.next();
+ if (resultElement.attributeValue("name").equals(result)) {
+ view.setJsp(resultElement.getText());
+ break;
+ }
+ }
+
+ return view;
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+}
diff --git a/group01/1298552064/src/week02/litestruts/View.java b/group01/1298552064/src/week02/litestruts/View.java
new file mode 100644
index 0000000000..a286412f0e
--- /dev/null
+++ b/group01/1298552064/src/week02/litestruts/View.java
@@ -0,0 +1,26 @@
+package week02.litestruts;
+
+import java.util.Map;
+
+public class View {
+ private String jsp;
+ private Map parameters;
+
+ public String getJsp() {
+ return jsp;
+ }
+
+ public View setJsp(String jsp) {
+ this.jsp = jsp;
+ return this;
+ }
+
+ public Map getParameters() {
+ return parameters;
+ }
+
+ public View setParameters(Map parameters) {
+ this.parameters = parameters;
+ return this;
+ }
+}
diff --git a/group01/1298552064/src/week02/litestruts/struts.xml b/group01/1298552064/src/week02/litestruts/struts.xml
new file mode 100644
index 0000000000..01398e9c3d
--- /dev/null
+++ b/group01/1298552064/src/week02/litestruts/struts.xml
@@ -0,0 +1,11 @@
+
+
+
+ /jsp/homepage.jsp
+ /jsp/showLogin.jsp
+
+
+ /jsp/welcome.jsp
+ /jsp/error.jsp
+
+
\ No newline at end of file
diff --git a/group01/1298552064/src/week02/test/ArrayUtilTest.java b/group01/1298552064/src/week02/test/ArrayUtilTest.java
new file mode 100644
index 0000000000..e796b5f845
--- /dev/null
+++ b/group01/1298552064/src/week02/test/ArrayUtilTest.java
@@ -0,0 +1,75 @@
+package week02.test;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import week02.array.ArrayUtil;
+
+public class ArrayUtilTest {
+
+ @Test
+ public void testReverseArray() {
+ int[] a = new int[] { 7, 9, 30, 3 };
+ int[] b = new int[] { 7, 9, 30, 3, 4 };
+
+ ArrayUtil.reverseArray(a);
+ ArrayUtil.reverseArray(b);
+
+ Assert.assertArrayEquals(new int[] { 3, 30, 9, 7 }, a);
+ Assert.assertArrayEquals(new int[] { 4, 3, 30, 9, 7 }, b);
+ }
+
+ @Test
+ public void testRemoveZero() {
+ int[] oldArr = new int[] { 1, 3, 4, 5, 0, 0, 6, 6, 0, 5, 4, 7, 6, 7, 0, 5 };
+ int[] newArray = ArrayUtil.removeZero(oldArr);
+ Assert.assertArrayEquals(new int[] { 1, 3, 4, 5, 6, 6, 5, 4, 7, 6, 7, 5 }, newArray);
+ }
+
+ @Test
+ public void testMerge() {
+ int[] a1 = new int[] { 3, 5, 7, 8 };
+ int[] a2 = new int[] { 4, 5, 6, 6, 7, 7 };
+ int[] a3 = ArrayUtil.merge(a1, a2);
+ Assert.assertArrayEquals(new int[] { 3, 4, 5, 6, 7, 8 }, a3);
+ }
+
+ @Test
+ public void testGrow() {
+ int[] oldArray = new int[] { 2, 3, 6 };
+ int size = 3;
+ int[] newArray = ArrayUtil.grow(oldArray, size);
+ Assert.assertArrayEquals(new int[] { 2, 3, 6, 0, 0, 0 }, newArray);
+ }
+
+ @Test
+ public void testFibonacci() {
+ int max = 15;
+ int max2 = 1;
+ int[] newArray = ArrayUtil.fibonacci(max);
+ int[] newArray2 = ArrayUtil.fibonacci(max2);
+ Assert.assertArrayEquals(new int[] { 1, 1, 2, 3, 5, 8, 13 }, newArray);
+ Assert.assertArrayEquals(new int[] {}, newArray2);
+ }
+
+ @Test
+ public void testGetPrimes() {
+ int[] newArray = ArrayUtil.getPrimes(23);
+ Assert.assertArrayEquals(new int[] { 2, 3, 5, 7, 11, 13, 17, 19 }, newArray);
+ }
+
+ @Test
+ public void testGetPerfectNumbers() {
+ int[] newArray = ArrayUtil.getPerfectNumbers(1000);
+ Assert.assertArrayEquals(new int[] { 6, 28, 496 }, newArray);
+ }
+
+ @Test
+ public void testJoin() {
+ int[] array = new int[] { 3, 8, 9 };
+ String seperator = "-";
+ String result = ArrayUtil.join(array, seperator);
+ Assert.assertEquals("3-8-9", result);
+ }
+
+}
diff --git a/group01/1298552064/src/week02/test/StrutsTest.java b/group01/1298552064/src/week02/test/StrutsTest.java
new file mode 100644
index 0000000000..3eb6d01fd0
--- /dev/null
+++ b/group01/1298552064/src/week02/test/StrutsTest.java
@@ -0,0 +1,41 @@
+package week02.test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import week02.litestruts.Struts;
+import week02.litestruts.View;
+
+public class StrutsTest {
+
+ @Test
+ public void testLoginActionSuccess() {
+
+ String actionName = "login";
+
+ Map params = new HashMap();
+ params.put("name", "test");
+ params.put("password", "1234");
+
+ View view = Struts.runAction(actionName, params);
+
+ Assert.assertEquals("/jsp/homepage.jsp", view.getJsp());
+ Assert.assertEquals("login successful", view.getParameters().get("message"));
+ }
+
+ @Test
+ public void testLoginActionFailed() {
+ String actionName = "login";
+ Map params = new HashMap();
+ params.put("name", "test");
+ params.put("password", "123456"); // 密码和预设的不一致
+
+ View view = Struts.runAction(actionName, params);
+
+ Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp());
+ Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message"));
+ }
+}
diff --git a/group01/1328404806/RemoteSystemsTempFiles/.project b/group01/1328404806/RemoteSystemsTempFiles/.project
index 7675629320..5447a64fa9 100644
--- a/group01/1328404806/RemoteSystemsTempFiles/.project
+++ b/group01/1328404806/RemoteSystemsTempFiles/.project
@@ -1,12 +1,12 @@
-
-
- RemoteSystemsTempFiles
-
-
-
-
-
-
- org.eclipse.rse.ui.remoteSystemsTempNature
-
-
+
+
+ RemoteSystemsTempFiles
+
+
+
+
+
+
+ org.eclipse.rse.ui.remoteSystemsTempNature
+
+
diff --git a/group01/1328404806/dataStructure/.classpath b/group01/1328404806/dataStructure/.classpath
index 7faf63dc05..4e4d00bbfd 100644
--- a/group01/1328404806/dataStructure/.classpath
+++ b/group01/1328404806/dataStructure/.classpath
@@ -1,27 +1,27 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/group01/1328404806/dataStructure/.project b/group01/1328404806/dataStructure/.project
index 86bf42de91..d2311ab943 100644
--- a/group01/1328404806/dataStructure/.project
+++ b/group01/1328404806/dataStructure/.project
@@ -1,23 +1,23 @@
-
-
- dataStructure
-
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- org.eclipse.m2e.core.maven2Builder
-
-
-
-
-
- org.eclipse.jdt.core.javanature
- org.eclipse.m2e.core.maven2Nature
-
-
+
+
+ dataStructure
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ org.eclipse.m2e.core.maven2Nature
+
+
diff --git a/group01/1328404806/dataStructure/.settings/org.eclipse.core.resources.prefs b/group01/1328404806/dataStructure/.settings/org.eclipse.core.resources.prefs
index 4c28b1a898..f9fe34593f 100644
--- a/group01/1328404806/dataStructure/.settings/org.eclipse.core.resources.prefs
+++ b/group01/1328404806/dataStructure/.settings/org.eclipse.core.resources.prefs
@@ -1,4 +1,4 @@
-eclipse.preferences.version=1
-encoding//src/main/java=UTF-8
-encoding//src/test/java=UTF-8
-encoding/=UTF-8
+eclipse.preferences.version=1
+encoding//src/main/java=UTF-8
+encoding//src/test/java=UTF-8
+encoding/=UTF-8
diff --git a/group01/1328404806/dataStructure/.settings/org.eclipse.jdt.core.prefs b/group01/1328404806/dataStructure/.settings/org.eclipse.jdt.core.prefs
index 8626026241..abec6ca389 100644
--- a/group01/1328404806/dataStructure/.settings/org.eclipse.jdt.core.prefs
+++ b/group01/1328404806/dataStructure/.settings/org.eclipse.jdt.core.prefs
@@ -1,5 +1,5 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
-org.eclipse.jdt.core.compiler.compliance=1.5
-org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
-org.eclipse.jdt.core.compiler.source=1.5
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/group01/1328404806/dataStructure/.settings/org.eclipse.m2e.core.prefs b/group01/1328404806/dataStructure/.settings/org.eclipse.m2e.core.prefs
index 14b697b7bb..f897a7f1cb 100644
--- a/group01/1328404806/dataStructure/.settings/org.eclipse.m2e.core.prefs
+++ b/group01/1328404806/dataStructure/.settings/org.eclipse.m2e.core.prefs
@@ -1,4 +1,4 @@
-activeProfiles=
-eclipse.preferences.version=1
-resolveWorkspaceProjects=true
-version=1
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/group01/1328404806/dataStructure/pom.xml b/group01/1328404806/dataStructure/pom.xml
index 0b5e3a1ca3..c1f7aaf8c2 100644
--- a/group01/1328404806/dataStructure/pom.xml
+++ b/group01/1328404806/dataStructure/pom.xml
@@ -1,25 +1,25 @@
-
- 4.0.0
-
- increaseLearning
- dataStructure
- 0.0.1-SNAPSHOT
- jar
-
- dataStructure
- http://maven.apache.org
-
-
- UTF-8
-
-
-
-
- junit
- junit
- 3.8.1
- test
-
-
-
+
+ 4.0.0
+
+ increaseLearning
+ dataStructure
+ 0.0.1-SNAPSHOT
+ jar
+
+ dataStructure
+ http://maven.apache.org
+
+
+ UTF-8
+
+
+
+
+ junit
+ junit
+ 3.8.1
+ test
+
+
+
diff --git a/group01/1328404806/dataStructure/src/main/java/ListService/KILinkedList.java b/group01/1328404806/dataStructure/src/main/java/ListService/KILinkedList.java
index 8f0307f340..8dc4ecb32b 100644
--- a/group01/1328404806/dataStructure/src/main/java/ListService/KILinkedList.java
+++ b/group01/1328404806/dataStructure/src/main/java/ListService/KILinkedList.java
@@ -1,10 +1,10 @@
-package ListService;
-
-//集合接口
-public interface KILinkedList {
-
- public void add(T t, int pos);
-
- public T remove(int pos);
-
-}
+package ListService;
+
+//集合接口
+public interface KILinkedList {
+
+ public void add(T t, int pos);
+
+ public T remove(int pos);
+
+}
diff --git a/group01/1328404806/dataStructure/src/main/java/ListService/KIList.java b/group01/1328404806/dataStructure/src/main/java/ListService/KIList.java
index b0851d30b0..cad7ff2501 100644
--- a/group01/1328404806/dataStructure/src/main/java/ListService/KIList.java
+++ b/group01/1328404806/dataStructure/src/main/java/ListService/KIList.java
@@ -1,28 +1,28 @@
-package ListService;
-
-//集合接口
-public interface KIList {
-
- public void add(T item);
-
- public void add(int index, T item);
-
- public void set(int index, T item);
-
- public void remove(int index);
-
- public void remove(T item);
-
- public void clear();
-
- public boolean contains(T item);
-
- public boolean isEmpty();
-
- public T get(int index);
-
- public int indexOf(T item);
-
- public int size();
-
-}
+package ListService;
+
+//集合接口
+public interface KIList {
+
+ public void add(T item);
+
+ public void add(int index, T item);
+
+ public void set(int index, T item);
+
+ public void remove(int index);
+
+ public void remove(T item);
+
+ public void clear();
+
+ public boolean contains(T item);
+
+ public boolean isEmpty();
+
+ public T get(int index);
+
+ public int indexOf(T item);
+
+ public int size();
+
+}
diff --git a/group01/1328404806/dataStructure/src/main/java/ListService/KIQueueList.java b/group01/1328404806/dataStructure/src/main/java/ListService/KIQueueList.java
index b02c0e86a5..a6bee9833e 100644
--- a/group01/1328404806/dataStructure/src/main/java/ListService/KIQueueList.java
+++ b/group01/1328404806/dataStructure/src/main/java/ListService/KIQueueList.java
@@ -1,11 +1,11 @@
-package ListService;
-
-//集合接口
-public interface KIQueueList {
- public T add(T ele);
-
- public T remove();
-
- public Object[] getData();
-
-}
+package ListService;
+
+//集合接口
+public interface KIQueueList {
+ public T add(T ele);
+
+ public T remove();
+
+ public Object[] getData();
+
+}
diff --git a/group01/1328404806/dataStructure/src/main/java/ListService/KIStackList.java b/group01/1328404806/dataStructure/src/main/java/ListService/KIStackList.java
index 8a1f031976..1734852fe6 100644
--- a/group01/1328404806/dataStructure/src/main/java/ListService/KIStackList.java
+++ b/group01/1328404806/dataStructure/src/main/java/ListService/KIStackList.java
@@ -1,9 +1,9 @@
-package ListService;
-
-//集合接口
-public interface KIStackList {
- public void push(T ele);
-
- public void pop();
-
-}
+package ListService;
+
+//集合接口
+public interface KIStackList {
+ public void push(T ele);
+
+ public void pop();
+
+}
diff --git a/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KArrayList.java b/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KArrayList.java
index d85a8957cf..6d7a4ab354 100644
--- a/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KArrayList.java
+++ b/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KArrayList.java
@@ -1,192 +1,192 @@
-package ListServiceImpl;
-
-import ListService.KIList;
-
-public class KArrayList implements KIList {
-
- /** 初始化的容量的大小 */
- private final static int INIT_CAPACITY = 12;
- private Object[] mList = null;
-
- /** 当前的容量 */
- private int mCurrentCapacity = 0;
- /** 容器中元素的个数 */
- private int mSize = 0;
-
- public KArrayList() {
- mList = new Object[INIT_CAPACITY];
- mCurrentCapacity = INIT_CAPACITY;
- }
-
- /**
- * 插入一个元素到链表尾部
- *
- * @param item
- */
- public void add(T item) {
- if (mSize == mCurrentCapacity) {
- expansion();
- }
- mList[mSize] = item;
- mSize++;
-
- }
-
- /**
- * 插入一个元素到指定位置,从插入位置及其后面的元素往后移动一个位置
- *
- * @param index
- * 要插入的位置
- * @param item
- */
- public void add(int index, T item) {
- if (index < 0 || index >= mSize) { // 不允许index小于0,或者index >= 数组当前大小
- throw new IndexOutOfBoundsException();
- }
- if (mSize == mCurrentCapacity) {
- expansion();
- }
- Object[] newList = new Object[mCurrentCapacity];
- System.arraycopy(mList, 0, newList, 0, index);
- System.arraycopy(mList, index, newList, index + 1, mSize - index);
- newList[index] = item;
- mList = newList;
- mSize++;
-
- }
-
- /**
- * 更新指定位置的元素
- *
- * @param index
- * @param item
- */
- public void set(int index, T item) {
- if (index < 0 || index >= mSize) {
- throw new IndexOutOfBoundsException();
- }
- mList[index] = item;
-
- }
-
- /**
- * 移除指定位置的元素,后面的元素向前移动一位
- *
- * @param index
- */
- public void remove(int index) {
- if (index < 0 || index >= mSize) {
- throw new IndexOutOfBoundsException();
- }
- Object[] newList = new Object[mCurrentCapacity];
- System.arraycopy(mList, 0, newList, 0, index);
- System.arraycopy(mList, index + 1, newList, index, mSize - index);
- mList = newList;
- mSize--;
-
- }
-
- /**
- * 移除链表中特定的元素。(如果item在链表中有多个,只移除第一个)
- *
- * @param item
- */
- public void remove(T item) {
- for (int i = 0; i < mSize; i++) {
- if (mList[i].equals(item)) {
- remove(i);
- break;
- }
- }
-
- }
-
- /**
- * 将链表清空,capacity不变
- */
- public void clear() {
- mList = new Object[mCurrentCapacity];
- mSize = 0;
-
- }
-
- /**
- * 判断是否包含某个元素
- *
- * @param item
- * @return true表示有这个元素,false表示没有这个元素
- */
- public boolean contains(T item) {
- for (int i = 0; i < mSize; i++) {
- if (mList[i].equals(item)) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * 判断链表是否为空
- *
- * @return boolean
- */
- public boolean isEmpty() {
- return (mSize == 0) ? true : false;
- }
-
- /**
- * 获取指定位置的元素
- *
- * @param index
- * @return
- */
- @SuppressWarnings("unchecked")
- public T get(int index) {
- if (index < 0 || index >= mSize) {
- throw new IndexOutOfBoundsException();
- }
- return (T) mList[index];
- }
-
- /**
- * 获取特定元素所在的位置。 如果该链表中存在多个相同的元素,只返回第一个的位置,如果找不到,则返回-1。
- *
- * @param item
- * @return int 如果没找到,返回-1
- */
- public int indexOf(T item) {
- for (int i = 0; i < mSize; i++) {
- if (mList[i].equals(item)) {
- return i;
- }
- }
- return -1;
- }
-
- /**
- * 获取当前链表的长度
- *
- * @return int
- */
- public int size() {
- return mSize;
- }
-
- /**
- * 扩容,当 mSize == mCurrentCapacity 时调用
- */
- private void expansion() {
- Object[] oldList = mList;
- Object[] newList = new Object[getNewCapacity()];
- System.arraycopy(oldList, 0, newList, 0, oldList.length);
- mList = newList;
- }
-
- /**
- * 获取新的容量大小 当满的时候每次增加当前容量的50%
- */
- private int getNewCapacity() {
- return mCurrentCapacity = mCurrentCapacity + (mCurrentCapacity >> 1);
- }
-
-}
+package ListServiceImpl;
+
+import ListService.KIList;
+
+public class KArrayList implements KIList {
+
+ /** 初始化的容量的大小 */
+ private final static int INIT_CAPACITY = 12;
+ private Object[] mList = null;
+
+ /** 当前的容量 */
+ private int mCurrentCapacity = 0;
+ /** 容器中元素的个数 */
+ private int mSize = 0;
+
+ public KArrayList() {
+ mList = new Object[INIT_CAPACITY];
+ mCurrentCapacity = INIT_CAPACITY;
+ }
+
+ /**
+ * 插入一个元素到链表尾部
+ *
+ * @param item
+ */
+ public void add(T item) {
+ if (mSize == mCurrentCapacity) {
+ expansion();
+ }
+ mList[mSize] = item;
+ mSize++;
+
+ }
+
+ /**
+ * 插入一个元素到指定位置,从插入位置及其后面的元素往后移动一个位置
+ *
+ * @param index
+ * 要插入的位置
+ * @param item
+ */
+ public void add(int index, T item) {
+ if (index < 0 || index >= mSize) { // 不允许index小于0,或者index >= 数组当前大小
+ throw new IndexOutOfBoundsException();
+ }
+ if (mSize == mCurrentCapacity) {
+ expansion();
+ }
+ Object[] newList = new Object[mCurrentCapacity];
+ System.arraycopy(mList, 0, newList, 0, index);
+ System.arraycopy(mList, index, newList, index + 1, mSize - index);
+ newList[index] = item;
+ mList = newList;
+ mSize++;
+
+ }
+
+ /**
+ * 更新指定位置的元素
+ *
+ * @param index
+ * @param item
+ */
+ public void set(int index, T item) {
+ if (index < 0 || index >= mSize) {
+ throw new IndexOutOfBoundsException();
+ }
+ mList[index] = item;
+
+ }
+
+ /**
+ * 移除指定位置的元素,后面的元素向前移动一位
+ *
+ * @param index
+ */
+ public void remove(int index) {
+ if (index < 0 || index >= mSize) {
+ throw new IndexOutOfBoundsException();
+ }
+ Object[] newList = new Object[mCurrentCapacity];
+ System.arraycopy(mList, 0, newList, 0, index);
+ System.arraycopy(mList, index + 1, newList, index, mSize - index);
+ mList = newList;
+ mSize--;
+
+ }
+
+ /**
+ * 移除链表中特定的元素。(如果item在链表中有多个,只移除第一个)
+ *
+ * @param item
+ */
+ public void remove(T item) {
+ for (int i = 0; i < mSize; i++) {
+ if (mList[i].equals(item)) {
+ remove(i);
+ break;
+ }
+ }
+
+ }
+
+ /**
+ * 将链表清空,capacity不变
+ */
+ public void clear() {
+ mList = new Object[mCurrentCapacity];
+ mSize = 0;
+
+ }
+
+ /**
+ * 判断是否包含某个元素
+ *
+ * @param item
+ * @return true表示有这个元素,false表示没有这个元素
+ */
+ public boolean contains(T item) {
+ for (int i = 0; i < mSize; i++) {
+ if (mList[i].equals(item)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * 判断链表是否为空
+ *
+ * @return boolean
+ */
+ public boolean isEmpty() {
+ return (mSize == 0) ? true : false;
+ }
+
+ /**
+ * 获取指定位置的元素
+ *
+ * @param index
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ public T get(int index) {
+ if (index < 0 || index >= mSize) {
+ throw new IndexOutOfBoundsException();
+ }
+ return (T) mList[index];
+ }
+
+ /**
+ * 获取特定元素所在的位置。 如果该链表中存在多个相同的元素,只返回第一个的位置,如果找不到,则返回-1。
+ *
+ * @param item
+ * @return int 如果没找到,返回-1
+ */
+ public int indexOf(T item) {
+ for (int i = 0; i < mSize; i++) {
+ if (mList[i].equals(item)) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ /**
+ * 获取当前链表的长度
+ *
+ * @return int
+ */
+ public int size() {
+ return mSize;
+ }
+
+ /**
+ * 扩容,当 mSize == mCurrentCapacity 时调用
+ */
+ private void expansion() {
+ Object[] oldList = mList;
+ Object[] newList = new Object[getNewCapacity()];
+ System.arraycopy(oldList, 0, newList, 0, oldList.length);
+ mList = newList;
+ }
+
+ /**
+ * 获取新的容量大小 当满的时候每次增加当前容量的50%
+ */
+ private int getNewCapacity() {
+ return mCurrentCapacity = mCurrentCapacity + (mCurrentCapacity >> 1);
+ }
+
+}
diff --git a/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KLinkedList.java b/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KLinkedList.java
index 6afb12befc..cf158d2399 100644
--- a/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KLinkedList.java
+++ b/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KLinkedList.java
@@ -1,201 +1,201 @@
-package ListServiceImpl;
-
-import java.util.Iterator;
-
-import ListService.KILinkedList;
-
-public class KLinkedList implements Iterable, KILinkedList {
-
- // 记录链表的长度
- private int mSize = 0;
- // private int mActionCount = 0;
- // 开始和结束节点
- private Node mBeginNode, mLastNode;
-
- public KLinkedList() {
- // TODO Auto-generated constructor stub
- init();
- }
-
- /**
- * 初始化一个只有开始节点和结束节点的空链表
- */
- private void init() {
- // 将首位节点链接起来
- mBeginNode = new Node(null, null, null);
- mLastNode = new Node(null, mBeginNode, null);
- mBeginNode.nextNode = mLastNode;
- mSize = 0;
- // mActionCount++;
- }
-
- public int size() {
- return mSize;
- }
-
- public boolean isEmpty() {
- return mSize == 0 ? true : false;
- }
-
- /**
- * 在链表的pos位置之前放置t_node这个节点
- *
- * @param t_node
- * 需要放置的节点
- * @param pos
- * 放置节点在pos之前
- */
- private void add(Node newNode, int pos) {
- // 抛出不合法的位置
- if (pos < 0 || pos > mSize) {
- throw new IndexOutOfBoundsException();
- }
-
- // 链接新节点
- newNode.nextNode = getNode(pos);
- getNode(pos - 1).nextNode = newNode;
- getNode(pos).preNode = newNode;
- // mActionCount++;
- mSize++;
-
- }
-
- /**
- * t 供外部调用,直接在链表的末尾添加,即在mLastNode节点之前
- *
- * @param
- */
- public void add(T t) {
- add(new Node(t, null, null), mSize);
- }
-
- /**
- * 往链表pos位置之前添加数据t
- *
- * @param t
- * 添加的数据
- * @param pos
- * 添加在pos位置之前
- */
- public void add(T t, int pos) {
- add(new Node(t, null, null), pos);
- }
-
- /**
- *
- * @param pos
- * 链表中的某个位置
- * @return 翻去pos位置的节点 (此处的pos的范围是[-1,mSize],此方法是私有方法,外部访问不了,只共此类中呢个访问)
- */
- private Node getNode(int pos) {
- Node node;
- int currentPos;
- if (pos == -1) {
- // -1的位置是开始节点
- return mBeginNode;
- } else if (pos == mSize) {
- // mSize的位置是结束的节点
- return mLastNode;
- }
- // 因为这是双向节点,所以判断一下能提高搜索效率
- if (pos < mSize / 2) {
- currentPos = 0;
- node = mBeginNode.nextNode;
- while (currentPos < pos) {
- node = node.nextNode;
- currentPos++;
- }
- } else {
- node = mLastNode.preNode;
- currentPos = mSize - 1;
- while (currentPos > pos) {
- node = node.preNode;
- currentPos--;
- }
- }
- return node;
- }
-
- public T get(int pos) {
- return getNode(pos).t;
- }
-
- public void set(T t, int pos) {
- if (pos < 0 || pos >= mSize) {
- throw new IndexOutOfBoundsException();
- }
- getNode(pos).t = t;
- }
-
- /**
- * 删除特定位置的节点
- *
- * @param t_node
- * 需要删除节点的位置
- * @return
- */
- private T remove(Node t_node) {
-
- t_node.preNode.nextNode = t_node.nextNode;
- t_node.nextNode.preNode = t_node.preNode;
- // 最好在此处给其设置为空,不要其链接到其他节点,因为已经被销毁,不再持有其他的节点的引用
- t_node.nextNode = null;
- t_node.preNode = null;
- mSize--;
- // mActionCount++;
- return t_node.t;
- }
-
- public T remove(int pos) {
- if (pos < 0 || pos >= mSize) {
- throw new IndexOutOfBoundsException();
- }
- Node tempNode = getNode(pos);
- remove(tempNode);
- return tempNode.t;
- }
-
- public Iterator iterator() {
-
- return new MyLinkedListIterator();
- }
-
- private class MyLinkedListIterator implements Iterator {
-
- private int currentPos = 0;
-
- public boolean hasNext() {
- // TODO Auto-generated method stub
- if (currentPos < mSize) {
- return true;
- }
- return false;
- }
-
- public T next() {
- // TODO Auto-generated method stub
- return (T) getNode(currentPos++).t;
- }
-
- public void remove() {
- // TODO Auto-generated method stub
- KLinkedList.this.remove(getNode(--currentPos));
- ;
- }
-
- }
-
- // 静态内部类,定义的节点,双向链表,需要一个指向前面一项的引用域和一个指向后面一项的引用域,方便查找
- private static class Node {
- public T t;
- public Node preNode;
- public Node nextNode;
-
- public Node(T t, Node preNode, Node nextNode) {
- this.preNode = preNode;
- this.nextNode = nextNode;
- this.t = t;
- }
- }
-
-}
+package ListServiceImpl;
+
+import java.util.Iterator;
+
+import ListService.KILinkedList;
+
+public class KLinkedList implements Iterable, KILinkedList {
+
+ // 记录链表的长度
+ private int mSize = 0;
+ // private int mActionCount = 0;
+ // 开始和结束节点
+ private Node mBeginNode, mLastNode;
+
+ public KLinkedList() {
+ // TODO Auto-generated constructor stub
+ init();
+ }
+
+ /**
+ * 初始化一个只有开始节点和结束节点的空链表
+ */
+ private void init() {
+ // 将首位节点链接起来
+ mBeginNode = new Node(null, null, null);
+ mLastNode = new Node(null, mBeginNode, null);
+ mBeginNode.nextNode = mLastNode;
+ mSize = 0;
+ // mActionCount++;
+ }
+
+ public int size() {
+ return mSize;
+ }
+
+ public boolean isEmpty() {
+ return mSize == 0 ? true : false;
+ }
+
+ /**
+ * 在链表的pos位置之前放置t_node这个节点
+ *
+ * @param t_node
+ * 需要放置的节点
+ * @param pos
+ * 放置节点在pos之前
+ */
+ private void add(Node newNode, int pos) {
+ // 抛出不合法的位置
+ if (pos < 0 || pos > mSize) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ // 链接新节点
+ newNode.nextNode = getNode(pos);
+ getNode(pos - 1).nextNode = newNode;
+ getNode(pos).preNode = newNode;
+ // mActionCount++;
+ mSize++;
+
+ }
+
+ /**
+ * t 供外部调用,直接在链表的末尾添加,即在mLastNode节点之前
+ *
+ * @param
+ */
+ public void add(T t) {
+ add(new Node(t, null, null), mSize);
+ }
+
+ /**
+ * 往链表pos位置之前添加数据t
+ *
+ * @param t
+ * 添加的数据
+ * @param pos
+ * 添加在pos位置之前
+ */
+ public void add(T t, int pos) {
+ add(new Node(t, null, null), pos);
+ }
+
+ /**
+ *
+ * @param pos
+ * 链表中的某个位置
+ * @return 翻去pos位置的节点 (此处的pos的范围是[-1,mSize],此方法是私有方法,外部访问不了,只共此类中呢个访问)
+ */
+ private Node getNode(int pos) {
+ Node node;
+ int currentPos;
+ if (pos == -1) {
+ // -1的位置是开始节点
+ return mBeginNode;
+ } else if (pos == mSize) {
+ // mSize的位置是结束的节点
+ return mLastNode;
+ }
+ // 因为这是双向节点,所以判断一下能提高搜索效率
+ if (pos < mSize / 2) {
+ currentPos = 0;
+ node = mBeginNode.nextNode;
+ while (currentPos < pos) {
+ node = node.nextNode;
+ currentPos++;
+ }
+ } else {
+ node = mLastNode.preNode;
+ currentPos = mSize - 1;
+ while (currentPos > pos) {
+ node = node.preNode;
+ currentPos--;
+ }
+ }
+ return node;
+ }
+
+ public T get(int pos) {
+ return getNode(pos).t;
+ }
+
+ public void set(T t, int pos) {
+ if (pos < 0 || pos >= mSize) {
+ throw new IndexOutOfBoundsException();
+ }
+ getNode(pos).t = t;
+ }
+
+ /**
+ * 删除特定位置的节点
+ *
+ * @param t_node
+ * 需要删除节点的位置
+ * @return
+ */
+ private T remove(Node t_node) {
+
+ t_node.preNode.nextNode = t_node.nextNode;
+ t_node.nextNode.preNode = t_node.preNode;
+ // 最好在此处给其设置为空,不要其链接到其他节点,因为已经被销毁,不再持有其他的节点的引用
+ t_node.nextNode = null;
+ t_node.preNode = null;
+ mSize--;
+ // mActionCount++;
+ return t_node.t;
+ }
+
+ public T remove(int pos) {
+ if (pos < 0 || pos >= mSize) {
+ throw new IndexOutOfBoundsException();
+ }
+ Node tempNode = getNode(pos);
+ remove(tempNode);
+ return tempNode.t;
+ }
+
+ public Iterator iterator() {
+
+ return new MyLinkedListIterator();
+ }
+
+ private class MyLinkedListIterator implements Iterator {
+
+ private int currentPos = 0;
+
+ public boolean hasNext() {
+ // TODO Auto-generated method stub
+ if (currentPos < mSize) {
+ return true;
+ }
+ return false;
+ }
+
+ public T next() {
+ // TODO Auto-generated method stub
+ return (T) getNode(currentPos++).t;
+ }
+
+ public void remove() {
+ // TODO Auto-generated method stub
+ KLinkedList.this.remove(getNode(--currentPos));
+ ;
+ }
+
+ }
+
+ // 静态内部类,定义的节点,双向链表,需要一个指向前面一项的引用域和一个指向后面一项的引用域,方便查找
+ private static class Node {
+ public T t;
+ public Node preNode;
+ public Node nextNode;
+
+ public Node(T t, Node preNode, Node nextNode) {
+ this.preNode = preNode;
+ this.nextNode = nextNode;
+ this.t = t;
+ }
+ }
+
+}
diff --git a/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KQueueList.java b/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KQueueList.java
index 7ea8643c43..1e389ae1ef 100644
--- a/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KQueueList.java
+++ b/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KQueueList.java
@@ -1,97 +1,97 @@
-package ListServiceImpl;
-
-import java.util.Arrays;
-import java.util.Collection;
-
-import ListService.KIQueueList;
-
-public class KQueueList implements KIQueueList{
-
- /** 初始容量 */
- public static final int DEFAULT_SIZE = 10;
- /** 容量不足时翻倍数 */
- public static final float DEFAULT_INCREMENT = 1.5f;
- /** 数据 */
- private Object[] elementData;
- /** 元素个数 */
- private int elementCount;
- /** 数组的头部,即 下次删除数据的 index */
- private int head;
- /** 数组的尾部,即 下次插入数据的 index */
- private int tail;
-
- public KQueueList() {
- this(DEFAULT_SIZE);
- }
-
- public KQueueList(int size) {
- this.elementData = new Object[size];
- this.elementCount = 0;
- this.head = 0;
- this.tail = 0;
- }
-
- public KQueueList(Object[] data) {
- this.elementData = data;
- this.elementCount = data.length;
- this.head = 0;
- this.tail = 0;
- }
-
- public KQueueList(Collection extends T> c) {
- this(c.toArray());
- }
-
- /**
- * 添加数据 到尾部
- *
- * @param ele
- * @return
- */
- public T add(T ele) {
- if (tail >= elementData.length) {
- adjustData();
- }
- elementData[tail] = ele;
- elementCount++;
- tail++;
- return ele;
- };
-
- /**
- * 删除数据 从头部
- *
- * @return
- */
- @SuppressWarnings("unchecked")
- public T remove() {
- T e = (T) elementData[head];
- elementData[head] = null;
- elementCount--;
- head++;
- return e;
- };
-
- /**
- * 获得当前的数据
- *
- * @return
- */
- public Object[] getData() {
- return Arrays.copyOfRange(this.elementData, this.head, this.tail);
- }
-
- public void adjustData() {
- if (tail >= elementData.length) { // tail 处空间不足时调用
- // head 的空位去掉
- int newSize = (elementData.length == elementCount) ? (int) Math.ceil(elementCount * DEFAULT_INCREMENT)
- : elementData.length;
- elementData = Arrays.copyOfRange(elementData, head, elementData.length);
- // 调整空间
- elementData = Arrays.copyOf(elementData, newSize);
- tail = elementCount;
- head = 0;
- }
- }
-
-}
+package ListServiceImpl;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import ListService.KIQueueList;
+
+public class KQueueList implements KIQueueList{
+
+ /** 初始容量 */
+ public static final int DEFAULT_SIZE = 10;
+ /** 容量不足时翻倍数 */
+ public static final float DEFAULT_INCREMENT = 1.5f;
+ /** 数据 */
+ private Object[] elementData;
+ /** 元素个数 */
+ private int elementCount;
+ /** 数组的头部,即 下次删除数据的 index */
+ private int head;
+ /** 数组的尾部,即 下次插入数据的 index */
+ private int tail;
+
+ public KQueueList() {
+ this(DEFAULT_SIZE);
+ }
+
+ public KQueueList(int size) {
+ this.elementData = new Object[size];
+ this.elementCount = 0;
+ this.head = 0;
+ this.tail = 0;
+ }
+
+ public KQueueList(Object[] data) {
+ this.elementData = data;
+ this.elementCount = data.length;
+ this.head = 0;
+ this.tail = 0;
+ }
+
+ public KQueueList(Collection extends T> c) {
+ this(c.toArray());
+ }
+
+ /**
+ * 添加数据 到尾部
+ *
+ * @param ele
+ * @return
+ */
+ public T add(T ele) {
+ if (tail >= elementData.length) {
+ adjustData();
+ }
+ elementData[tail] = ele;
+ elementCount++;
+ tail++;
+ return ele;
+ };
+
+ /**
+ * 删除数据 从头部
+ *
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ public T remove() {
+ T e = (T) elementData[head];
+ elementData[head] = null;
+ elementCount--;
+ head++;
+ return e;
+ };
+
+ /**
+ * 获得当前的数据
+ *
+ * @return
+ */
+ public Object[] getData() {
+ return Arrays.copyOfRange(this.elementData, this.head, this.tail);
+ }
+
+ public void adjustData() {
+ if (tail >= elementData.length) { // tail 处空间不足时调用
+ // head 的空位去掉
+ int newSize = (elementData.length == elementCount) ? (int) Math.ceil(elementCount * DEFAULT_INCREMENT)
+ : elementData.length;
+ elementData = Arrays.copyOfRange(elementData, head, elementData.length);
+ // 调整空间
+ elementData = Arrays.copyOf(elementData, newSize);
+ tail = elementCount;
+ head = 0;
+ }
+ }
+
+}
diff --git a/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KStackList.java b/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KStackList.java
index e2b9ee1186..3b252cd7f4 100644
--- a/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KStackList.java
+++ b/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KStackList.java
@@ -1,48 +1,48 @@
-package ListServiceImpl;
-
-import java.util.Arrays;
-
-import ListService.KIStackList;
-
-public class KStackList implements KIStackList{
- Object[] data;
- private int capacity;
- private int size;
-
- public KStackList()
- {
- capacity=16;
- size=0;
- data=new Object[capacity];
- }
-
- public void ensureCapacity() {
- capacity = capacity * 2;
- data = Arrays.copyOf(data, capacity);
- }
-
- //压入栈底
- public void push(T ele) {
- if (size < capacity) {
- data[size++] = ele;
- } else {
- ensureCapacity();
- data[size++] = ele;
- }
- }
-
- //弹出
- public void pop() {
- if (size > 0) {
- System.out.println(data[size - 1]);
- data[--size] = null;
- } else {
- System.out.println("Empty stack!");
- }
- }
-
- boolean isEmpty() {
- return size == 0;
- }
-
-}
+package ListServiceImpl;
+
+import java.util.Arrays;
+
+import ListService.KIStackList;
+
+public class KStackList implements KIStackList{
+ Object[] data;
+ private int capacity;
+ private int size;
+
+ public KStackList()
+ {
+ capacity=16;
+ size=0;
+ data=new Object[capacity];
+ }
+
+ public void ensureCapacity() {
+ capacity = capacity * 2;
+ data = Arrays.copyOf(data, capacity);
+ }
+
+ //压入栈底
+ public void push(T ele) {
+ if (size < capacity) {
+ data[size++] = ele;
+ } else {
+ ensureCapacity();
+ data[size++] = ele;
+ }
+ }
+
+ //弹出
+ public void pop() {
+ if (size > 0) {
+ System.out.println(data[size - 1]);
+ data[--size] = null;
+ } else {
+ System.out.println("Empty stack!");
+ }
+ }
+
+ boolean isEmpty() {
+ return size == 0;
+ }
+
+}
diff --git a/group01/1328404806/dataStructure/src/main/java/increaseLearning/dataStructure/App.java b/group01/1328404806/dataStructure/src/main/java/increaseLearning/dataStructure/App.java
index 018ba70bdb..2787ea64f4 100644
--- a/group01/1328404806/dataStructure/src/main/java/increaseLearning/dataStructure/App.java
+++ b/group01/1328404806/dataStructure/src/main/java/increaseLearning/dataStructure/App.java
@@ -1,13 +1,13 @@
-package increaseLearning.dataStructure;
-
-/**
- * Hello world!
- *
- */
-public class App
-{
- public static void main( String[] args )
- {
- System.out.println( "Hello World!" );
- }
-}
+package increaseLearning.dataStructure;
+
+/**
+ * Hello world!
+ *
+ */
+public class App
+{
+ public static void main( String[] args )
+ {
+ System.out.println( "Hello World!" );
+ }
+}
diff --git a/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/AppTest.java b/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/AppTest.java
index 4fffcb78ed..e717bddafe 100644
--- a/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/AppTest.java
+++ b/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/AppTest.java
@@ -1,38 +1,38 @@
-package increaseLearning.dataStructure;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Unit test for simple App.
- */
-public class AppTest
- extends TestCase
-{
- /**
- * Create the test case
- *
- * @param testName name of the test case
- */
- public AppTest( String testName )
- {
- super( testName );
- }
-
- /**
- * @return the suite of tests being tested
- */
- public static Test suite()
- {
- return new TestSuite( AppTest.class );
- }
-
- /**
- * Rigourous Test :-)
- */
- public void testApp()
- {
- assertTrue( true );
- }
-}
+package increaseLearning.dataStructure;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest
+ extends TestCase
+{
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public AppTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite()
+ {
+ return new TestSuite( AppTest.class );
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testApp()
+ {
+ assertTrue( true );
+ }
+}
diff --git a/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/arrayListTest.java b/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/arrayListTest.java
index 3815775989..a9d55fd05b 100644
--- a/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/arrayListTest.java
+++ b/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/arrayListTest.java
@@ -1,36 +1,36 @@
-package increaseLearning.dataStructure;
-
-
-import org.junit.Test;
-
-import ListServiceImpl.KArrayList;
-import junit.framework.TestCase;
-
-public class arrayListTest extends TestCase {
- @Test
- public void testArrayList() {
-
- KArrayList arr = new KArrayList();
-
- for (int i = 1; i <= 50; i++) {
- arr.add(i);
- }
-
- arr.add(10, 99);
- arr.add(0, 99);
-
- System.out.println(arr.get(51));
- System.out.println(arr.get(11));
-
- // arr.clear();
-
- // System.out.println(arr.contains(99));
- // System.out.println(arr.indexOf(59));
-
- arr.remove(11);
-
- arr = null;
-
- }
-
-}
+package increaseLearning.dataStructure;
+
+
+import org.junit.Test;
+
+import ListServiceImpl.KArrayList;
+import junit.framework.TestCase;
+
+public class arrayListTest extends TestCase {
+ @Test
+ public void testArrayList() {
+
+ KArrayList arr = new KArrayList();
+
+ for (int i = 1; i <= 50; i++) {
+ arr.add(i);
+ }
+
+ arr.add(10, 99);
+ arr.add(0, 99);
+
+ System.out.println(arr.get(51));
+ System.out.println(arr.get(11));
+
+ // arr.clear();
+
+ // System.out.println(arr.contains(99));
+ // System.out.println(arr.indexOf(59));
+
+ arr.remove(11);
+
+ arr = null;
+
+ }
+
+}
diff --git a/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/linkedListTest.java b/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/linkedListTest.java
index 6b42a261fa..2c0d0554f6 100644
--- a/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/linkedListTest.java
+++ b/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/linkedListTest.java
@@ -1,21 +1,21 @@
-package increaseLearning.dataStructure;
-
-import org.junit.Test;
-
-import ListServiceImpl.KLinkedList;
-import junit.framework.TestCase;
-
-public class linkedListTest extends TestCase{
- @Test
- public void testLinkedList(){
- KLinkedList linkList=new KLinkedList();
-
-
- linkList.add(3, 0);
-
- System.out.println(linkList.get(0));
-// System.out.println("成功!!!");
-
- }
-
-}
+package increaseLearning.dataStructure;
+
+import org.junit.Test;
+
+import ListServiceImpl.KLinkedList;
+import junit.framework.TestCase;
+
+public class linkedListTest extends TestCase{
+ @Test
+ public void testLinkedList(){
+ KLinkedList linkList=new KLinkedList();
+
+
+ linkList.add(3, 0);
+
+ System.out.println(linkList.get(0));
+// System.out.println("成功!!!");
+
+ }
+
+}
diff --git a/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/queueListTest.java b/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/queueListTest.java
index af4f952f6c..274faf5b83 100644
--- a/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/queueListTest.java
+++ b/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/queueListTest.java
@@ -1,42 +1,42 @@
-package increaseLearning.dataStructure;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import ListServiceImpl.KQueueList;
-import junit.framework.TestCase;
-
-public class queueListTest extends TestCase {
- @Test
- public void testQueueList() {
- KQueueList queueOne = new KQueueList();
- // 第1次 加入个数
- int addCountOne = 30;
- // 第1次 删除个数
- int removeCountOne = 20;
- // 第2次 加入个数
- int addCountTwo = 10;
-
- for (int i = 0; i < addCountOne; i++) {
- queueOne.add(i);
- }
- Object[] data = queueOne.getData();
- for (int i = 0; i < data.length; i++) {
- Assert.assertTrue((Integer) data[i] == i);
- }
-
- for (int i = 0; i < removeCountOne; i++) {
- Assert.assertTrue(queueOne.remove() == i);
- }
-
- for (int i = 0; i < addCountTwo; i++) {
- queueOne.add(i * 10);
- }
- Object[] data2 = queueOne.getData();
- int baseCount = addCountOne - removeCountOne;
- for (int i = 0; i < addCountTwo; i++) {
- Assert.assertTrue((Integer) data2[baseCount + i] == i * 10);
- }
- }
-
-}
+package increaseLearning.dataStructure;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import ListServiceImpl.KQueueList;
+import junit.framework.TestCase;
+
+public class queueListTest extends TestCase {
+ @Test
+ public void testQueueList() {
+ KQueueList queueOne = new KQueueList();
+ // 第1次 加入个数
+ int addCountOne = 30;
+ // 第1次 删除个数
+ int removeCountOne = 20;
+ // 第2次 加入个数
+ int addCountTwo = 10;
+
+ for (int i = 0; i < addCountOne; i++) {
+ queueOne.add(i);
+ }
+ Object[] data = queueOne.getData();
+ for (int i = 0; i < data.length; i++) {
+ Assert.assertTrue((Integer) data[i] == i);
+ }
+
+ for (int i = 0; i < removeCountOne; i++) {
+ Assert.assertTrue(queueOne.remove() == i);
+ }
+
+ for (int i = 0; i < addCountTwo; i++) {
+ queueOne.add(i * 10);
+ }
+ Object[] data2 = queueOne.getData();
+ int baseCount = addCountOne - removeCountOne;
+ for (int i = 0; i < addCountTwo; i++) {
+ Assert.assertTrue((Integer) data2[baseCount + i] == i * 10);
+ }
+ }
+
+}
diff --git a/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/stackListTest.java b/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/stackListTest.java
index 614f18cb8c..50ad4c0a3e 100644
--- a/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/stackListTest.java
+++ b/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/stackListTest.java
@@ -1,26 +1,26 @@
-package increaseLearning.dataStructure;
-
-import org.junit.Test;
-
-import ListServiceImpl.KStackList;
-import junit.framework.TestCase;
-
-public class stackListTest extends TestCase{
- @Test
- public void testStackList(){
- KStackList fcStack=new KStackList();
- for(int i=0;i<10;i++)
- {
- fcStack.push(i);
- System.out.println(fcStack);
- }
-
- for(int i=0;i<10;i++)
- {
- fcStack.pop();
- System.out.println(fcStack);
- }
- fcStack.pop();
- }
-
-}
+package increaseLearning.dataStructure;
+
+import org.junit.Test;
+
+import ListServiceImpl.KStackList;
+import junit.framework.TestCase;
+
+public class stackListTest extends TestCase{
+ @Test
+ public void testStackList(){
+ KStackList fcStack=new KStackList();
+ for(int i=0;i<10;i++)
+ {
+ fcStack.push(i);
+ System.out.println(fcStack);
+ }
+
+ for(int i=0;i<10;i++)
+ {
+ fcStack.pop();
+ System.out.println(fcStack);
+ }
+ fcStack.pop();
+ }
+
+}
diff --git a/group01/1664823950/.project b/group01/1664823950/.project
index 14ce66b1b3..6cca5cf64b 100644
--- a/group01/1664823950/.project
+++ b/group01/1664823950/.project
@@ -1,6 +1,10 @@
+<<<<<<< HEAD:group01/1664823950/.project
1664823950
+=======
+ 1264835468
+>>>>>>> master:group17/1264835468/.project
diff --git a/group01/1664823950/src/com/coderising/array/ArrayUtil.java b/group01/1664823950/src/com/coderising/array/ArrayUtil.java
new file mode 100644
index 0000000000..56a86160f4
--- /dev/null
+++ b/group01/1664823950/src/com/coderising/array/ArrayUtil.java
@@ -0,0 +1,209 @@
+package com.coderising.array;
+import java.util.*;
+
+import com.sun.org.apache.bcel.internal.generic.NEWARRAY;
+
+public class ArrayUtil {
+
+ /**
+ * 给定一个整形数组a , 对该数组的值进行置换
+ 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7]
+ 如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7]
+ * @param origin
+ * @return
+ */
+ public void reverseArray(int[] origin)
+ {
+ int[] a = origin;
+ for (int i = 0; i < a.length; i++)
+ {
+ origin[i] = a[a.length-i];
+ }
+ }
+
+ /**
+ * 现在有如下的一个数组: int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5}
+ * 要求将以上数组中值为0的项去掉,将不为0的值存入一个新的数组,生成的新数组为:
+ * {1,3,4,5,6,6,5,4,7,6,7,5}
+ * @param oldArray
+ * @return
+ */
+
+ public int[] removeZero(int[] oldArray)
+ {
+ ArrayList a= new ArrayList();
+
+ for (int i : oldArray)
+ {
+ if (i != 0)
+ {
+ a.add(i);
+ }
+ }
+
+ int[] newArray = new int[a.size()];
+ for (int i = 0; i < a.size(); i++)
+ {
+ newArray[i] = a.get(i);
+ }
+ return null;
+ }
+
+ /**
+ * 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的
+ * 例如 a1 = [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复
+ * @param array1
+ * @param array2
+ * @return
+ */
+
+ public int[] merge(int[] array1, int[] array2)
+ {
+ for (int i = 0; i < array1.length; i++)
+ {
+ for (int j = 0; j < array2.length; j++)
+ {
+ if(array1[i] == array2[j])
+ {
+ array2[j] = 0;
+ }
+ }
+ }
+
+ removeZero(array2);
+
+ int[] array3 = new int[array1.length + array2.length];
+
+ for (int i = 0; i < array1.length; i++)
+ {
+ array3[i] = array1[i];
+ }
+
+ for (int i = 0; i < array2.length; i++)
+ {
+ array3[array1.length + i] = array2[i];
+ }
+
+ Arrays.sort(array3);
+ return array3;
+ }
+ /**
+ * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
+ * 注意,老数组的元素在新数组中需要保持
+ * 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
+ * [2,3,6,0,0,0]
+ * @param oldArray
+ * @param size
+ * @return
+ */
+ public int[] grow(int [] oldArray, int size)
+ {
+ return new int[oldArray.length + size];
+ }
+
+ /**
+ * 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列
+ * 例如, max = 15 , 则返回的数组应该为 [1,1,2,3,5,8,13]
+ * max = 1, 则返回空数组 []
+ * @param max
+ * @return
+ */
+ public int[] fibonacci(int max)
+ {
+ int top = 1;
+ int sec = 1;
+ ArrayList tem = new ArrayList();
+ while (top < max)
+ {
+ tem.add(top);
+ int a = top;
+ top += sec;
+ sec = a;
+ }
+
+
+ return toArray(tem);
+ }
+
+ /**
+ * 返回小于给定最大值max的所有素数数组
+ * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ * @param max
+ * @return
+ */
+ public int[] getPrimes(int max)
+ {
+ ArrayList tem = new ArrayList();
+ for (int i = 0; i < max; i++)
+ {
+ if (isPrimes(i))
+ {
+ tem.add(i);
+ }
+ }
+
+ return toArray(tem);
+ }
+
+ private boolean isPrimes(int i)
+ {
+ return true;
+ }
+
+ private int[] toArray(ArrayList tem)
+ {
+ int[] newArr = new int[tem.size()];
+ for (int i = 0; i < newArr.length; i++)
+ {
+ newArr[i] = tem.get(i);
+ }
+ return newArr;
+ }
+ /**
+ * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
+ * 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
+ * @param max
+ * @return
+ */
+ public int[] getPerfectNumbers(int max)
+ {
+ ArrayList tem = new ArrayList();
+ for (int i = 0; i < max; i++)
+ {
+ if (isPerfectNumbers(i))
+ {
+ tem.add(i);
+ }
+ }
+
+ return toArray(tem);
+ }
+
+
+ private boolean isPerfectNumbers(int i)
+ {
+ return true;
+ }
+ /**
+ * 用seperator 把数组 array给连接起来
+ * 例如array= [3,8,9], seperator = "-"
+ * 则返回值为"3-8-9"
+ * @param array
+ * @param s
+ * @return
+ */
+ public String join(int[] array, String seperator)
+ {
+ String newStr = "";
+ for (int i = 0; i < array.length; i++)
+ {
+ if(i == array.length-1)
+ {
+ seperator = "";
+ }
+ newStr += array[i] + seperator;
+ }
+ return newStr;
+ }
+
+}
diff --git a/group01/1664823950/src/com/coderising/litestruts/LoginAction.java b/group01/1664823950/src/com/coderising/litestruts/LoginAction.java
new file mode 100644
index 0000000000..dcdbe226ed
--- /dev/null
+++ b/group01/1664823950/src/com/coderising/litestruts/LoginAction.java
@@ -0,0 +1,39 @@
+package com.coderising.litestruts;
+
+/**
+ * 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。
+ * @author liuxin
+ *
+ */
+public class LoginAction{
+ private String name ;
+ private String password;
+ private String message;
+
+ public String getName() {
+ return name;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String execute(){
+ if("test".equals(name) && "1234".equals(password)){
+ this.message = "login successful";
+ return "success";
+ }
+ this.message = "login failed,please check your user/pwd";
+ return "fail";
+ }
+
+ public void setName(String name){
+ this.name = name;
+ }
+ public void setPassword(String password){
+ this.password = password;
+ }
+ public String getMessage(){
+ return this.message;
+ }
+}
diff --git a/group01/1664823950/src/com/coderising/litestruts/Struts.java b/group01/1664823950/src/com/coderising/litestruts/Struts.java
new file mode 100644
index 0000000000..85e2e22de3
--- /dev/null
+++ b/group01/1664823950/src/com/coderising/litestruts/Struts.java
@@ -0,0 +1,34 @@
+package com.coderising.litestruts;
+
+import java.util.Map;
+
+
+
+public class Struts {
+
+ public static View runAction(String actionName, Map parameters) {
+
+ /*
+
+ 0. 读取配置文件struts.xml
+
+ 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
+ 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是
+ ("name"="test" , "password"="1234") ,
+ 那就应该调用 setName和setPassword方法
+
+ 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
+
+ 3. 通过反射找到对象的所有getter方法(例如 getMessage),
+ 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} ,
+ 放到View对象的parameters
+
+ 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
+ 放到View对象的jsp字段中。
+
+ */
+
+ return null;
+ }
+
+}
diff --git a/group01/1664823950/src/com/coderising/litestruts/StrutsTest.java b/group01/1664823950/src/com/coderising/litestruts/StrutsTest.java
new file mode 100644
index 0000000000..b8c81faf3c
--- /dev/null
+++ b/group01/1664823950/src/com/coderising/litestruts/StrutsTest.java
@@ -0,0 +1,43 @@
+package com.coderising.litestruts;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+
+
+
+
+public class StrutsTest {
+
+ @Test
+ public void testLoginActionSuccess() {
+
+ String actionName = "login";
+
+ Map params = new HashMap();
+ params.put("name","test");
+ params.put("password","1234");
+
+
+ View view = Struts.runAction(actionName,params);
+
+ Assert.assertEquals("/jsp/homepage.jsp", view.getJsp());
+ Assert.assertEquals("login successful", view.getParameters().get("message"));
+ }
+
+ @Test
+ public void testLoginActionFailed() {
+ String actionName = "login";
+ Map params = new HashMap();
+ params.put("name","test");
+ params.put("password","123456"); //密码和预设的不一致
+
+ View view = Struts.runAction(actionName,params);
+
+ Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp());
+ Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message"));
+ }
+}
diff --git a/group01/1664823950/src/com/coderising/litestruts/View.java b/group01/1664823950/src/com/coderising/litestruts/View.java
new file mode 100644
index 0000000000..07df2a5dab
--- /dev/null
+++ b/group01/1664823950/src/com/coderising/litestruts/View.java
@@ -0,0 +1,23 @@
+package com.coderising.litestruts;
+
+import java.util.Map;
+
+public class View {
+ private String jsp;
+ private Map parameters;
+
+ public String getJsp() {
+ return jsp;
+ }
+ public View setJsp(String jsp) {
+ this.jsp = jsp;
+ return this;
+ }
+ public Map getParameters() {
+ return parameters;
+ }
+ public View setParameters(Map parameters) {
+ this.parameters = parameters;
+ return this;
+ }
+}
diff --git a/group01/1664823950/src/com/coderising/litestruts/struts.xml b/group01/1664823950/src/com/coderising/litestruts/struts.xml
new file mode 100644
index 0000000000..a6cfe43e6c
--- /dev/null
+++ b/group01/1664823950/src/com/coderising/litestruts/struts.xml
@@ -0,0 +1,11 @@
+
+
+
+ /jsp/homepage.jsp
+ /jsp/showLogin.jsp
+
+
+ /jsp/welcome.jsp
+ /jsp/error.jsp
+
+
\ No newline at end of file
diff --git a/group01/1664823950/src/com/coding/basic/ArrayList.java b/group01/1664823950/src/com/coding/basic/ArrayList.java
index 87928e7483..3df8071a0e 100644
--- a/group01/1664823950/src/com/coding/basic/ArrayList.java
+++ b/group01/1664823950/src/com/coding/basic/ArrayList.java
@@ -1,73 +1,73 @@
-package com.coding.basic;
-
-public class ArrayList implements List
-{
-
- private int size = 0;
-
-
- private Object[] elementData = new Object[100];
-
- public void add(Object o)
- {
- elementData[size] = o;
- size ++;
- }
-
- public void add(int index, Object o)
- {
- if(index > size || index < 0)
- {
- return;
- }
- else
- {
- for (int i = size-1; i > index; i--)
- {
- elementData[i+1] = elementData[size];
- }
- elementData[index] = o;
- size++;
- }
-
- }
-
- public Object get(int index)
- {
- if(index < size || index >= 0)
- {
- return elementData[index];
- }
- return null;
- }
-
- public Object remove(int index)
- {
- Object removedObj;
- if(index >= size || index < 0)
- {
- removedObj = null;
- }
- else
- {
- removedObj = elementData[index];
- for (int j = index; j < elementData.length; j++)
- {
- elementData[j] = elementData[j+1];
- }
- size--;
- }
- return removedObj;
- }
-
- public int size()
- {
- return size;
- }
-
- public Iterator iterator()
- {
- return null;
- }
-
-}
+package com.coding.basic;
+
+public class ArrayList implements List
+{
+
+ private int size = 0;
+
+
+ private Object[] elementData = new Object[100];
+
+ public void add(Object o)
+ {
+ elementData[size] = o;
+ size ++;
+ }
+
+ public void add(int index, Object o)
+ {
+ if(index > size || index < 0)
+ {
+ return;
+ }
+ else
+ {
+ for (int i = size-1; i > index; i--)
+ {
+ elementData[i+1] = elementData[size];
+ }
+ elementData[index] = o;
+ size++;
+ }
+
+ }
+
+ public Object get(int index)
+ {
+ if(index < size || index >= 0)
+ {
+ return elementData[index];
+ }
+ return null;
+ }
+
+ public Object remove(int index)
+ {
+ Object removedObj;
+ if(index >= size || index < 0)
+ {
+ removedObj = null;
+ }
+ else
+ {
+ removedObj = elementData[index];
+ for (int j = index; j < elementData.length; j++)
+ {
+ elementData[j] = elementData[j+1];
+ }
+ size--;
+ }
+ return removedObj;
+ }
+
+ public int size()
+ {
+ return size;
+ }
+
+ public Iterator iterator()
+ {
+ return null;
+ }
+
+}
diff --git a/group01/1664823950/src/com/coding/basic/BinaryTreeNode.java b/group01/1664823950/src/com/coding/basic/BinaryTreeNode.java
index 24710872cb..4841c1310c 100644
--- a/group01/1664823950/src/com/coding/basic/BinaryTreeNode.java
+++ b/group01/1664823950/src/com/coding/basic/BinaryTreeNode.java
@@ -1,45 +1,45 @@
-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;
- }
-
-}
+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;
+ }
+
+}
diff --git a/group01/1664823950/src/com/coding/basic/Iterator.java b/group01/1664823950/src/com/coding/basic/Iterator.java
index e5ccd24b42..e98814b4c5 100644
--- a/group01/1664823950/src/com/coding/basic/Iterator.java
+++ b/group01/1664823950/src/com/coding/basic/Iterator.java
@@ -1,8 +1,8 @@
-package com.coding.basic;
-
-public interface Iterator
-{
- public boolean hasNext();
- public Object next();
-
-}
+package com.coding.basic;
+
+public interface Iterator
+{
+ public boolean hasNext();
+ public Object next();
+
+}
diff --git a/group01/1664823950/src/com/coding/basic/LinkedList.java b/group01/1664823950/src/com/coding/basic/LinkedList.java
index 2a217b2df7..5cb68effd8 100644
--- a/group01/1664823950/src/com/coding/basic/LinkedList.java
+++ b/group01/1664823950/src/com/coding/basic/LinkedList.java
@@ -1,108 +1,108 @@
-package com.coding.basic;
-
-public class LinkedList implements List
-{
-
- private Node head;
- private Node tail;
-
- public void add(Object o)
- {
- Node n = new Node(o);
- tail.next = n;
- tail = n;
- }
-
- public void add(int index , Object o)
- {
- Node n = new Node(o);
- getNode(index-1).next = n;
- n.next = getNode(index);
- }
-
- private Node getNode(int index)
- {
- Node n = head;
- int counter = 0;
- while (counter
+
+ src
+
+
+
+
+
+
+
+
diff --git a/group01/1814014897/zhouhui/src/week02/array/ArrayUtil.java b/group01/1814014897/zhouhui/src/week02/array/ArrayUtil.java
new file mode 100644
index 0000000000..dd939e7d2c
--- /dev/null
+++ b/group01/1814014897/zhouhui/src/week02/array/ArrayUtil.java
@@ -0,0 +1,222 @@
+package week02.array;
+
+/**
+ *
+ * @author Hui Zhou
+ * @version 1.0 2017-02-28
+ *
+ */
+
+public class ArrayUtil {
+
+ /**
+ * 给定一个整形数组a , 对该数组的值进行置换
+ 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7]
+ 如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7]
+ * @param origin
+ * @return
+ */
+ public void reverseArray(int[] origin){
+ if(origin == null) return;
+
+ int mid = origin.length/2;
+ for(int i=0;iarray4[j+1]){
+ int sto = array4[j];
+ array4[j] = array4[j+1];
+ array4[j+1] = sto;
+ }
+ }
+ }
+ return array4;
+ }
+ /**
+ * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
+ * 注意,老数组的元素在新数组中需要保持
+ * 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
+ * [2,3,6,0,0,0]
+ * @param oldArray
+ * @param size
+ * @return
+ */
+ public int[] grow(int [] oldArray, int size){
+ if(size<0 || oldArray==null) return null;
+
+ int[] newArray = new int[oldArray.length + size];
+ for(int i=0;i parameters) {
+
+ /*
+
+ 0. 读取配置文件struts.xml
+
+ 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
+ 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是
+ ("name"="test" , "password"="1234") ,
+ 那就应该调用 setName和setPassword方法
+
+ 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
+
+ 3. 通过反射找到对象的所有getter方法(例如 getMessage),
+ 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} ,
+ 放到View对象的parameters
+
+ 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
+ 放到View对象的jsp字段中。
+
+ */
+
+ //读取配置文件struts.xml
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder;
+ Document doc = null;
+ View view = new View(); //实例化View(后面调用view,存储parameters以及jsp,最后return view)
+ try {
+ builder = factory.newDocumentBuilder();
+ File f = new File("src/week02/litestruts/struts.xml");
+ doc = builder.parse(f);
+ } catch (ParserConfigurationException|SAXException|IOException e) {
+ e.printStackTrace();
+ }
+
+ //根据actionName找到相对应的action
+ Element root = doc.getDocumentElement();
+ NodeList actionNode = root.getElementsByTagName("action");
+ Element action = null;
+ for(int i=0;i cls = Class.forName(actionClass);
+ Object obj = cls.newInstance();
+ Method setName = cls.getMethod("setName", String.class);
+ Method setPassword = cls.getMethod("setPassword", String.class);
+ setName.invoke(obj, parameters.get("name"));
+ setPassword.invoke(obj, parameters.get("password"));
+
+ //通过反射调用对象的exectue 方法,并获得返回值
+ Method execute = cls.getMethod("execute");
+ String exe_val = (String) execute.invoke(obj);
+
+ //通过反射找到对象的所有getter方法,通过反射来调用
+ Method[] met = cls.getDeclaredMethods();
+ List list = new LinkedList();
+ for(int i=0;i param = new HashMap<>();
+ for(int i=0;i 配置,以及execute的返回值,确定哪一个jsp,放到View对象的jsp字段中
+ if(exe_val.equals("success"))
+ view.setJsp("/jsp/homepage.jsp");
+ else view.setJsp("/jsp/showLogin.jsp");
+
+ } catch (ClassNotFoundException|InstantiationException|IllegalAccessException
+ |NoSuchMethodException|SecurityException|IllegalArgumentException|InvocationTargetException e) {
+ e.printStackTrace();
+ }
+
+ return view;
+ }
+}
diff --git a/group01/1814014897/zhouhui/src/week02/litestruts/StrutsTest.java b/group01/1814014897/zhouhui/src/week02/litestruts/StrutsTest.java
new file mode 100644
index 0000000000..e65f6525bd
--- /dev/null
+++ b/group01/1814014897/zhouhui/src/week02/litestruts/StrutsTest.java
@@ -0,0 +1,41 @@
+package week02.litestruts;
+
+import java.util.*;
+import org.junit.*;
+
+/**
+ * @author Hui Zhou
+ * @version 1.0 2017-02-28
+ */
+
+public class StrutsTest {
+
+ @Test
+ public void testLoginActionSuccess() {
+
+ String actionName = "login";
+
+ Map params = new HashMap();
+ params.put("name","test");
+ params.put("password","1234");
+
+
+ View view = Struts.runAction(actionName,params);
+
+ Assert.assertEquals("/jsp/homepage.jsp", view.getJsp());
+ Assert.assertEquals("login successful", view.getParameters().get("message"));
+ }
+
+ @Test
+ public void testLoginActionFailed() {
+ String actionName = "login";
+ Map params = new HashMap();
+ params.put("name","test");
+ params.put("password","123456"); //密码和预设的不一致
+
+ View view = Struts.runAction(actionName,params);
+
+ Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp());
+ Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message"));
+ }
+}
diff --git a/group01/1814014897/zhouhui/src/week02/litestruts/View.java b/group01/1814014897/zhouhui/src/week02/litestruts/View.java
new file mode 100644
index 0000000000..3043fb5d5a
--- /dev/null
+++ b/group01/1814014897/zhouhui/src/week02/litestruts/View.java
@@ -0,0 +1,28 @@
+package week02.litestruts;
+
+import java.util.Map;
+
+/**
+ * @author Hui Zhou
+ * @version 1.0 2017-02-28
+ */
+
+public class View {
+ private String jsp;
+ private Map parameters;
+
+ public String getJsp() {
+ return jsp;
+ }
+ public View setJsp(String jsp) {
+ this.jsp = jsp;
+ return this;
+ }
+ public Map getParameters() {
+ return parameters;
+ }
+ public View setParameters(Map parameters) {
+ this.parameters = parameters;
+ return this;
+ }
+}
diff --git a/group01/1814014897/zhouhui/src/week02/litestruts/struts.xml b/group01/1814014897/zhouhui/src/week02/litestruts/struts.xml
new file mode 100644
index 0000000000..f449db14dd
--- /dev/null
+++ b/group01/1814014897/zhouhui/src/week02/litestruts/struts.xml
@@ -0,0 +1,11 @@
+
+
+
+ /jsp/homepage.jsp
+ /jsp/showLogin.jsp
+
+
+ /jsp/welcome.jsp
+ /jsp/error.jsp
+
+
\ No newline at end of file
diff --git a/group01/2137642225/work01/.classpath b/group01/2137642225/work01/.classpath
index 2d7497573f..3e0fb272a8 100644
--- a/group01/2137642225/work01/.classpath
+++ b/group01/2137642225/work01/.classpath
@@ -1,7 +1,7 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
diff --git a/group01/2137642225/work01/.project b/group01/2137642225/work01/.project
index f8dde642e5..a703634d61 100644
--- a/group01/2137642225/work01/.project
+++ b/group01/2137642225/work01/.project
@@ -1,17 +1,17 @@
-
-
- work01
-
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
-
- org.eclipse.jdt.core.javanature
-
-
+
+
+ work01
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group01/2137642225/work01/README.md b/group01/2137642225/work01/README.md
new file mode 100644
index 0000000000..31114b9ff8
--- /dev/null
+++ b/group01/2137642225/work01/README.md
@@ -0,0 +1,6 @@
+- 实现基本的数据结构
+# ArrayList
+# LinkedList
+# Stack
+# Queue
+# BinaryTree
\ No newline at end of file
diff --git a/group01/2137642225/work01/src/com/coding/mybasic/ArrayList.java b/group01/2137642225/work01/src/com/coding/mybasic/ArrayList.java
index 1826ee7c50..047453a4e7 100644
--- a/group01/2137642225/work01/src/com/coding/mybasic/ArrayList.java
+++ b/group01/2137642225/work01/src/com/coding/mybasic/ArrayList.java
@@ -1,139 +1,139 @@
-package com.coding.mybasic;
-
-public class ArrayList implements List{
-
- private static final int DEF_CAPACITY = 10;
- private int size;
- private Object[] elementData;
-
- public ArrayList(){
- elementData = new Object[DEF_CAPACITY];
- }
-
- public ArrayList(int initCapacity) {
- if(initCapacity <= 0){
- throw new RuntimeException("初始化长度必须大于0");
- }
- elementData = new Object[initCapacity];
- }
-
- @Override
- public void add(Object element) {
- checkArrayOutOfRange();
- elementData[size++] = element;
- }
-
-
- @Override
- public void add(int index, Object element) {
- // 末尾插入
- if(index == size){
- add(element);
- return;
- }
- // index 在 0到size 之间,index之后元素要后移
- checkIndex(index);
- checkArrayOutOfRange();
- moveBackwardElement(index);
- elementData[index] = element;
- size++;
- }
-
-
- @Override
- public Object get(int index) {
- checkIndex(index);
- return elementData[index];
- }
-
- @Override
- public Object remove(int index) {
- checkIndex(index);
- Object temp = elementData[index];
- moveForwardElement(index);
- elementData[size--] = null;
- return temp;
- }
-
-
-
- @Override
- public int size() {
- return size;
- }
-
- @Override
- public Iterator iterator() {
- return new ArrayListIterator();
- }
-
- private class ArrayListIterator implements Iterator{
- private int i = 0;
- @Override
- public boolean hasNext() {
- return i < size;
- }
-
- @Override
- public Object next() {
- checkIndex(i);
- return elementData[i++];
- }
-
- }
-
- /**
- * 数组增长
- * @param newCapacity 新数组容量
- */
- private void grow(int newCapacity) {
- Object[] dest = new Object[newCapacity];
- System.arraycopy(elementData, 0, dest , 0, elementData.length);
- elementData = dest;
- }
-
- /**
- * 检查index index >=0 且 < size
- * @param index
- * @throws Exception
- */
- private void checkIndex(int index) {
- if(index < 0){
- throw new RuntimeException("index 必须大于0");
- }
- // 越界
- if(index >= size){
- throw new RuntimeException("index 必须小于size:" + size);
- }
- }
-
- /**
- * 检查数组容量是否已满,已满则扩容
- */
- private void checkArrayOutOfRange() {
- if(size >= elementData.length){
- // 扩容 默认新容量是原来容量的2倍
- grow(elementData.length * 2);
- }
- }
-
- /**
- * 后移元素,从index开始
- * @param index
- */
- private void moveBackwardElement(int index) {
- for (int i = size; i > index; i--) {
- elementData[i] = elementData[i - 1];
- }
- }
- /**
- * 前移元素,从index开始
- * @param index
- */
- private void moveForwardElement(int index) {
- for (int i = index; i < size; i++) {
- elementData[i] = elementData[i + 1];
- }
- }
-
-}
+package com.coding.mybasic;
+
+public class ArrayList implements List{
+
+ private static final int DEF_CAPACITY = 10;
+ private int size;
+ private Object[] elementData;
+
+ public ArrayList(){
+ elementData = new Object[DEF_CAPACITY];
+ }
+
+ public ArrayList(int initCapacity) {
+ if(initCapacity <= 0){
+ throw new RuntimeException("初始化长度必须大于0");
+ }
+ elementData = new Object[initCapacity];
+ }
+
+ @Override
+ public void add(Object element) {
+ checkArrayOutOfRange();
+ elementData[size++] = element;
+ }
+
+
+ @Override
+ public void add(int index, Object element) {
+ // 末尾插入
+ if(index == size){
+ add(element);
+ return;
+ }
+ // index 在 0到size 之间,index之后元素要后移
+ checkIndex(index);
+ checkArrayOutOfRange();
+ moveBackwardElement(index);
+ elementData[index] = element;
+ size++;
+ }
+
+
+ @Override
+ public Object get(int index) {
+ checkIndex(index);
+ return elementData[index];
+ }
+
+ @Override
+ public Object remove(int index) {
+ checkIndex(index);
+ Object temp = elementData[index];
+ moveForwardElement(index);
+ elementData[size--] = null;
+ return temp;
+ }
+
+
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ @Override
+ public Iterator iterator() {
+ return new ArrayListIterator();
+ }
+
+ private class ArrayListIterator implements Iterator{
+ private int i = 0;
+ @Override
+ public boolean hasNext() {
+ return i < size;
+ }
+
+ @Override
+ public Object next() {
+ checkIndex(i);
+ return elementData[i++];
+ }
+
+ }
+
+ /**
+ * 数组增长
+ * @param newCapacity 新数组容量
+ */
+ private void grow(int newCapacity) {
+ Object[] dest = new Object[newCapacity];
+ System.arraycopy(elementData, 0, dest , 0, elementData.length);
+ elementData = dest;
+ }
+
+ /**
+ * 检查index index >=0 且 < size
+ * @param index
+ * @throws Exception
+ */
+ private void checkIndex(int index) {
+ if(index < 0){
+ throw new RuntimeException("index 必须大于0");
+ }
+ // 越界
+ if(index >= size){
+ throw new RuntimeException("index 必须小于size:" + size);
+ }
+ }
+
+ /**
+ * 检查数组容量是否已满,已满则扩容
+ */
+ private void checkArrayOutOfRange() {
+ if(size >= elementData.length){
+ // 扩容 默认新容量是原来容量的2倍
+ grow(elementData.length * 2);
+ }
+ }
+
+ /**
+ * 后移元素,从index开始
+ * @param index
+ */
+ private void moveBackwardElement(int index) {
+ for (int i = size; i > index; i--) {
+ elementData[i] = elementData[i - 1];
+ }
+ }
+ /**
+ * 前移元素,从index开始
+ * @param index
+ */
+ private void moveForwardElement(int index) {
+ for (int i = index; i < size; i++) {
+ elementData[i] = elementData[i + 1];
+ }
+ }
+
+}
diff --git a/group01/2137642225/work01/src/com/coding/mybasic/BinaryTreeNode.java b/group01/2137642225/work01/src/com/coding/mybasic/BinaryTreeNode.java
index 21bd8f696f..c35cd96d8a 100644
--- a/group01/2137642225/work01/src/com/coding/mybasic/BinaryTreeNode.java
+++ b/group01/2137642225/work01/src/com/coding/mybasic/BinaryTreeNode.java
@@ -1,73 +1,73 @@
-package com.coding.mybasic;
-
-public class BinaryTreeNode {
-
- private Integer data;
- private BinaryTreeNode left;
- private BinaryTreeNode right;
-
- public Object getData() {
- return data;
- }
- public void setData(Integer 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(Integer o){
- if(o == null){
- throw new RuntimeException("不能插入空值");
- }
- BinaryTreeNode searchNode = search(this,o);
- if(isExistData(searchNode,o)){
- throw new RuntimeException("该值已存在 无法插入");
- }
- if(searchNode != null){
- BinaryTreeNode binaryTreeNode = new BinaryTreeNode();
- binaryTreeNode.setData(o);
- if(searchNode.data.intValue() > o.intValue()){
- searchNode.setLeft(binaryTreeNode);
- }else{
- searchNode.setRight(binaryTreeNode);
- }
- } else {
- throw new RuntimeException("根节点未赋值,无法插入");
- }
- return this;
- }
-
- private boolean isExistData(BinaryTreeNode searchNode,Integer data) {
- return searchNode != null && searchNode.data.intValue() == data.intValue();
-
- }
-
- private BinaryTreeNode search(BinaryTreeNode binaryTreeNode, Integer data) {
- if(binaryTreeNode == null || binaryTreeNode.data == null){
- return null;
- }
- Integer curNodeData = binaryTreeNode.data;
- if(curNodeData.intValue() > data.intValue()){// 左 curNodeData > data
- if(binaryTreeNode.left != null){
- return search(binaryTreeNode.left,data);
- }
- }else if(curNodeData.intValue() < data.intValue()){
- if(binaryTreeNode.right != null){
- return search(binaryTreeNode.right,data);
- }
-
- }
- return binaryTreeNode;
- }
-
-}
+package com.coding.mybasic;
+
+public class BinaryTreeNode {
+
+ private Integer data;
+ private BinaryTreeNode left;
+ private BinaryTreeNode right;
+
+ public Object getData() {
+ return data;
+ }
+ public void setData(Integer 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(Integer o){
+ if(o == null){
+ throw new RuntimeException("不能插入空值");
+ }
+ BinaryTreeNode searchNode = search(this,o);
+ if(isExistData(searchNode,o)){
+ throw new RuntimeException("该值已存在 无法插入");
+ }
+ if(searchNode != null){
+ BinaryTreeNode binaryTreeNode = new BinaryTreeNode();
+ binaryTreeNode.setData(o);
+ if(searchNode.data.intValue() > o.intValue()){
+ searchNode.setLeft(binaryTreeNode);
+ }else{
+ searchNode.setRight(binaryTreeNode);
+ }
+ } else {
+ throw new RuntimeException("根节点未赋值,无法插入");
+ }
+ return this;
+ }
+
+ private boolean isExistData(BinaryTreeNode searchNode,Integer data) {
+ return searchNode != null && searchNode.data.intValue() == data.intValue();
+
+ }
+
+ private BinaryTreeNode search(BinaryTreeNode binaryTreeNode, Integer data) {
+ if(binaryTreeNode == null || binaryTreeNode.data == null){
+ return null;
+ }
+ Integer curNodeData = binaryTreeNode.data;
+ if(curNodeData.intValue() > data.intValue()){// 左 curNodeData > data
+ if(binaryTreeNode.left != null){
+ return search(binaryTreeNode.left,data);
+ }
+ }else if(curNodeData.intValue() < data.intValue()){
+ if(binaryTreeNode.right != null){
+ return search(binaryTreeNode.right,data);
+ }
+
+ }
+ return binaryTreeNode;
+ }
+
+}
diff --git a/group01/2137642225/work01/src/com/coding/mybasic/Iterator.java b/group01/2137642225/work01/src/com/coding/mybasic/Iterator.java
index 622cc5b902..33d55843cd 100644
--- a/group01/2137642225/work01/src/com/coding/mybasic/Iterator.java
+++ b/group01/2137642225/work01/src/com/coding/mybasic/Iterator.java
@@ -1,7 +1,7 @@
-package com.coding.mybasic;
-
-public interface Iterator {
- public boolean hasNext();
- public Object next();
-
-}
+package com.coding.mybasic;
+
+public interface Iterator {
+ public boolean hasNext();
+ public Object next();
+
+}
diff --git a/group01/2137642225/work01/src/com/coding/mybasic/LinkedList.java b/group01/2137642225/work01/src/com/coding/mybasic/LinkedList.java
index ab37360e78..cbdd293173 100644
--- a/group01/2137642225/work01/src/com/coding/mybasic/LinkedList.java
+++ b/group01/2137642225/work01/src/com/coding/mybasic/LinkedList.java
@@ -1,226 +1,226 @@
-package com.coding.mybasic;
-
-public class LinkedList implements List {
-
- private Node head;
- private Node last;
- private int size;
-
- public LinkedList() {
- }
-
- @Override
- public void add(Object element) {
- if(head == null){
- addHead(element);
- }else{
- addLast(element);
- }
- }
-
- @Override
- public void add(int index, Object element) {
- if(index == size){
- add(element);
- return;
- }
-
- if(index == 0){
- addFirst(element);
- return;
- }
- checkIndex(index);
- insertElement(index - 1,element);
- }
-
-
- @Override
- public Object get(int index) {
- checkIndex(index);
- Node node = getNodeByIndex(index);
- return node != null ? node.data : null;
- }
-
- @Override
- public Object remove(int index) {
-
- checkIndex(index);
- Object element = null;
- if(index == 0){
- element = removeFirst();
- }
- else if(index == (size - 1)){
- element = removeLast();
- }
- else {
- element = removeMiddle(index);
- }
- return element;
- }
-
-
- @Override
- public int size() {
- return size;
- }
-
+package com.coding.mybasic;
- @Override
- public Iterator iterator() {
- return new LinkedListIterator();
- }
-
- private class LinkedListIterator implements Iterator{
- private Node node = head;
- int i = 0;
- @Override
- public boolean hasNext() {
- return i < size;
- }
-
- @Override
- public Object next() {
- checkIndex(i);
- Object element = node.data;
- node = node.next;
- i++;
- return element;
- }
-
- }
+public class LinkedList implements List {
+
+ private Node head;
+ private Node last;
+ private int size;
+
+ public LinkedList() {
+ }
+
+ @Override
+ public void add(Object element) {
+ if(head == null){
+ addHead(element);
+ }else{
+ addLast(element);
+ }
+ }
+
+ @Override
+ public void add(int index, Object element) {
+ if(index == size){
+ add(element);
+ return;
+ }
+
+ if(index == 0){
+ addFirst(element);
+ return;
+ }
+ checkIndex(index);
+ insertElement(index - 1,element);
+ }
+
+
+ @Override
+ public Object get(int index) {
+ checkIndex(index);
+ Node node = getNodeByIndex(index);
+ return node != null ? node.data : null;
+ }
- public void addFirst(Object o){
- Node node = new Node();
- node.data = o;
- node.next = head.next;
- head = node;
- size++;
- }
- public void addLast(Object o){
- Node node = new Node();
- node.data = o;
- node.next = null;
- last.next = node;
- last = node;
- size++;
- }
- public Object removeFirst(){
- return removeFirstNode();
- }
- public Object removeLast(){
- return removeLastNode();
- }
- private Object removeMiddle(int index) {
- Node temp = getNodeByIndex(index - 1);
- Node removeNode = temp.next;
- Object element = removeNode.data;
- temp.next = removeNode.next;
- removeNode = null;
- size--;
- return element;
- }
-
- /**
- * 检查index index >=0 且 < size
- * @param index
- * @throws Exception
- */
- private void checkIndex(int index) {
- if(index < 0){
- throw new RuntimeException("index 必须大于0");
- }
- // 越界
- if(index >= size){
- throw new RuntimeException("index 必须小于size:" + size);
- }
- }
-
- /**
- * 添加head
- * @param element
- */
- private void addHead(Object element) {
- head = new Node();
- head.data = element;
- head.next = null;
- last = head;
- size++;
- }
- /**
- * 插入序号在0-size之间的元素,不包含0和size位置
- * @param index
- * @param element
- */
- private void insertElement(int index, Object element) {
-
- Node temp = getNodeByIndex(index);
- if(temp != null){
- Node node = new Node();
- node.data = element;
- node.next = temp.next;
- temp.next = node;
- }
- size++;
- }
- /**
- * 获取下标为index的元素
- * @param index
- * @return
- */
- private Node getNodeByIndex(int index) {
- Node temp = head;
- int i = 0;
-
- while(i < size){
- if(i == index){
- return temp;
- }
- temp = temp.next;
- i++;
- }
-
- return null;
- }
- /**
- * 移除最后一个元素
- * @return
- */
- private Object removeLastNode() {
- Node node = getNodeByIndex(size - 2);
- Node lastNode = node.next;
- Object element = lastNode.data;
- lastNode = null;
- last = node;
- size--;
- return element;
- }
- /**
- * 移除第一个元素
- * @return
- */
- private Object removeFirstNode() {
- Node node = head.next;
- Object element = head.data;
- head = null;
- head = node;
- size--;
- return element;
- }
-
-
-
- private static class Node{
- Object data;
- Node next;
- public Node() {
- }
- @SuppressWarnings("unused")
- public Node(Object data, Node next) {
- super();
- this.data = data;
- this.next = next;
- }
-
-
- }
-}
+ @Override
+ public Object remove(int index) {
+
+ checkIndex(index);
+ Object element = null;
+ if(index == 0){
+ element = removeFirst();
+ }
+ else if(index == (size - 1)){
+ element = removeLast();
+ }
+ else {
+ element = removeMiddle(index);
+ }
+ return element;
+ }
+
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+
+ @Override
+ public Iterator iterator() {
+ return new LinkedListIterator();
+ }
+
+ private class LinkedListIterator implements Iterator{
+ private Node node = head;
+ int i = 0;
+ @Override
+ public boolean hasNext() {
+ return i < size;
+ }
+
+ @Override
+ public Object next() {
+ checkIndex(i);
+ Object element = node.data;
+ node = node.next;
+ i++;
+ return element;
+ }
+
+ }
+
+ public void addFirst(Object o){
+ Node node = new Node();
+ node.data = o;
+ node.next = head.next;
+ head = node;
+ size++;
+ }
+ public void addLast(Object o){
+ Node node = new Node();
+ node.data = o;
+ node.next = null;
+ last.next = node;
+ last = node;
+ size++;
+ }
+ public Object removeFirst(){
+ return removeFirstNode();
+ }
+ public Object removeLast(){
+ return removeLastNode();
+ }
+ private Object removeMiddle(int index) {
+ Node temp = getNodeByIndex(index - 1);
+ Node removeNode = temp.next;
+ Object element = removeNode.data;
+ temp.next = removeNode.next;
+ removeNode = null;
+ size--;
+ return element;
+ }
+
+ /**
+ * 检查index index >=0 且 < size
+ * @param index
+ * @throws Exception
+ */
+ private void checkIndex(int index) {
+ if(index < 0){
+ throw new RuntimeException("index 必须大于0");
+ }
+ // 越界
+ if(index >= size){
+ throw new RuntimeException("index 必须小于size:" + size);
+ }
+ }
+
+ /**
+ * 添加head
+ * @param element
+ */
+ private void addHead(Object element) {
+ head = new Node();
+ head.data = element;
+ head.next = null;
+ last = head;
+ size++;
+ }
+ /**
+ * 插入序号在0-size之间的元素,不包含0和size位置
+ * @param index
+ * @param element
+ */
+ private void insertElement(int index, Object element) {
+
+ Node temp = getNodeByIndex(index);
+ if(temp != null){
+ Node node = new Node();
+ node.data = element;
+ node.next = temp.next;
+ temp.next = node;
+ }
+ size++;
+ }
+ /**
+ * 获取下标为index的元素
+ * @param index
+ * @return
+ */
+ private Node getNodeByIndex(int index) {
+ Node temp = head;
+ int i = 0;
+
+ while(i < size){
+ if(i == index){
+ return temp;
+ }
+ temp = temp.next;
+ i++;
+ }
+
+ return null;
+ }
+ /**
+ * 移除最后一个元素
+ * @return
+ */
+ private Object removeLastNode() {
+ Node node = getNodeByIndex(size - 2);
+ Node lastNode = node.next;
+ Object element = lastNode.data;
+ lastNode = null;
+ last = node;
+ size--;
+ return element;
+ }
+ /**
+ * 移除第一个元素
+ * @return
+ */
+ private Object removeFirstNode() {
+ Node node = head.next;
+ Object element = head.data;
+ head = null;
+ head = node;
+ size--;
+ return element;
+ }
+
+
+
+ private static class Node{
+ Object data;
+ Node next;
+ public Node() {
+ }
+ @SuppressWarnings("unused")
+ public Node(Object data, Node next) {
+ super();
+ this.data = data;
+ this.next = next;
+ }
+
+
+ }
+}
diff --git a/group01/2137642225/work01/src/com/coding/mybasic/List.java b/group01/2137642225/work01/src/com/coding/mybasic/List.java
index 87a58a6c4c..7cca6b3f71 100644
--- a/group01/2137642225/work01/src/com/coding/mybasic/List.java
+++ b/group01/2137642225/work01/src/com/coding/mybasic/List.java
@@ -1,10 +1,10 @@
-package com.coding.mybasic;
-
-public interface List {
- public void add(Object element);
- public void add(int index, Object element);
- public Object get(int index);
- public Object remove(int index);
- public int size();
- public Iterator iterator();
-}
+package com.coding.mybasic;
+
+public interface List {
+ public void add(Object element);
+ public void add(int index, Object element);
+ public Object get(int index);
+ public Object remove(int index);
+ public int size();
+ public Iterator iterator();
+}
diff --git a/group01/2137642225/work01/src/com/coding/mybasic/Queue.java b/group01/2137642225/work01/src/com/coding/mybasic/Queue.java
index 36d10fd668..68b17c014e 100644
--- a/group01/2137642225/work01/src/com/coding/mybasic/Queue.java
+++ b/group01/2137642225/work01/src/com/coding/mybasic/Queue.java
@@ -1,30 +1,30 @@
-package com.coding.mybasic;
-
-public class Queue {
- private LinkedList linkedList = new LinkedList();
- public void enQueue(Object o){
- linkedList.add(o);
- }
-
- public Object deQueue(){
- checkEmptyQueue();
- return linkedList.remove(0);
- }
-
- public boolean isEmpty(){
- return size() <= 0;
- }
-
- public int size(){
- return linkedList.size();
- }
-
- /**
- * 检查队列是否为空
- */
- private void checkEmptyQueue() {
- if(isEmpty()){
- throw new RuntimeException("size:" + size() + " 空队列");
- }
- }
-}
+package com.coding.mybasic;
+
+public class Queue {
+ private LinkedList linkedList = new LinkedList();
+ public void enQueue(Object o){
+ linkedList.add(o);
+ }
+
+ public Object deQueue(){
+ checkEmptyQueue();
+ return linkedList.remove(0);
+ }
+
+ public boolean isEmpty(){
+ return size() <= 0;
+ }
+
+ public int size(){
+ return linkedList.size();
+ }
+
+ /**
+ * 检查队列是否为空
+ */
+ private void checkEmptyQueue() {
+ if(isEmpty()){
+ throw new RuntimeException("size:" + size() + " 空队列");
+ }
+ }
+}
diff --git a/group01/2137642225/work01/src/com/coding/mybasic/Stack.java b/group01/2137642225/work01/src/com/coding/mybasic/Stack.java
index f50e686317..f89deb457a 100644
--- a/group01/2137642225/work01/src/com/coding/mybasic/Stack.java
+++ b/group01/2137642225/work01/src/com/coding/mybasic/Stack.java
@@ -1,35 +1,35 @@
-package com.coding.mybasic;
-
-public class Stack {
- private ArrayList elementData = new ArrayList();
-
- public void push(Object o){
- elementData.add(o);
- }
-
- public Object pop(){
- checkEmptyStack();
- return elementData.remove(size() - 1);
- }
-
- public Object peek(){
- checkEmptyStack();
- Object element = elementData.get(size() - 1);
- return element;
- }
-
- public boolean isEmpty(){
- return size() <= 0;
- }
- public int size(){
- return elementData.size();
- }
- /**
- * 检查栈是否为空
- */
- private void checkEmptyStack() {
- if(isEmpty()){
- throw new RuntimeException("size:" + size() + " 空栈");
- }
- }
-}
+package com.coding.mybasic;
+
+public class Stack {
+ private ArrayList elementData = new ArrayList();
+
+ public void push(Object o){
+ elementData.add(o);
+ }
+
+ public Object pop(){
+ checkEmptyStack();
+ return elementData.remove(size() - 1);
+ }
+
+ public Object peek(){
+ checkEmptyStack();
+ Object element = elementData.get(size() - 1);
+ return element;
+ }
+
+ public boolean isEmpty(){
+ return size() <= 0;
+ }
+ public int size(){
+ return elementData.size();
+ }
+ /**
+ * 检查栈是否为空
+ */
+ private void checkEmptyStack() {
+ if(isEmpty()){
+ throw new RuntimeException("size:" + size() + " 空栈");
+ }
+ }
+}
diff --git a/group01/2137642225/work01/src/com/coding/test/TestArrayList.java b/group01/2137642225/work01/src/com/coding/test/TestArrayList.java
index 8bd8952195..b6669c4b98 100644
--- a/group01/2137642225/work01/src/com/coding/test/TestArrayList.java
+++ b/group01/2137642225/work01/src/com/coding/test/TestArrayList.java
@@ -1,81 +1,81 @@
-package com.coding.test;
-
-
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.coding.mybasic.ArrayList;
-import com.coding.mybasic.Iterator;
-import com.coding.mybasic.List;
-
-public class TestArrayList {
-
- private List list;
- @Before
- public void before() {
- list = new ArrayList();
- }
-
- @Test
- public void testAddObject() {
- list.add("ele");
- Assert.assertEquals("ele", list.get(0));
- }
-
- @Test
- public void testAddIntObject() {
-
- for (int i = 0; i < 5; i++) {
- list.add(i,i);
- Assert.assertEquals(i, list.get(i));
- }
-
- }
-
- @Test
- public void testGet() {
- list.add("ss");
- Assert.assertEquals("ss", list.get(0));
- }
-
- @Test
- public void testRemove() {
- list.add("we");
- list.add(1, "gga");
- list.add(0, "start");
- list.add(3, "end");
-
- Assert.assertEquals("end", list.remove(3));
-
- }
-
- @Test
- public void testSize() {
-
- for (int i = 0; i < 10; i++) {
- list.add(i);
- }
-
- Assert.assertEquals(10, list.size());
- }
-
- @Test
- public void testIterator() {
-
- for (int i = 0; i < 10; i++) {
- list.add(i);
- }
- Iterator iterator = list.iterator();
- int i = 0;
- while(iterator.hasNext()){
- Assert.assertEquals(i++, iterator.next());
- }
- }
-
- @After
- public void after(){
-
- }
-}
+package com.coding.test;
+
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.coding.mybasic.ArrayList;
+import com.coding.mybasic.Iterator;
+import com.coding.mybasic.List;
+
+public class TestArrayList {
+
+ private List list;
+ @Before
+ public void before() {
+ list = new ArrayList();
+ }
+
+ @Test
+ public void testAddObject() {
+ list.add("ele");
+ Assert.assertEquals("ele", list.get(0));
+ }
+
+ @Test
+ public void testAddIntObject() {
+
+ for (int i = 0; i < 5; i++) {
+ list.add(i,i);
+ Assert.assertEquals(i, list.get(i));
+ }
+
+ }
+
+ @Test
+ public void testGet() {
+ list.add("ss");
+ Assert.assertEquals("ss", list.get(0));
+ }
+
+ @Test
+ public void testRemove() {
+ list.add("we");
+ list.add(1, "gga");
+ list.add(0, "start");
+ list.add(3, "end");
+
+ Assert.assertEquals("end", list.remove(3));
+
+ }
+
+ @Test
+ public void testSize() {
+
+ for (int i = 0; i < 10; i++) {
+ list.add(i);
+ }
+
+ Assert.assertEquals(10, list.size());
+ }
+
+ @Test
+ public void testIterator() {
+
+ for (int i = 0; i < 10; i++) {
+ list.add(i);
+ }
+ Iterator iterator = list.iterator();
+ int i = 0;
+ while(iterator.hasNext()){
+ Assert.assertEquals(i++, iterator.next());
+ }
+ }
+
+ @After
+ public void after(){
+
+ }
+}
diff --git a/group01/2137642225/work01/src/com/coding/test/TestBinaryTreeNode.java b/group01/2137642225/work01/src/com/coding/test/TestBinaryTreeNode.java
index 662bb55570..760abd8b9a 100644
--- a/group01/2137642225/work01/src/com/coding/test/TestBinaryTreeNode.java
+++ b/group01/2137642225/work01/src/com/coding/test/TestBinaryTreeNode.java
@@ -1,32 +1,32 @@
-package com.coding.test;
-
-import static org.junit.Assert.*;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.coding.mybasic.BinaryTreeNode;
-
-public class TestBinaryTreeNode {
-
- private BinaryTreeNode node;
- @Before
- public void before(){
- node = new BinaryTreeNode();
- }
-
- @Test
- public void testInsert() {
- node.insert(1);
- node.insert(0);
- node.insert(3);
- node.insert(-2);
- node.insert(-1);
- assertEquals(1, node.getData());
- assertEquals(0, node.getLeft().getData());
- assertEquals(3, node.getRight().getData());
- assertEquals(-2, node.getLeft().getLeft().getData());
- assertEquals(-1, node.getLeft().getLeft().getRight().getData());
- }
-
-}
+package com.coding.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.coding.mybasic.BinaryTreeNode;
+
+public class TestBinaryTreeNode {
+
+ private BinaryTreeNode node;
+ @Before
+ public void before(){
+ node = new BinaryTreeNode();
+ }
+
+ @Test
+ public void testInsert() {
+ node.insert(1);
+ node.insert(0);
+ node.insert(3);
+ node.insert(-2);
+ node.insert(-1);
+ assertEquals(1, node.getData());
+ assertEquals(0, node.getLeft().getData());
+ assertEquals(3, node.getRight().getData());
+ assertEquals(-2, node.getLeft().getLeft().getData());
+ assertEquals(-1, node.getLeft().getLeft().getRight().getData());
+ }
+
+}
diff --git a/group01/2137642225/work01/src/com/coding/test/TestLinkedList.java b/group01/2137642225/work01/src/com/coding/test/TestLinkedList.java
index 57a8b13bb8..52ac84016c 100644
--- a/group01/2137642225/work01/src/com/coding/test/TestLinkedList.java
+++ b/group01/2137642225/work01/src/com/coding/test/TestLinkedList.java
@@ -1,73 +1,73 @@
-package com.coding.test;
-
-import static org.junit.Assert.*;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.coding.mybasic.Iterator;
-import com.coding.mybasic.LinkedList;
-import com.coding.mybasic.List;
-
-public class TestLinkedList {
-
- private List list;
-
- @Before
- public void before(){
- list = new LinkedList();
- }
-
- @Test
- public void testAddObject() {
- list.add(1);
-
- System.out.println(list.get(0));
- assertEquals(1, list.get(0));
- assertEquals(1, list.size());
- }
-
- @Test
- public void testAddIntObject() {
- list.add(0,1);
- System.out.println(list.get(0));
- assertEquals(1, list.get(0));
- assertEquals(1, list.size());
- }
-
- @Test
- public void testGet() {
- fail("Not yet implemented");
- }
-
- @Test
- public void testRemove() {
- list.add(0,1);
- System.out.println(list.remove(0));
- assertEquals(0, list.size());
- }
-
- @Test
- public void testSize() {
-
- for(int i = 0; i < 10; i++){
- list.add(i, i);
- }
-
- assertEquals(10, list.size());
- }
-
- @Test
- public void testIterator() {
-
- for(int i = 0; i < 10; i++){
- list.add(i, i);
- }
- Iterator iterator = list.iterator();
- int i = 0;
- while(iterator.hasNext()){
- assertEquals(i++, iterator.next());
- }
- //iterator.next();
- }
-}
+package com.coding.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.coding.mybasic.Iterator;
+import com.coding.mybasic.LinkedList;
+import com.coding.mybasic.List;
+
+public class TestLinkedList {
+
+ private List list;
+
+ @Before
+ public void before(){
+ list = new LinkedList();
+ }
+
+ @Test
+ public void testAddObject() {
+ list.add(1);
+
+ System.out.println(list.get(0));
+ assertEquals(1, list.get(0));
+ assertEquals(1, list.size());
+ }
+
+ @Test
+ public void testAddIntObject() {
+ list.add(0,1);
+ System.out.println(list.get(0));
+ assertEquals(1, list.get(0));
+ assertEquals(1, list.size());
+ }
+
+ @Test
+ public void testGet() {
+ fail("Not yet implemented");
+ }
+
+ @Test
+ public void testRemove() {
+ list.add(0,1);
+ System.out.println(list.remove(0));
+ assertEquals(0, list.size());
+ }
+
+ @Test
+ public void testSize() {
+
+ for(int i = 0; i < 10; i++){
+ list.add(i, i);
+ }
+
+ assertEquals(10, list.size());
+ }
+
+ @Test
+ public void testIterator() {
+
+ for(int i = 0; i < 10; i++){
+ list.add(i, i);
+ }
+ Iterator iterator = list.iterator();
+ int i = 0;
+ while(iterator.hasNext()){
+ assertEquals(i++, iterator.next());
+ }
+ //iterator.next();
+ }
+}
diff --git a/group01/2137642225/work01/src/com/coding/test/TestQueue.java b/group01/2137642225/work01/src/com/coding/test/TestQueue.java
index 367a44d151..d4eb8288b1 100644
--- a/group01/2137642225/work01/src/com/coding/test/TestQueue.java
+++ b/group01/2137642225/work01/src/com/coding/test/TestQueue.java
@@ -1,36 +1,36 @@
-package com.coding.test;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.coding.mybasic.Queue;
-
-public class TestQueue {
-
- private Queue queue;
- @Before
- public void before(){
- queue = new Queue();
- queue.enQueue(1);
- queue.enQueue(2);
- }
- @Test
- public void testEnQueue() {
- queue.enQueue(3);
- assertEquals(3, queue.size());
- }
-
- @Test
- public void testDeQueue() {
- assertEquals(2, queue.deQueue());
- assertEquals(1, queue.deQueue());
- }
-
- @Test
- public void testSize() {
- assertEquals(2, queue.size());
- }
-
-}
+package com.coding.test;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.coding.mybasic.Queue;
+
+public class TestQueue {
+
+ private Queue queue;
+ @Before
+ public void before(){
+ queue = new Queue();
+ queue.enQueue(1);
+ queue.enQueue(2);
+ }
+ @Test
+ public void testEnQueue() {
+ queue.enQueue(3);
+ assertEquals(3, queue.size());
+ }
+
+ @Test
+ public void testDeQueue() {
+ assertEquals(2, queue.deQueue());
+ assertEquals(1, queue.deQueue());
+ }
+
+ @Test
+ public void testSize() {
+ assertEquals(2, queue.size());
+ }
+
+}
diff --git a/group01/2137642225/work01/src/com/coding/test/TestStack.java b/group01/2137642225/work01/src/com/coding/test/TestStack.java
index 0e278f2992..f3bade5eb6 100644
--- a/group01/2137642225/work01/src/com/coding/test/TestStack.java
+++ b/group01/2137642225/work01/src/com/coding/test/TestStack.java
@@ -1,49 +1,49 @@
-package com.coding.test;
-
-import static org.junit.Assert.*;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.coding.mybasic.Stack;
-
-public class TestStack {
-
- private Stack stack;
- @Before
- public void before() {
- stack = new Stack();
- stack.push(1);
- stack.push(2);
- stack.push(3);
- }
-
- @Test
- public void testPush() {
- assertEquals(3, stack.peek());
- }
-
- @Test
- public void testPop() {
- assertEquals(3, stack.pop());
- assertEquals(2, stack.pop());
- assertEquals(1, stack.pop());
- //stack.pop();
- //System.out.println(stack.size());
- }
-
- @Test
- public void testPeek() {
- assertEquals(3, stack.peek());
- assertEquals(3, stack.pop());
- assertEquals(2, stack.pop());
- //assertEquals(1, stack.pop());
- assertEquals(1, stack.peek());
- }
-
- @Test
- public void testSize() {
- assertEquals(3, stack.size());
- }
-
-}
+package com.coding.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.coding.mybasic.Stack;
+
+public class TestStack {
+
+ private Stack stack;
+ @Before
+ public void before() {
+ stack = new Stack();
+ stack.push(1);
+ stack.push(2);
+ stack.push(3);
+ }
+
+ @Test
+ public void testPush() {
+ assertEquals(3, stack.peek());
+ }
+
+ @Test
+ public void testPop() {
+ assertEquals(3, stack.pop());
+ assertEquals(2, stack.pop());
+ assertEquals(1, stack.pop());
+ //stack.pop();
+ //System.out.println(stack.size());
+ }
+
+ @Test
+ public void testPeek() {
+ assertEquals(3, stack.peek());
+ assertEquals(3, stack.pop());
+ assertEquals(2, stack.pop());
+ //assertEquals(1, stack.pop());
+ assertEquals(1, stack.peek());
+ }
+
+ @Test
+ public void testSize() {
+ assertEquals(3, stack.size());
+ }
+
+}
diff --git a/group01/2137642225/work02/.classpath b/group01/2137642225/work02/.classpath
new file mode 100644
index 0000000000..dfa83d7793
--- /dev/null
+++ b/group01/2137642225/work02/.classpath
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git "a/group14/1091149131/20170226_\344\275\234\344\270\2321_\346\225\260\346\215\256\347\273\223\346\236\204\345\217\212\346\226\207\347\253\240/basicstructuredemo/.gitignore" b/group01/2137642225/work02/.gitignore
similarity index 100%
rename from "group14/1091149131/20170226_\344\275\234\344\270\2321_\346\225\260\346\215\256\347\273\223\346\236\204\345\217\212\346\226\207\347\253\240/basicstructuredemo/.gitignore"
rename to group01/2137642225/work02/.gitignore
diff --git a/group01/2137642225/work02/.project b/group01/2137642225/work02/.project
new file mode 100644
index 0000000000..8d10821aba
--- /dev/null
+++ b/group01/2137642225/work02/.project
@@ -0,0 +1,17 @@
+
+
+ work02
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group01/2137642225/work02/.settings/org.eclipse.jdt.core.prefs b/group01/2137642225/work02/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000000..7341ab1683
--- /dev/null
+++ b/group01/2137642225/work02/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/group01/2137642225/work02/README.md b/group01/2137642225/work02/README.md
new file mode 100644
index 0000000000..ce9e536748
--- /dev/null
+++ b/group01/2137642225/work02/README.md
@@ -0,0 +1 @@
+-- 实现数组工具类和读取xml
\ No newline at end of file
diff --git a/group01/2137642225/work02/src/com/coderising/array/ArrayUtil.java b/group01/2137642225/work02/src/com/coderising/array/ArrayUtil.java
new file mode 100644
index 0000000000..0c3dd816c9
--- /dev/null
+++ b/group01/2137642225/work02/src/com/coderising/array/ArrayUtil.java
@@ -0,0 +1,236 @@
+package com.coderising.array;
+
+public class ArrayUtil {
+
+ /**
+ * 给定一个整形数组a , 对该数组的值进行置换
+ 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7]
+ 如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7]
+ * @param origin
+ * @return
+ */
+ public void reverseArray(int[] origin){
+ if (origin != null && origin.length > 1) {
+ int len = origin.length;
+ int temp;
+ for(int left = 0,right = len - 1; left < right; left++,right = len - left - 1){
+ temp = origin[left];
+ origin[left] = origin[right];
+ origin[right] = temp;
+ }
+ }
+ }
+
+ /**
+ * 现在有如下的一个数组: int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5}
+ * 要求将以上数组中值为0的项去掉,将不为0的值存入一个新的数组,生成的新数组为:
+ * {1,3,4,5,6,6,5,4,7,6,7,5}
+ * @param oldArray
+ * @return
+ */
+ public int[] removeZero(int[] oldArray){
+ int[] newArray = null;
+ if (oldArray != null && oldArray.length > 0) {
+ int[] indexArray = new int[oldArray.length];
+ int j = 0;
+ for (int i = 0; i < oldArray.length; i++) {
+ if(oldArray[i] != 0){
+ indexArray[j++] = i;
+ }
+ }
+ newArray = new int[j];
+ for (int i = 0; i < j; i++) {
+ newArray[i] = oldArray[indexArray[i]];
+ }
+ indexArray = null;
+ }
+ return newArray;
+ }
+
+ /**
+ * 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的
+ * 例如 a1 = [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复
+ * @param array1
+ * @param array2
+ * @return
+ */
+
+ public int[] merge(int[] array1, int[] array2){
+ if(array1 == null || array1.length <= 0){
+ return array2;
+ }
+ if(array2 == null || array2.length <= 0){
+ return array1;
+ }
+ int[] tempArray = new int[array1.length + array2.length];
+ int i = 0,j = 0,k = 0;
+ for (; i < array1.length && j < array2.length; ) {
+ if (array1[i] > array2[j]) {
+ tempArray[k++] = array2[j++];
+ }
+ else if(array1[i] < array2[j]){
+ tempArray[k++] = array1[i++];
+ }
+ else {
+ tempArray[k++] = array1[i++];
+ j++;
+ }
+ }
+ // 以array1为结束点
+ if(array1[array1.length - 1] > array2[array2.length - 1]){
+ for (; i < array1.length;) {
+ tempArray[k++] = array1[i++];
+ }
+ } else { // 以array2为结束点
+ for (; j < array2.length;) {
+ tempArray[k++] = array1[j++];
+ }
+ }
+ int[] mergeArray = new int[k];
+ for (int l = 0; l < mergeArray.length; l++) {
+ mergeArray[l] = tempArray[l];
+ }
+ tempArray = null;
+ return mergeArray;
+ }
+ /**
+ * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
+ * 注意,老数组的元素在新数组中需要保持
+ * 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
+ * [2,3,6,0,0,0]
+ * @param oldArray
+ * @param size
+ * @return
+ */
+ public int[] grow(int [] oldArray, int size){
+ if(size <= 0){
+ throw new RuntimeException("size大于0");
+ }
+ int[] newArray = null;
+ if(oldArray != null && oldArray.length > 0){
+ newArray = new int[oldArray.length + size];
+ for (int i = 0; i < oldArray.length; i++) {
+ newArray[i] = oldArray[i];
+ }
+ }
+ return newArray;
+ }
+
+ /**
+ * 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列
+ * 例如, max = 15 , 则返回的数组应该为 [1,1,2,3,5,8,13]
+ * max = 1, 则返回空数组 []
+ * @param max
+ * @return
+ */
+ public int[] fibonacci(int max){
+ if(max <= 1){
+ return new int[0];
+ }
+ int[] tempArray = new int[max];
+ int i = 0;
+ tempArray[i++] = 1;
+ tempArray[i] = 1;
+ while(tempArray[i] < max){
+ i++;
+ tempArray[i] = tempArray[i - 1] + tempArray[i - 2];
+ }
+ int[] array = new int[i];
+ for (int j = 0; j < array.length; j++) {
+ array[j] = tempArray[j];
+ }
+ tempArray = null;
+ return array;
+ }
+
+ /**
+ * 返回小于给定最大值max的所有素数数组
+ * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ * @param max
+ * @return
+ */
+ public int[] getPrimes(int max){
+ if(max <= 2){
+ return new int[0];
+ }
+ int[] tempArray = new int[max];
+ int j = 0;
+ for (int i = 2; i < max; i++) {
+ if(isPrime(i)){
+ tempArray[j++] = i;
+ }
+ }
+ int[] array = new int[j];
+ for (int i = 0; i < j; i++) {
+ array[i] = tempArray[i];
+ }
+ tempArray = null;
+ return array;
+ }
+
+ private boolean isPrime(int i) {
+ for (int j = 2; j < i; j++) {
+ if(i % j == 0){
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
+ * 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
+ * @param max
+ * @return
+ */
+ public int[] getPerfectNumbers(int max){
+ if(max <= 2){
+ return new int[0];
+ }
+ int[] tempArray = new int[max];
+ int j = 0;
+ for (int i = 3; i < max; i++) {
+ if(isPerfectNumber(i)){
+ tempArray[j++] = i;
+ }
+ }
+ int[] array = new int[j];
+ for (int i = 0; i < j; i++) {
+ array[i] = tempArray[i];
+ }
+ tempArray = null;
+ return array;
+ }
+
+ private boolean isPerfectNumber(int num) {
+ int sum = 1;
+ for(int i = 2; i < num; i++){
+ if(num % i == 0){
+ sum += i;
+ }
+ }
+ if(sum == num){
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * 用seperator 把数组 array给连接起来
+ * 例如array= [3,8,9], seperator = "-"
+ * 则返回值为"3-8-9"
+ * @param array
+ * @param s
+ * @return
+ */
+ public String join(int[] array, String seperator){
+ char[] chars = new char[array.length<<1];
+ for (int i = 0,j = 1; i < chars.length; i+=2,j+=2) {
+ chars[i] = (char) (array[i>>1] + 48);
+ chars[j] = seperator.charAt(0);
+ }
+ return new String(chars, 0, chars.length - 1);
+ }
+
+
+}
diff --git a/group01/2137642225/work02/src/com/coderising/litestruts/LoginAction.java b/group01/2137642225/work02/src/com/coderising/litestruts/LoginAction.java
new file mode 100644
index 0000000000..dcdbe226ed
--- /dev/null
+++ b/group01/2137642225/work02/src/com/coderising/litestruts/LoginAction.java
@@ -0,0 +1,39 @@
+package com.coderising.litestruts;
+
+/**
+ * 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。
+ * @author liuxin
+ *
+ */
+public class LoginAction{
+ private String name ;
+ private String password;
+ private String message;
+
+ public String getName() {
+ return name;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String execute(){
+ if("test".equals(name) && "1234".equals(password)){
+ this.message = "login successful";
+ return "success";
+ }
+ this.message = "login failed,please check your user/pwd";
+ return "fail";
+ }
+
+ public void setName(String name){
+ this.name = name;
+ }
+ public void setPassword(String password){
+ this.password = password;
+ }
+ public String getMessage(){
+ return this.message;
+ }
+}
diff --git a/group01/2137642225/work02/src/com/coderising/litestruts/Struts.java b/group01/2137642225/work02/src/com/coderising/litestruts/Struts.java
new file mode 100644
index 0000000000..62a1705c41
--- /dev/null
+++ b/group01/2137642225/work02/src/com/coderising/litestruts/Struts.java
@@ -0,0 +1,338 @@
+package com.coderising.litestruts;
+
+import java.io.File;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+
+
+@SuppressWarnings("unchecked")
+public class Struts {
+
+ public static View runAction(String actionName, Map parameters) {
+
+ if(actionName == null || actionName.trim().equals("")){
+ throw new RuntimeException("传入的actionName不能为null或者空");
+ }
+
+ // 0. 读取配置文件struts.xml ok
+ URL resource = Struts.class.getResource("/com/coderising/litestruts");
+ String path = "";
+ try {
+ path = URLDecoder.decode(resource.getPath(), "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Map> actionMap = xmlParse(path + File.separator + "struts.xml");
+
+ // 找到访问的action通过actionName
+ Map action = findAction(actionName,actionMap);
+
+ //1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
+ //据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是
+ //("name"="test" , "password"="1234") ,
+ //那就应该调用 setName和setPassword方法
+ // 实例化对象
+ String className = (String) action.get("class");
+ Class> clazz = getActionClassByClassName(className);
+ Object actionObject = buildActionObject(clazz,parameters);
+
+ //2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
+ // 执行访问的方法
+ String result = (String) executeAccessMethod(actionObject,clazz,"execute");
+
+ //3. 通过反射找到对象的所有getter方法(例如 getMessage),
+ //通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} ,
+ //放到View对象的parameters
+ Map parameterMap = getActionObjectParameters(actionObject,clazz);
+
+ //4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
+ //放到View对象的jsp字段中。
+ String jsp = getViewPath(action,result);
+ View v = buildView(jsp,parameterMap);
+
+ return v;
+ }
+
+ private static Class> getActionClassByClassName(String className) {
+
+ if(className == null || className.trim().equals("")){
+ throw new RuntimeException("没有配置action的class属性");
+ }
+
+ try {
+ return Class.forName(className);
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * 获取配置文件中视图的路径
+ * @param action
+ * @param result
+ * @return
+ */
+ private static String getViewPath(Map action, String result) {
+
+ if(result != null && !result.trim().equals("")){
+
+ List