diff --git a/.gitignore b/.gitignore
index dbf44ab662..d749cfbd62 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,26 +1,21 @@
-*.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
-
-
-#macOS
-.DS_Store
-
-.idea/
-*.iml
-rebel.*
-.rebel.*
-
+*.class
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.ear
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+
+#ide config
+.metadata
+.recommenders
+.idea/
+*.iml
+rebel.*
+.rebel.*
+
+target
diff --git a/.project b/.project
new file mode 100644
index 0000000000..6b4d50ed9a
--- /dev/null
+++ b/.project
@@ -0,0 +1,11 @@
+
+
+ coding2017
+
+
+
+
+
+
+
+
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000000..4824b80263
--- /dev/null
+++ b/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+encoding/=UTF-8
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/src/week01/basic/Iterator.java b/group01/1298552064/src/week01/basic/Iterator.java
new file mode 100644
index 0000000000..e209875b54
--- /dev/null
+++ b/group01/1298552064/src/week01/basic/Iterator.java
@@ -0,0 +1,8 @@
+package week01.basic;
+
+public interface Iterator {
+ public boolean hasNext();
+
+ public Object next();
+
+}
diff --git a/group01/1298552064/src/week01/basic/List.java b/group01/1298552064/src/week01/basic/List.java
new file mode 100644
index 0000000000..608c1b532b
--- /dev/null
+++ b/group01/1298552064/src/week01/basic/List.java
@@ -0,0 +1,13 @@
+package week01.basic;
+
+public interface List {
+ public void add(Object o);
+
+ public void add(int index, Object o);
+
+ public Object get(int index);
+
+ public Object remove(int index);
+
+ public int size();
+}
diff --git a/group01/1298552064/src/week01/basic/MyArrayList.java b/group01/1298552064/src/week01/basic/MyArrayList.java
new file mode 100644
index 0000000000..c4f6572f1c
--- /dev/null
+++ b/group01/1298552064/src/week01/basic/MyArrayList.java
@@ -0,0 +1,131 @@
+package week01.basic;
+
+import java.util.Arrays;
+
+public class MyArrayList implements List {
+
+ private int size = 0;
+
+ private Object[] elementData = new Object[100];
+
+ public void add(Object o) {
+ ensureCapacity(size + 1);
+
+ elementData[size++] = o;
+ }
+
+ public void add(int index, Object o) {
+ checkPositionIndex(index);
+ ensureCapacity(size + 1);
+
+ if (index >= size) {
+ elementData[size++] = o;
+ } else {
+ System.arraycopy(elementData, index, elementData, index + 1, size
+ - index);
+
+ elementData[index] = o;
+
+ size++;
+ }
+ }
+
+ public Object get(int index) {
+ checkElementIndex(index);
+ return elementData[index];
+ }
+
+ public Object remove(int index) {
+ checkElementIndex(index);
+ Object removeElement = elementData[index];
+ if (index == (size - 1)) {
+ elementData[index] = null;
+ size--;
+ } else {
+ System.arraycopy(elementData, index + 1, elementData, index, size
+ - index - 1);
+ elementData[size - 1] = null;
+ size--;
+ }
+ return removeElement;
+ }
+
+ public int size() {
+ return size;
+ }
+
+ /**
+ * 保证数组空间充足
+ *
+ * @param minCapacity
+ */
+ private void ensureCapacity(int minCapacity) {
+ int capacity = elementData.length;
+ if (minCapacity > capacity) {
+ capacity += capacity / 2;
+ grow(capacity);
+ }
+ }
+
+ private void checkElementIndex(int index) {
+ if (!isElementIndex(index)) {
+ throw new IndexOutOfBoundsException("Index: " + index + ", Size: "
+ + size);
+ }
+ }
+
+ private boolean isElementIndex(int index) {
+ return index >= 0 && index < size;
+ }
+
+ private void checkPositionIndex(int index) {
+ if (!isPositionIndex(index)) {
+ throw new IndexOutOfBoundsException("Index: " + index + ", Size: "
+ + size);
+ }
+ }
+
+ private boolean isPositionIndex(int index) {
+ return index >= 0 && index <= size;
+ }
+
+ private void grow(int newCapacity) {
+ elementData = Arrays.copyOf(elementData, newCapacity);
+ }
+
+ public Iterator iterator() {
+ return new ArrayListIterator(this);
+ }
+
+ private class ArrayListIterator implements Iterator {
+ private MyArrayList list;
+ private int position = 0;
+
+ private ArrayListIterator(MyArrayList list) {
+ this.list = list;
+ }
+
+ @Override
+ public boolean hasNext() {
+ if ((position + 1) > size) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public Object next() {
+ return list.get(position++);
+ }
+ }
+
+ @Override
+ public String toString() {
+ String elementStr = "";
+ for (int i = 0; i < size; i++) {
+ elementStr += elementData[i] + ",";
+ }
+ return "MyArrayList: { size=" + size + ", elementData=" + "["
+ + elementStr.substring(0, elementStr.length() - 1) + "]" + " }";
+ }
+}
diff --git a/group01/1298552064/src/week01/basic/MyBinaryTreeNode.java b/group01/1298552064/src/week01/basic/MyBinaryTreeNode.java
new file mode 100644
index 0000000000..30e6c810a5
--- /dev/null
+++ b/group01/1298552064/src/week01/basic/MyBinaryTreeNode.java
@@ -0,0 +1,70 @@
+package week01.basic;
+
+public class MyBinaryTreeNode {
+
+ private Object data;
+ private MyBinaryTreeNode left;
+ private MyBinaryTreeNode right;
+
+ public Object getData() {
+ return data;
+ }
+
+ public void setData(Object data) {
+ this.data = data;
+ }
+
+ public MyBinaryTreeNode getLeft() {
+ return left;
+ }
+
+ public void setLeft(MyBinaryTreeNode left) {
+ this.left = left;
+ }
+
+ public MyBinaryTreeNode getRight() {
+ return right;
+ }
+
+ public void setRight(MyBinaryTreeNode right) {
+ this.right = right;
+ }
+
+ public MyBinaryTreeNode insert(Object o) {
+ if(this.getData() == null && this.getLeft() == null && this.getRight() == null){
+ this.setData(o);
+ this.setLeft(null);
+ this.setRight(null);
+ return this;
+ }
+
+ MyBinaryTreeNode node = new MyBinaryTreeNode();
+ MyBinaryTreeNode currentNode = this;
+ while(true){
+ if((Integer) o < (Integer) getData()){
+ if(currentNode.getLeft() == null){
+ node.setData(o);
+ node.setLeft(null);
+ node.setRight(null);
+
+ currentNode.setLeft(node);
+ return this;
+ }else{
+ currentNode = currentNode.getLeft();
+ }
+
+ }else{
+ if(currentNode.getRight() == null){
+ node.setData(o);
+ node.setLeft(null);
+ node.setRight(null);
+
+ currentNode.setRight(node);
+ return this;
+ }else{
+ currentNode = currentNode.getRight();
+ }
+ }
+ }
+ }
+}
diff --git a/group01/1298552064/src/week01/basic/MyLinkedList.java b/group01/1298552064/src/week01/basic/MyLinkedList.java
new file mode 100644
index 0000000000..4894c5ff6c
--- /dev/null
+++ b/group01/1298552064/src/week01/basic/MyLinkedList.java
@@ -0,0 +1,215 @@
+package week01.basic;
+
+public class MyLinkedList implements List {
+
+ private Node head;
+ private int size;
+
+ public void add(Object o) {
+ // 空链表
+ if (head == null) {
+ head = new Node();
+ head.data = o;
+ head.next = null;
+ } else {
+ Node p = head;
+ while (p.next != null) {
+ p = p.next;
+ }
+
+ Node target = new Node();
+ target.data = o;
+ target.next = null;
+ p.next = target;
+ }
+ size++;
+ }
+
+ public void add(int index, Object o) {
+ // index 是否合法
+ checkPositionIndex(index);
+ if (head == null) {
+ head = new Node();
+ head.data = o;
+ head.next = null;
+ } else {
+ if (index == 0) {
+ addFirst(o);
+ } else if (index == size) {
+ addLast(o);
+ } else {
+ Node p = new Node();
+ Node p1 = head;
+ for (int i = 0; i < index - 1; i++) {
+ p1 = p1.next;
+ }
+ p.data = o;
+ p.next = p1.next;
+ p1.next = p;
+
+ size++;
+ }
+ }
+ }
+
+ public Object get(int index) {
+ checkElementIndex(index);
+ Node p = head;
+ for (int i = 0; i < index; i++) {
+ p = p.next;
+ }
+ return p.data;
+ }
+
+ public Object remove(int index) {
+ checkElementRemove();
+ checkElementIndex(index);
+
+ Object removeObject = null;
+ if (index == 0) {
+ removeObject = removeFirst();
+ } else if (index == (size - 1)) {
+ removeObject = removeLast();
+ } else {
+ Node p = head;
+ for (int i = 1; i < index; i++) {
+ p = p.next;
+ }
+ removeObject = p.next.data;
+ p.next = p.next.next;
+ size--;
+ }
+ return removeObject;
+ }
+
+ public int size() {
+ return size;
+ }
+
+ public void addFirst(Object o) {
+ if (head == null) {
+ head = new Node();
+ head.data = o;
+ head.next = null;
+ } else {
+ Node p = new Node();
+ p.data = o;
+ p.next = head;
+ head = p;
+ }
+ size++;
+ }
+
+ public void addLast(Object o) {
+ add(o);
+ }
+
+ public Object removeFirst() {
+ checkElementRemove();
+ Object removeObject = head.data;
+ head = head.next;
+ size--;
+ return removeObject;
+ }
+
+ public Object removeLast() {
+ checkElementRemove();
+
+ Object removeObject = null;
+
+ if (size == 1) {
+ removeObject = head.data;
+ head = head.next;
+ } else {
+ Node p = head;
+ for (int i = 0; i < size; i++) {
+ if (p.next.next == null) {
+ removeObject = p.next;
+ p.next = null;
+ break;
+ } else {
+ p = p.next;
+ }
+ }
+ }
+ size--;
+ return removeObject;
+ }
+
+ private boolean isEmpty() {
+ return size == 0;
+ }
+
+ private void checkElementRemove() {
+ if (isEmpty()) {
+ throw new NullPointerException("The list is empty.");
+ }
+ }
+
+ private void checkElementIndex(int index) {
+ if (!isElementIndex(index)) {
+ throw new IndexOutOfBoundsException("Index: " + index + ", Size: "
+ + size);
+ }
+ }
+
+ private boolean isElementIndex(int index) {
+ return index >= 0 && index < size;
+ }
+
+ private void checkPositionIndex(int index) {
+ if (!isPositionIndex(index)) {
+ throw new IndexOutOfBoundsException("Index: " + index + ", Size: "
+ + size);
+ }
+ }
+
+ private boolean isPositionIndex(int index) {
+ return index >= 0 && index <= size;
+ }
+
+ public Iterator iterator() {
+ return new MyLinkedListIterator(this);
+ }
+
+ private class MyLinkedListIterator implements Iterator {
+ private MyLinkedList list = null;
+ private int position = 0;
+
+ private MyLinkedListIterator(MyLinkedList list) {
+ this.list = list;
+ }
+
+ @Override
+ public boolean hasNext() {
+ if ((position + 1) > size()) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public Object next() {
+ return list.get(position++);
+ }
+ }
+
+ private static class Node {
+ Object data;
+ Node next;
+ }
+
+ @Override
+ public String toString() {
+ String elementStr = "";
+ Node p = head;
+ while (p != null) {
+ elementStr += p.data + ",";
+ p = p.next;
+ }
+
+ return "MyLinkedList: { size=" + size + ", elementData=" + "["
+ + elementStr.substring(0, elementStr.length() - 1) + "]" + " }";
+ }
+
+}
diff --git a/group01/1298552064/src/week01/basic/MyQueue.java b/group01/1298552064/src/week01/basic/MyQueue.java
new file mode 100644
index 0000000000..54008652ff
--- /dev/null
+++ b/group01/1298552064/src/week01/basic/MyQueue.java
@@ -0,0 +1,22 @@
+package week01.basic;
+
+public class MyQueue {
+
+ private MyLinkedList elementData = new MyLinkedList();
+
+ public void enQueue(Object o) {
+ elementData.add(o);
+ }
+
+ public Object deQueue() {
+ return elementData.removeFirst();
+ }
+
+ public boolean isEmpty() {
+ return elementData.size() == 0;
+ }
+
+ public int size() {
+ return elementData.size();
+ }
+}
diff --git a/group01/1298552064/src/week01/basic/MyStack.java b/group01/1298552064/src/week01/basic/MyStack.java
new file mode 100644
index 0000000000..aea4d94e24
--- /dev/null
+++ b/group01/1298552064/src/week01/basic/MyStack.java
@@ -0,0 +1,25 @@
+package week01.basic;
+
+public class MyStack {
+ private MyArrayList elementData = new MyArrayList();
+
+ public void push(Object o) {
+ elementData.add(o);
+ }
+
+ public Object pop() {
+ return elementData.remove(size() - 1);
+ }
+
+ public Object peek() {
+ return elementData.get(size() - 1);
+ }
+
+ public boolean isEmpty() {
+ return elementData.size() == 0;
+ }
+
+ public int size() {
+ return elementData.size();
+ }
+}
diff --git a/group01/1298552064/src/week01/test/MyArrayListTest.java b/group01/1298552064/src/week01/test/MyArrayListTest.java
new file mode 100644
index 0000000000..219035b46f
--- /dev/null
+++ b/group01/1298552064/src/week01/test/MyArrayListTest.java
@@ -0,0 +1,53 @@
+package week01.test;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import week01.basic.MyArrayList;
+
+
+
+public class MyArrayListTest {
+
+ private MyArrayList list = null;
+
+ @Before
+ public void setUp() throws Exception {
+ list = new MyArrayList();
+
+ list.add(1);
+ list.add(2);
+ list.add(3);
+ list.add(4);
+ list.add(5);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ list = null;
+ }
+
+ @Test
+ public void testAdd(){
+ list.add(4, 10);
+ Assert.assertEquals("MyArrayList: { size=6, elementData=[1,2,3,4,10,5] }", list.toString());
+ }
+
+ @Test
+ public void testGet(){
+ Assert.assertEquals((Object)new Integer(3), list.get(2));
+ }
+
+ @Test
+ public void testRemove(){
+ list.remove(2);
+ Assert.assertEquals("MyArrayList: { size=4, elementData=[1,2,4,5] }", list.toString());
+ }
+
+ @Test
+ public void testSize(){
+ Assert.assertEquals((Object)new Integer(5), list.size());
+ }
+}
diff --git a/group01/1298552064/src/week01/test/MyLinkedListTest.java b/group01/1298552064/src/week01/test/MyLinkedListTest.java
new file mode 100644
index 0000000000..b5d6c048d6
--- /dev/null
+++ b/group01/1298552064/src/week01/test/MyLinkedListTest.java
@@ -0,0 +1,78 @@
+package week01.test;
+
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import week01.basic.MyLinkedList;
+
+public class MyLinkedListTest {
+
+ private MyLinkedList list = null;
+
+ @Before
+ public void setUp() throws Exception {
+ list = new MyLinkedList();
+
+ list.add(1);
+ list.add(2);
+ list.add(3);
+ list.add(4);
+ list.add(5);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ list = null;
+ }
+
+
+ @Test
+ public void testAdd(){
+ list.add(3,10);
+ Assert.assertEquals("MyLinkedList: { size=6, elementData=[1,2,3,10,4,5] }",list.toString());
+ }
+
+ @Test
+ public void testAddFirst(){
+ list.addFirst(100);
+ Assert.assertEquals("MyLinkedList: { size=6, elementData=[100,1,2,3,4,5] }",list.toString());
+ }
+
+ @Test
+ public void testAddLast(){
+ list.addLast(100);
+ Assert.assertEquals("MyLinkedList: { size=6, elementData=[1,2,3,4,5,100] }",list.toString());
+ }
+
+ @Test
+ public void testGet(){
+ Assert.assertEquals((Object)new Integer(5), list.get(4));
+ }
+
+ @Test
+ public void testRemove(){
+ list.remove(3);
+ Assert.assertEquals("MyLinkedList: { size=4, elementData=[1,2,3,5] }",list.toString());
+ }
+
+ @Test
+ public void testRemoveFirst(){
+ list.removeFirst();
+ Assert.assertEquals("MyLinkedList: { size=4, elementData=[2,3,4,5] }",list.toString());
+ }
+
+ @Test
+ public void testRemoveLast(){
+ list.removeLast();
+ Assert.assertEquals("MyLinkedList: { size=4, elementData=[1,2,3,4] }",list.toString());
+ }
+
+ @Test
+ public void testSize(){
+ Assert.assertEquals((Object)new Integer(5), list.size());
+ }
+
+}
diff --git a/group01/1298552064/src/week01/test/MyQueueTest.java b/group01/1298552064/src/week01/test/MyQueueTest.java
new file mode 100644
index 0000000000..f9b7cb63f2
--- /dev/null
+++ b/group01/1298552064/src/week01/test/MyQueueTest.java
@@ -0,0 +1,48 @@
+package week01.test;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import week01.basic.MyQueue;
+
+public class MyQueueTest {
+
+ private MyQueue queue = null;
+
+ @Before
+ public void setUp() throws Exception {
+ queue = new MyQueue();
+
+ queue.enQueue(1);
+ queue.enQueue(2);
+ queue.enQueue(3);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ queue = null;
+ }
+
+ @Test
+ public void testEnQueue(){
+ queue.enQueue(4);
+ Assert.assertEquals((Object)new Integer(4), queue.size());
+ }
+
+ @Test
+ public void testDeQueue(){
+ Assert.assertEquals((Object) new Integer(1), queue.deQueue());
+ }
+
+ @Test
+ public void testIsEmpty(){
+ Assert.assertFalse(queue.isEmpty());
+ }
+
+ @Test
+ public void testSize(){
+ Assert.assertEquals((Object)new Integer(3), queue.size());
+ }
+}
diff --git a/group01/1298552064/src/week01/test/MyStackTest.java b/group01/1298552064/src/week01/test/MyStackTest.java
new file mode 100644
index 0000000000..4efbc2b204
--- /dev/null
+++ b/group01/1298552064/src/week01/test/MyStackTest.java
@@ -0,0 +1,53 @@
+package week01.test;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import week01.basic.MyStack;
+
+public class MyStackTest {
+ private MyStack stack = null;
+
+ @Before
+ public void setUp() throws Exception {
+ stack = new MyStack();
+
+ stack.push(1);
+ stack.push(2);
+ stack.push(3);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ stack = null;
+ }
+
+ @Test
+ public void tearPush() throws Exception {
+ stack.push(10);
+ Assert.assertEquals((Object) new Integer(4), stack.size());
+ Assert.assertEquals((Object) new Integer(10), stack.peek());
+ }
+
+ @Test
+ public void testPop(){
+ Assert.assertEquals((Object) new Integer(3), stack.pop());
+ Assert.assertEquals((Object) new Integer(2), stack.size());
+ }
+
+ @Test
+ public void testPeek(){
+ Assert.assertEquals((Object) new Integer(3), stack.peek());
+ }
+
+ @Test
+ public void testIsEmpty(){
+ Assert.assertFalse(stack.isEmpty());
+ }
+
+ @Test
+ public void testSize(){
+ Assert.assertEquals((Object) new Integer(3), stack.size());
+ }
+}
diff --git a/group01/1328404806/RemoteSystemsTempFiles/.project b/group01/1328404806/RemoteSystemsTempFiles/.project
new file mode 100644
index 0000000000..7675629320
--- /dev/null
+++ b/group01/1328404806/RemoteSystemsTempFiles/.project
@@ -0,0 +1,12 @@
+
+
+ RemoteSystemsTempFiles
+
+
+
+
+
+
+ org.eclipse.rse.ui.remoteSystemsTempNature
+
+
diff --git a/group01/1328404806/dataStructure/.classpath b/group01/1328404806/dataStructure/.classpath
new file mode 100644
index 0000000000..7faf63dc05
--- /dev/null
+++ b/group01/1328404806/dataStructure/.classpath
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/group17/82427129/JavaUtil/.gitignore b/group01/1328404806/dataStructure/.gitignore
similarity index 90%
rename from group17/82427129/JavaUtil/.gitignore
rename to group01/1328404806/dataStructure/.gitignore
index 24d64373c4..b83d22266a 100644
--- a/group17/82427129/JavaUtil/.gitignore
+++ b/group01/1328404806/dataStructure/.gitignore
@@ -1 +1 @@
-/target/
+/target/
diff --git a/group01/1328404806/dataStructure/.project b/group01/1328404806/dataStructure/.project
new file mode 100644
index 0000000000..86bf42de91
--- /dev/null
+++ b/group01/1328404806/dataStructure/.project
@@ -0,0 +1,23 @@
+
+
+ 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
new file mode 100644
index 0000000000..4c28b1a898
--- /dev/null
+++ b/group01/1328404806/dataStructure/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,4 @@
+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
new file mode 100644
index 0000000000..8626026241
--- /dev/null
+++ b/group01/1328404806/dataStructure/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +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
new file mode 100644
index 0000000000..14b697b7bb
--- /dev/null
+++ b/group01/1328404806/dataStructure/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/group01/1328404806/dataStructure/pom.xml b/group01/1328404806/dataStructure/pom.xml
new file mode 100644
index 0000000000..0b5e3a1ca3
--- /dev/null
+++ b/group01/1328404806/dataStructure/pom.xml
@@ -0,0 +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
+
+
+
diff --git a/group01/1328404806/dataStructure/src/main/java/ListService/KILinkedList.java b/group01/1328404806/dataStructure/src/main/java/ListService/KILinkedList.java
new file mode 100644
index 0000000000..8f0307f340
--- /dev/null
+++ b/group01/1328404806/dataStructure/src/main/java/ListService/KILinkedList.java
@@ -0,0 +1,10 @@
+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
new file mode 100644
index 0000000000..b0851d30b0
--- /dev/null
+++ b/group01/1328404806/dataStructure/src/main/java/ListService/KIList.java
@@ -0,0 +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();
+
+}
diff --git a/group01/1328404806/dataStructure/src/main/java/ListService/KIQueueList.java b/group01/1328404806/dataStructure/src/main/java/ListService/KIQueueList.java
new file mode 100644
index 0000000000..b02c0e86a5
--- /dev/null
+++ b/group01/1328404806/dataStructure/src/main/java/ListService/KIQueueList.java
@@ -0,0 +1,11 @@
+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
new file mode 100644
index 0000000000..8a1f031976
--- /dev/null
+++ b/group01/1328404806/dataStructure/src/main/java/ListService/KIStackList.java
@@ -0,0 +1,9 @@
+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
new file mode 100644
index 0000000000..d85a8957cf
--- /dev/null
+++ b/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KArrayList.java
@@ -0,0 +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);
+ }
+
+}
diff --git a/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KLinkedList.java b/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KLinkedList.java
new file mode 100644
index 0000000000..6afb12befc
--- /dev/null
+++ b/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KLinkedList.java
@@ -0,0 +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;
+ }
+ }
+
+}
diff --git a/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KQueueList.java b/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KQueueList.java
new file mode 100644
index 0000000000..7ea8643c43
--- /dev/null
+++ b/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KQueueList.java
@@ -0,0 +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;
+ }
+ }
+
+}
diff --git a/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KStackList.java b/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KStackList.java
new file mode 100644
index 0000000000..e2b9ee1186
--- /dev/null
+++ b/group01/1328404806/dataStructure/src/main/java/ListServiceImpl/KStackList.java
@@ -0,0 +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;
+ }
+
+}
diff --git a/group01/1328404806/dataStructure/src/main/java/increaseLearning/dataStructure/App.java b/group01/1328404806/dataStructure/src/main/java/increaseLearning/dataStructure/App.java
new file mode 100644
index 0000000000..018ba70bdb
--- /dev/null
+++ b/group01/1328404806/dataStructure/src/main/java/increaseLearning/dataStructure/App.java
@@ -0,0 +1,13 @@
+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
new file mode 100644
index 0000000000..4fffcb78ed
--- /dev/null
+++ b/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/AppTest.java
@@ -0,0 +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 );
+ }
+}
diff --git a/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/arrayListTest.java b/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/arrayListTest.java
new file mode 100644
index 0000000000..3815775989
--- /dev/null
+++ b/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/arrayListTest.java
@@ -0,0 +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;
+
+ }
+
+}
diff --git a/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/linkedListTest.java b/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/linkedListTest.java
new file mode 100644
index 0000000000..6b42a261fa
--- /dev/null
+++ b/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/linkedListTest.java
@@ -0,0 +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("成功!!!");
+
+ }
+
+}
diff --git a/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/queueListTest.java b/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/queueListTest.java
new file mode 100644
index 0000000000..af4f952f6c
--- /dev/null
+++ b/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/queueListTest.java
@@ -0,0 +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);
+ }
+ }
+
+}
diff --git a/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/stackListTest.java b/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/stackListTest.java
new file mode 100644
index 0000000000..614f18cb8c
--- /dev/null
+++ b/group01/1328404806/dataStructure/src/test/java/increaseLearning/dataStructure/stackListTest.java
@@ -0,0 +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();
+ }
+
+}
diff --git a/group17/102228177/.classpath b/group01/1664823950/.classpath
similarity index 100%
rename from group17/102228177/.classpath
rename to group01/1664823950/.classpath
diff --git a/group18/935542673/Coding/.gitignore b/group01/1664823950/.gitignore
similarity index 100%
rename from group18/935542673/Coding/.gitignore
rename to group01/1664823950/.gitignore
diff --git a/group01/1664823950/.project b/group01/1664823950/.project
new file mode 100644
index 0000000000..6cca5cf64b
--- /dev/null
+++ b/group01/1664823950/.project
@@ -0,0 +1,21 @@
+
+
+<<<<<<< HEAD:group01/1664823950/.project
+ 1664823950
+=======
+ 1264835468
+>>>>>>> master:group17/1264835468/.project
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group01/1664823950/src/com/coding/basic/ArrayList.java b/group01/1664823950/src/com/coding/basic/ArrayList.java
new file mode 100644
index 0000000000..87928e7483
--- /dev/null
+++ b/group01/1664823950/src/com/coding/basic/ArrayList.java
@@ -0,0 +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;
+ }
+
+}
diff --git a/group01/1664823950/src/com/coding/basic/BinaryTreeNode.java b/group01/1664823950/src/com/coding/basic/BinaryTreeNode.java
new file mode 100644
index 0000000000..24710872cb
--- /dev/null
+++ b/group01/1664823950/src/com/coding/basic/BinaryTreeNode.java
@@ -0,0 +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;
+ }
+
+}
diff --git a/group01/1664823950/src/com/coding/basic/Iterator.java b/group01/1664823950/src/com/coding/basic/Iterator.java
new file mode 100644
index 0000000000..e5ccd24b42
--- /dev/null
+++ b/group01/1664823950/src/com/coding/basic/Iterator.java
@@ -0,0 +1,8 @@
+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
new file mode 100644
index 0000000000..2a217b2df7
--- /dev/null
+++ b/group01/1664823950/src/com/coding/basic/LinkedList.java
@@ -0,0 +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
+
+
+
+
+
+
diff --git a/group01/1814014897/zhouhui/.gitignore b/group01/1814014897/zhouhui/.gitignore
new file mode 100644
index 0000000000..ae3c172604
--- /dev/null
+++ b/group01/1814014897/zhouhui/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/group01/1814014897/zhouhui/.project b/group01/1814014897/zhouhui/.project
new file mode 100644
index 0000000000..fab8d7f04c
--- /dev/null
+++ b/group01/1814014897/zhouhui/.project
@@ -0,0 +1,17 @@
+
+
+ 2017Learning
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group01/1814014897/zhouhui/.settings/org.eclipse.jdt.core.prefs b/group01/1814014897/zhouhui/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000000..3a21537071
--- /dev/null
+++ b/group01/1814014897/zhouhui/.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.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+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.8
diff --git a/group01/1814014897/zhouhui/src/week01/BasicDataStructure/ArrayList.java b/group01/1814014897/zhouhui/src/week01/BasicDataStructure/ArrayList.java
new file mode 100644
index 0000000000..23ed3f6bc2
--- /dev/null
+++ b/group01/1814014897/zhouhui/src/week01/BasicDataStructure/ArrayList.java
@@ -0,0 +1,75 @@
+package week01.BasicDataStructure;
+
+import java.util.Arrays;
+
+public class ArrayList implements List {
+
+ private int size = 0;
+
+ private Object[] elementData = new Object[100];
+
+ public void add(Object o){
+ ensureCapacity(size + 1); //size increase,in order to have enough capacity.
+ elementData[size++] = o; //similar to: elementData[size]=o; size++;
+ }
+
+ private void ensureCapacity(int minCapacity){
+ if(minCapacity > elementData.length){
+ grow(minCapacity);
+ }
+ }
+
+ private void grow(int minCapacity){
+ int oldCapacity = elementData.length;
+ int newCapacity = oldCapacity + ( oldCapacity >> 1 );
+ if(newCapacity < minCapacity){
+ newCapacity = minCapacity;
+ }
+ elementData = Arrays.copyOf(elementData, newCapacity);
+
+ }
+
+ public void add(int index, Object o){
+ if(index < 0 || index > size) throw new IndexOutOfBoundsException("Index:"+index+",Size:"+size);
+ ensureCapacity(size+1);
+ System.arraycopy(elementData, index, elementData, index + 1, size - index);
+ elementData[index] = o;
+ size++;
+ }
+
+ public Object get(int index){
+ if(index < 0 || index >= size) throw new IndexOutOfBoundsException("Index:"+index+",Size:"+size);
+ return elementData[index];
+ }
+
+ public Object remove(int index){
+ if(index < 0 || index >= size) throw new IndexOutOfBoundsException("Index:"+index+",Size:"+size);
+ Object data_index = elementData[index];
+ System.arraycopy(elementData, index + 1, elementData, index, size - index - 1);
+ elementData[size - 1] = null;
+ size--;
+ return data_index;
+ }
+
+ public int size(){
+ return size;
+ }
+
+ public Iterator iterator(){
+ return new ArrayListIterator();
+ }
+
+ private class ArrayListIterator implements Iterator{
+
+ private int pos = 0;
+
+ public boolean hasNext() {
+ return pos < size;
+ }
+
+ public Object next() {
+ return elementData[pos++];
+ }
+ }
+
+}
diff --git a/group01/1814014897/zhouhui/src/week01/BasicDataStructure/BinaryTreeNode.java b/group01/1814014897/zhouhui/src/week01/BasicDataStructure/BinaryTreeNode.java
new file mode 100644
index 0000000000..a4fb2cf8b9
--- /dev/null
+++ b/group01/1814014897/zhouhui/src/week01/BasicDataStructure/BinaryTreeNode.java
@@ -0,0 +1,56 @@
+package week01.BasicDataStructure;
+
+public class BinaryTreeNode{
+
+ private Object data;
+ private BinaryTreeNode left;
+ private BinaryTreeNode right;
+
+ public BinaryTreeNode(Object data){
+ this.data = data;
+ left = null;
+ right = null;
+ }
+
+ 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){
+ if((Integer)o < (Integer)this.data)
+ {
+ if(this.left == null){
+ BinaryTreeNode node = new BinaryTreeNode(o);
+ this.setLeft(node);
+ return node;
+ }else{
+ return this.left.insert(o);
+ }
+ }else{
+ if(this.right == null){
+ BinaryTreeNode node = new BinaryTreeNode(o);
+ this.setRight(node);
+ return node;
+ }else{
+ return this.right.insert(o);
+ }
+ }
+ }
+ }
+
+
diff --git a/group01/1814014897/zhouhui/src/week01/BasicDataStructure/Iterator.java b/group01/1814014897/zhouhui/src/week01/BasicDataStructure/Iterator.java
new file mode 100644
index 0000000000..0ad3fff8f3
--- /dev/null
+++ b/group01/1814014897/zhouhui/src/week01/BasicDataStructure/Iterator.java
@@ -0,0 +1,7 @@
+package week01.BasicDataStructure;
+
+public interface Iterator {
+ public boolean hasNext();
+ public Object next();
+
+}
diff --git a/group01/1814014897/zhouhui/src/week01/BasicDataStructure/LinkedList.java b/group01/1814014897/zhouhui/src/week01/BasicDataStructure/LinkedList.java
new file mode 100644
index 0000000000..35b1158cd1
--- /dev/null
+++ b/group01/1814014897/zhouhui/src/week01/BasicDataStructure/LinkedList.java
@@ -0,0 +1,113 @@
+package week01.BasicDataStructure;
+
+public class LinkedList implements List {
+
+ private Node head;
+ private int size = 0;
+
+ public void add(Object o){
+ if(head == null){
+ head = new Node(o);
+ }else{
+ Node pos = head;
+ while(pos.next != null){
+ pos = pos.next;
+ }
+ pos.next = new Node(o);
+ }
+ size++;
+ }
+
+ public void add(int index , Object o){
+ if(index < 0 || index >size ) throw new IndexOutOfBoundsException("Index:"+index+",Size"+size);
+ if(index == 0) {
+ Node node = new Node(o);
+ node.next = head;
+ head = node;
+ }
+ else{
+ Node pos = head;
+ for(int i = 0;i < index-1;i++){
+ pos = pos.next;
+ }
+ Node node = new Node(o);
+ node.next = pos.next;
+ pos.next = node;
+ }
+ size++;
+ }
+
+ public Object get(int index){
+ if(index < 0 || index >=size ) throw new IndexOutOfBoundsException("Index:"+index+",Size"+size);
+ Node pos = head;
+ for(int i = 0;i < index;i++){
+ pos = pos.next;
+ }
+ return pos.data;
+ }
+
+ public Object remove(int index){
+ if(index < 0 || index >=size ) throw new IndexOutOfBoundsException("Index:"+index+",Size:"+size);
+ Node element = head;
+ if(index == 0){
+ head = head.next;
+ }else{
+ Node pos = head;
+ for(int i = 0;i < index - 1;i++){
+ pos = pos.next;
+ }
+ element = pos.next;
+ pos.next = pos.next.next;
+ }
+ size--;
+ return element.data;
+ }
+
+ public int size(){
+ return size;
+ }
+
+ public void addFirst(Object o){
+ add(0,o);
+ }
+ public void addLast(Object o){
+ add(size,o);
+ }
+ public Object removeFirst(){
+ return remove(0);
+ }
+ public Object removeLast(){
+ return remove(size-1);
+ }
+ public Iterator iterator(){
+ return new LinkedListIterator();
+ }
+
+ class LinkedListIterator implements Iterator{
+
+ private Node node = head;
+ private int pos = 0;
+ @Override
+ public boolean hasNext() {
+ return pos < size;
+ }
+
+ @Override
+ public Object next() {
+ pos++;
+ if(pos != 1){
+ node = node.next;
+ }
+ return node.data;
+ }
+ }
+
+ private static class Node{
+ Object data;
+ Node next;
+ public Node(Object data){
+ this.data = data;
+ next = null;
+ }
+ }
+}
diff --git a/group01/1814014897/zhouhui/src/week01/BasicDataStructure/List.java b/group01/1814014897/zhouhui/src/week01/BasicDataStructure/List.java
new file mode 100644
index 0000000000..7806b75ed3
--- /dev/null
+++ b/group01/1814014897/zhouhui/src/week01/BasicDataStructure/List.java
@@ -0,0 +1,9 @@
+package week01.BasicDataStructure;
+
+public interface List {
+ public void add(Object o);
+ public void add(int index, Object o);
+ public Object get(int index);
+ public Object remove(int index);
+ public int size();
+}
diff --git a/group01/1814014897/zhouhui/src/week01/BasicDataStructure/Queue.java b/group01/1814014897/zhouhui/src/week01/BasicDataStructure/Queue.java
new file mode 100644
index 0000000000..e0ab6bbb9c
--- /dev/null
+++ b/group01/1814014897/zhouhui/src/week01/BasicDataStructure/Queue.java
@@ -0,0 +1,25 @@
+package week01.BasicDataStructure;
+
+public class Queue {
+
+ private LinkedList linkedList = new LinkedList();
+ private int size = 0;
+
+ public void enQueue(Object o){
+ linkedList.add(o);
+ size++;
+ }
+
+ public Object deQueue(){
+ size--;
+ return linkedList.removeFirst();
+ }
+
+ public boolean isEmpty(){
+ return linkedList.size() == 0;
+ }
+
+ public int size(){
+ return size;
+ }
+}
diff --git a/group01/1814014897/zhouhui/src/week01/BasicDataStructure/Stack.java b/group01/1814014897/zhouhui/src/week01/BasicDataStructure/Stack.java
new file mode 100644
index 0000000000..53f99b37c7
--- /dev/null
+++ b/group01/1814014897/zhouhui/src/week01/BasicDataStructure/Stack.java
@@ -0,0 +1,25 @@
+package week01.BasicDataStructure;
+
+public class Stack {
+ private ArrayList elementData = new ArrayList();
+ private int size = 0;
+
+ public void push(Object o){
+ elementData.add(o);
+ size++;
+ }
+
+ public Object pop(){
+ return elementData.remove(--size);
+ }
+
+ public Object peek(){
+ return elementData.get(size - 1);
+ }
+ public boolean isEmpty(){
+ return elementData.size() == 0;
+ }
+ public int size(){
+ return elementData.size();
+ }
+}
diff --git a/group01/1814014897/zhouhui/src/week01/BasicDataStructureTest/AllTest.java b/group01/1814014897/zhouhui/src/week01/BasicDataStructureTest/AllTest.java
new file mode 100644
index 0000000000..5d5f07d815
--- /dev/null
+++ b/group01/1814014897/zhouhui/src/week01/BasicDataStructureTest/AllTest.java
@@ -0,0 +1,18 @@
+package week01.BasicDataStructureTest;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+@RunWith(Suite.class)
+@SuiteClasses({
+ ArrayListTest.class,
+ BinaryTreeNodeTest.class,
+ LinkedListTest.class,
+ QueueTest.class,
+ StackTest.class
+})
+
+public class AllTest {
+
+}
diff --git a/group01/1814014897/zhouhui/src/week01/BasicDataStructureTest/ArrayListTest.java b/group01/1814014897/zhouhui/src/week01/BasicDataStructureTest/ArrayListTest.java
new file mode 100644
index 0000000000..c5513acfda
--- /dev/null
+++ b/group01/1814014897/zhouhui/src/week01/BasicDataStructureTest/ArrayListTest.java
@@ -0,0 +1,72 @@
+package week01.BasicDataStructureTest;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import week01.BasicDataStructure.ArrayList;
+import week01.BasicDataStructure.Iterator;
+
+public class ArrayListTest {
+
+ private ArrayList arrayList = new ArrayList();
+
+ @Before
+ public void setUp() throws Exception {
+ for(int i = 0;i < 100 ; i++){
+ arrayList.add(i);
+ }
+ }
+
+ @Test
+ public void testAddObject() {
+ for(int i = 0;i < 100;i++){
+ Assert.assertEquals(arrayList.get(i), i);
+ }
+ }
+
+ @Test
+ public void testAddIntObject() {
+ arrayList.add(0,10);
+ arrayList.add(22, 44);
+ arrayList.add(40, 5);
+ arrayList.add(100,88);
+ Assert.assertEquals(arrayList.get(0), 10);
+ Assert.assertEquals(arrayList.get(22),44);
+ Assert.assertEquals(arrayList.get(40), 5);
+ Assert.assertEquals(arrayList.get(100), 88);
+ }
+
+ @Test
+ public void testGet() {
+ Assert.assertEquals(arrayList.get(0), 0);
+ Assert.assertEquals(arrayList.get(33), 33);
+ Assert.assertEquals(arrayList.get(77), 77);
+ Assert.assertEquals(arrayList.get(99), 99);
+ }
+
+ @Test
+ public void testRemove() {
+ Assert.assertEquals(arrayList.remove(0), 0);
+ Assert.assertEquals(arrayList.remove(0), 1);
+ Assert.assertEquals(arrayList.remove(97), 99);
+ Assert.assertEquals(arrayList.size(), 97);
+ }
+
+ @Test
+ public void testSize() {
+ Assert.assertEquals(arrayList.size(), 100);
+ arrayList.add(5,5);
+ Assert.assertEquals(arrayList.size(),101);
+ arrayList.remove(5);
+ Assert.assertEquals(arrayList.size(), 100);
+ }
+
+ @Test
+ public void testIterator() {
+ Iterator iterator = arrayList.iterator();
+ for(int i=0;iterator.hasNext();i++){
+ Assert.assertEquals(iterator.next(),i);
+ }
+ }
+}
diff --git a/group01/1814014897/zhouhui/src/week01/BasicDataStructureTest/BinaryTreeNodeTest.java b/group01/1814014897/zhouhui/src/week01/BasicDataStructureTest/BinaryTreeNodeTest.java
new file mode 100644
index 0000000000..724e6c0e03
--- /dev/null
+++ b/group01/1814014897/zhouhui/src/week01/BasicDataStructureTest/BinaryTreeNodeTest.java
@@ -0,0 +1,80 @@
+package week01.BasicDataStructureTest;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import week01.BasicDataStructure.BinaryTreeNode;
+
+
+public class BinaryTreeNodeTest {
+
+ private BinaryTreeNode root = new BinaryTreeNode(5);
+
+ @Before
+ public void setUp() throws Exception {
+ root.insert(2);
+ root.insert(7);
+ root.insert(1);
+ root.insert(6);
+ }
+
+ @Test
+ public void testGetData() {
+ Assert.assertEquals(root.getData(), 5);
+ Assert.assertEquals(root.getLeft().getData(), 2);
+ Assert.assertEquals(root.getRight().getData(), 7);
+ Assert.assertEquals(root.getLeft().getLeft().getData(), 1);
+ Assert.assertEquals(root.getRight().getLeft().getData(), 6);
+ }
+
+ @Test
+ public void testSetData() {
+ root.setData(8);
+ Assert.assertEquals(root.getData(),8);
+ root.getLeft().setData(88);
+ Assert.assertEquals(root.getLeft().getData(),88);
+ root.getRight().setData(888);
+ Assert.assertEquals(root.getRight().getData(),888);
+ }
+
+ @Test
+ public void testGetLeft() {
+ BinaryTreeNode node_left = root.getLeft();
+ Assert.assertEquals(node_left.getData(), 2);
+ BinaryTreeNode node_left_left = root.getLeft().getLeft();
+ Assert.assertEquals(node_left_left.getData(), 1);
+ }
+
+ @Test
+ public void testSetLeft() {
+ BinaryTreeNode node = new BinaryTreeNode(100);
+ root.setLeft(node);
+ Assert.assertEquals(root.getLeft().getData(), 100);
+ }
+
+ @Test
+ public void testGetRight() {
+ BinaryTreeNode node_right = root.getRight();
+ Assert.assertEquals(node_right.getData(), 7);
+ root.insert(8);
+ BinaryTreeNode node_right_right = root.getRight().getRight();
+ Assert.assertEquals(node_right_right.getData(), 8);
+ }
+
+ @Test
+ public void testSetRight() {
+ BinaryTreeNode node = new BinaryTreeNode(100);
+ root.setRight(node);
+ Assert.assertEquals(root.getRight().getData(), 100);
+ }
+
+ @Test
+ public void testInsert() {
+ root.insert(4);
+ root.insert(8);
+ Assert.assertEquals(root.getLeft().getRight().getData(), 4);
+ Assert.assertEquals(root.getRight().getRight().getData(), 8);
+ }
+
+}
diff --git a/group01/1814014897/zhouhui/src/week01/BasicDataStructureTest/LinkedListTest.java b/group01/1814014897/zhouhui/src/week01/BasicDataStructureTest/LinkedListTest.java
new file mode 100644
index 0000000000..2fb20d12f4
--- /dev/null
+++ b/group01/1814014897/zhouhui/src/week01/BasicDataStructureTest/LinkedListTest.java
@@ -0,0 +1,106 @@
+package week01.BasicDataStructureTest;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import week01.BasicDataStructure.Iterator;
+import week01.BasicDataStructure.LinkedList;
+
+public class LinkedListTest {
+
+ private LinkedList linkedList = new LinkedList();
+
+ @Before
+ public void setUp() throws Exception {
+ for(int i=0;i<100;i++){
+ linkedList.add(i);
+ }
+ }
+
+ @Test
+ public void testAddObject() {
+ for(int i=0;i<200;i++){
+ linkedList.add(i);
+ }
+ for(int i=0;i<100;i++){
+ Assert.assertEquals(linkedList.get(i), i);
+ }
+ for(int i=100;i<300;i++){
+ Assert.assertEquals(linkedList.get(i), i-100);
+ }
+ }
+
+ @Test
+ public void testAddIntObject() {
+ linkedList.add(0, 10);
+ Assert.assertEquals(linkedList.get(0), 10);
+ linkedList.add(5,60);
+ Assert.assertEquals(linkedList.get(5), 60);
+ Assert.assertEquals(linkedList.get(101), 99);
+ }
+
+ @Test
+ public void testGet() {
+ for(int i =0;i<100;i++){
+ Assert.assertEquals(linkedList.get(i), i);
+ }
+ }
+
+ @Test
+ public void testRemove() {
+ Assert.assertEquals(linkedList.remove(0), 0);
+ Assert.assertEquals(linkedList.remove(0), 1);
+ Assert.assertEquals(linkedList.size(), 98);
+ linkedList.remove(97);
+ Assert.assertEquals(linkedList.get(96), 98);
+ }
+
+ @Test
+ public void testSize() {
+ linkedList.add(0);
+ Assert.assertEquals(linkedList.size(), 101);
+ linkedList.add(0, 10);
+ Assert.assertEquals(linkedList.size(), 102);
+ linkedList.remove(0);
+ Assert.assertEquals(linkedList.size(), 101);
+ }
+
+ @Test
+ public void testAddFirst() {
+ linkedList.addFirst(22);
+ Assert.assertEquals(linkedList.get(0), 22);
+ linkedList.addFirst(44);
+ Assert.assertEquals(linkedList.get(0), 44);
+ Assert.assertEquals(linkedList.size(), 102);
+ }
+
+ @Test
+ public void testAddLast() {
+ linkedList.addLast(22);
+ Assert.assertEquals(linkedList.get(100), 22);
+ linkedList.addLast(44);
+ Assert.assertEquals(linkedList.get(101), 44);
+ }
+
+ @Test
+ public void testRemoveFirst() {
+ Assert.assertEquals(linkedList.removeFirst(), 0);
+ Assert.assertEquals(linkedList.removeFirst(), 1);
+ }
+
+ @Test
+ public void testRemoveLast() {
+ Assert.assertEquals(linkedList.removeLast(),99 );
+ Assert.assertEquals(linkedList.removeLast(), 98);
+ }
+
+ @Test
+ public void testIterator() {
+ Iterator iterator = linkedList.iterator();
+ for(int i = 0;iterator.hasNext();i++){
+ Assert.assertEquals(iterator.next(), i);
+ }
+ }
+
+}
diff --git a/group01/1814014897/zhouhui/src/week01/BasicDataStructureTest/QueueTest.java b/group01/1814014897/zhouhui/src/week01/BasicDataStructureTest/QueueTest.java
new file mode 100644
index 0000000000..7302b5ec38
--- /dev/null
+++ b/group01/1814014897/zhouhui/src/week01/BasicDataStructureTest/QueueTest.java
@@ -0,0 +1,56 @@
+package week01.BasicDataStructureTest;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import week01.BasicDataStructure.Queue;
+
+
+public class QueueTest {
+
+ Queue queue = new Queue();
+
+ @Before
+ public void setUp() throws Exception {
+ for(int i=0;i<100;i++){
+ queue.enQueue(i);
+ }
+ }
+
+ @Test
+ public void testEnQueue() {
+ Assert.assertEquals(queue.size(), 100);
+ for(int i =0;i<100;i++){
+ queue.enQueue(i);
+ }
+ Assert.assertEquals(queue.size(), 200);
+ }
+
+ @Test
+ public void testDeQueue() {
+ for(int i =0;i<100;i++){
+ Assert.assertEquals(queue.deQueue(), i);
+ }
+
+ }
+
+ @Test
+ public void testIsEmpty() {
+ Assert.assertEquals(queue.isEmpty(), false);
+ for(int i=0;i<100;i++){
+ queue.deQueue();
+ }
+ Assert.assertEquals(queue.isEmpty(), true);
+ }
+
+ @Test
+ public void testSize() {
+ Assert.assertEquals(queue.size(), 100);
+ queue.enQueue(100);
+ Assert.assertEquals(queue.size(), 101);
+ queue.deQueue();
+ Assert.assertEquals(queue.size(), 100);
+ }
+
+}
diff --git a/group01/1814014897/zhouhui/src/week01/BasicDataStructureTest/StackTest.java b/group01/1814014897/zhouhui/src/week01/BasicDataStructureTest/StackTest.java
new file mode 100644
index 0000000000..ae6d3a39d4
--- /dev/null
+++ b/group01/1814014897/zhouhui/src/week01/BasicDataStructureTest/StackTest.java
@@ -0,0 +1,71 @@
+package week01.BasicDataStructureTest;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import week01.BasicDataStructure.Stack;
+
+
+public class StackTest {
+
+ Stack stack = new Stack();
+
+ @Before
+ public void setUp() throws Exception {
+ for(int i =0 ;i <100;i++){
+ stack.push(i);
+ }
+ }
+
+ @Test
+ public void testPush() {
+ Assert.assertEquals(stack.peek(), 99);
+ for(int i =0;i <200;i++){
+ stack.push(i);
+ }
+ Assert.assertEquals(stack.peek(), 199);
+ Assert.assertEquals(stack.size(), 300);
+ }
+
+ @Test
+ public void testPop() {
+ Assert.assertEquals(stack.pop(), 99);
+ Assert.assertEquals(stack.pop(), 98);
+ for(int i=0;i<98;i++){
+ stack.pop();
+ }
+ Assert.assertEquals(stack.size(), 0);
+ }
+
+ @Test
+ public void testPeek() {
+ for(int i=0;i<100;i++){
+ Assert.assertEquals(stack.peek(), 99);
+ Assert.assertEquals(stack.size(), 100);
+ }
+ stack.pop();
+ Assert.assertEquals(stack.peek(), 98);
+ Assert.assertEquals(stack.peek(), 98);
+ }
+
+ @Test
+ public void testIsEmpty() {
+ Assert.assertEquals(stack.isEmpty(), false);
+ for(int i =0 ;i <100;i++){
+ stack.pop();
+ }
+ Assert.assertEquals(stack.isEmpty(), true);
+ }
+
+ @Test
+ public void testSize() {
+ stack.push(100);
+ Assert.assertEquals(stack.size(), 101);
+ stack.pop();
+ Assert.assertEquals(stack.size(), 100);
+ stack.peek();
+ Assert.assertEquals(stack.size(), 100);
+ }
+
+}
diff --git a/group01/1925347167/1925347167.md b/group01/1925347167/1925347167.md
new file mode 100644
index 0000000000..8b13789179
--- /dev/null
+++ b/group01/1925347167/1925347167.md
@@ -0,0 +1 @@
+
diff --git a/group01/1925347167/Week1 Basic Data Structure/ArrayList.java b/group01/1925347167/Week1 Basic Data Structure/ArrayList.java
new file mode 100644
index 0000000000..2797e0b129
--- /dev/null
+++ b/group01/1925347167/Week1 Basic Data Structure/ArrayList.java
@@ -0,0 +1,64 @@
+package com.coding.basic;
+
+import java.util.Arrays;
+
+public class ArrayList implements List {
+
+ private int size = 0;
+
+ private Object[] elementData = new Object[100];
+
+ public void add(Object o){
+ if (fullCheck())
+ elementData = Arrays.copyOf(elementData, size*2);
+ elementData[size++] = o;
+ }
+ public void add(int index, Object o){
+
+ if (fullCheck())
+ elementData = Arrays.copyOf(elementData, size*2);
+ if (!rangeCheck(index))
+ throw new IndexOutOfBoundsException();
+ for (int i = size; i > index; --i)
+ elementData[i] = elementData[i-1];
+ elementData[index] = o;
+ size++;
+ }
+
+ public Object get(int index){
+ if (rangeCheck(index))
+ return elementData[index];
+ throw new IndexOutOfBoundsException();
+ }
+
+ public Object remove(int index){
+ if (!rangeCheck(index))
+ throw new IndexOutOfBoundsException();
+ Object rmo = elementData[index];
+ for (int i = index; i < size-1; ++i)
+ elementData[i] = elementData[i-1];
+ size--;
+ return rmo;
+ }
+
+ public int size(){
+ return size;
+ }
+
+ public Iterator iterator(){
+ return null;
+ }
+
+ private boolean rangeCheck(int index) {
+ if (index < 0 || index >= size)
+ return false;
+ return true;
+ }
+
+ private boolean fullCheck() {
+ if (size >= elementData.length)
+ return true;
+ return false;
+ }
+
+}
diff --git a/group01/1925347167/Week1 Basic Data Structure/BinaryTreeNode.java b/group01/1925347167/Week1 Basic Data Structure/BinaryTreeNode.java
new file mode 100644
index 0000000000..45827be3a5
--- /dev/null
+++ b/group01/1925347167/Week1 Basic Data Structure/BinaryTreeNode.java
@@ -0,0 +1,38 @@
+package com.coding.basic;
+
+public class BinaryTreeNode {
+
+ private Object data;
+ private BinaryTreeNode left;
+ private BinaryTreeNode right;
+
+ public BinaryTreeNode(Object o) {
+ data = o;
+ left = null;
+ right = null;
+ }
+
+ 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/group16/542087872/src/com/coding/basic/Iterator.java b/group01/1925347167/Week1 Basic Data Structure/Iterator.java
similarity index 100%
rename from group16/542087872/src/com/coding/basic/Iterator.java
rename to group01/1925347167/Week1 Basic Data Structure/Iterator.java
diff --git a/group01/1925347167/Week1 Basic Data Structure/LinkedList.java b/group01/1925347167/Week1 Basic Data Structure/LinkedList.java
new file mode 100644
index 0000000000..3097f69edc
--- /dev/null
+++ b/group01/1925347167/Week1 Basic Data Structure/LinkedList.java
@@ -0,0 +1,127 @@
+package com.coding.basic;
+
+public class LinkedList implements List {
+
+ private Node head;
+
+ private int size = 0;
+
+ public void add(Object o){
+ Node tmp = head;
+ while (tmp.next != null)
+ tmp = tmp.next;
+
+ Node n = new Node(o);
+ tmp.next = n;
+ size++;
+ }
+ public void add(int index , Object o){
+ if (!rangeCheck(index))
+ throw new IndexOutOfBoundsException();
+
+ if (index == 0) {
+ Node newhead = new Node(o);
+ newhead.next = head;
+ head = newhead;
+ } else {
+ Node tmp = head;
+ for (int i = 0; i < index - 1; ++i)
+ tmp = tmp.next;
+ Node node = new Node(o);
+ node.next = tmp.next;
+ tmp.next = node;
+ }
+
+ size++;
+ }
+ public Object get(int index){
+ if (!rangeCheck(index))
+ throw new IndexOutOfBoundsException();
+ Node tmp = head;
+ for (int i = 0; i < index - 1; ++i)
+ tmp = tmp.next;
+ return tmp.data;
+
+ }
+
+ public Object remove(int index){
+ if (!rangeCheck(index))
+ throw new IndexOutOfBoundsException();
+
+ if (index == 0) {
+ Node oldHead= head;
+ head = head.next;
+ size--;
+ return oldHead.data;
+ }else {
+ Node tmp = head;
+ for (int i = 0; i < index - 1; i++) {
+ tmp = tmp.next;
+ }
+ Node node = tmp.next;
+ tmp.next = node.next;
+ size--;
+ return node.data;
+ }
+ }
+
+ public int size(){
+ return size;
+ }
+
+ public void addFirst(Object o){
+ Node newHead = new Node(o);
+ newHead.next = head;
+ head = newHead;
+ size++;
+ }
+ public void addLast(Object o){
+ Node tmp = head;
+ while (tmp.next != null) {
+ tmp = tmp.next;
+ }
+ Node node = new Node(o);
+ tmp.next = node;
+ size++;
+ }
+ public Object removeFirst(){
+ if (head == null)
+ throw new IndexOutOfBoundsException();
+ Node oldHead = head;
+ head = head.next;
+ size--;
+ return oldHead.data;
+ }
+ public Object removeLast(){
+ if (head == null)
+ throw new IndexOutOfBoundsException();
+ Node tmp = head;
+ while (tmp.next.next != null) {
+ tmp = tmp.next;
+ }
+ Node node = tmp.next;
+ tmp.next = null;
+ size--;
+ return node.data;
+ }
+ public Iterator iterator(){
+ return null;
+ }
+
+ private boolean rangeCheck(int index) {
+ if (index < 0 || index >= size)
+ return false;
+ return true;
+ }
+
+ private static class Node{
+ Object data;
+ Node next;
+
+ Node(Object data) {
+ this.data = data;
+ next = null;
+ }
+
+ }
+}
diff --git a/group16/542087872/src/com/coding/basic/List.java b/group01/1925347167/Week1 Basic Data Structure/List.java
similarity index 100%
rename from group16/542087872/src/com/coding/basic/List.java
rename to group01/1925347167/Week1 Basic Data Structure/List.java
diff --git a/group01/1925347167/Week1 Basic Data Structure/Queue.java b/group01/1925347167/Week1 Basic Data Structure/Queue.java
new file mode 100644
index 0000000000..b8c394b833
--- /dev/null
+++ b/group01/1925347167/Week1 Basic Data Structure/Queue.java
@@ -0,0 +1,24 @@
+package com.coding.basic;
+
+public class Queue {
+
+ private LinkedList llist = new LinkedList();
+
+ public void enQueue(Object o){
+ llist.add(o);
+ }
+
+ public Object deQueue(){
+ if (isEmpty())
+ return null;
+ return llist.removeFirst();
+ }
+
+ public boolean isEmpty(){
+ return (llist.size()==0);
+ }
+
+ public int size(){
+ return -llist.size();
+ }
+}
diff --git a/group01/1925347167/Week1 Basic Data Structure/Stack.java b/group01/1925347167/Week1 Basic Data Structure/Stack.java
new file mode 100644
index 0000000000..4458cb61d7
--- /dev/null
+++ b/group01/1925347167/Week1 Basic Data Structure/Stack.java
@@ -0,0 +1,28 @@
+package com.coding.basic;
+
+public class Stack {
+
+ private ArrayList elementData = new ArrayList();
+
+ public void push(Object o){
+ elementData.add(o);
+ }
+
+ public Object pop(){
+ if (isEmpty())
+ return null;
+ return elementData.remove(elementData.size() - 1);
+ }
+
+ public Object peek(){
+ if (elementData.size() == 0)
+ return null;
+ return elementData.get(elementData.size() - 1);
+ }
+ public boolean isEmpty(){
+ return (elementData.size() == 0);
+ }
+ public int size(){
+ return elementData.size();
+ }
+}
diff --git a/group01/1925347167/Week1 Basic Data Structure/readme.md b/group01/1925347167/Week1 Basic Data Structure/readme.md
new file mode 100644
index 0000000000..8b13789179
--- /dev/null
+++ b/group01/1925347167/Week1 Basic Data Structure/readme.md
@@ -0,0 +1 @@
+
diff --git a/group01/2137642225/work01/.classpath b/group01/2137642225/work01/.classpath
new file mode 100644
index 0000000000..2d7497573f
--- /dev/null
+++ b/group01/2137642225/work01/.classpath
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/group01/2137642225/work01/.gitignore b/group01/2137642225/work01/.gitignore
new file mode 100644
index 0000000000..ae3c172604
--- /dev/null
+++ b/group01/2137642225/work01/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/group01/2137642225/work01/.project b/group01/2137642225/work01/.project
new file mode 100644
index 0000000000..f8dde642e5
--- /dev/null
+++ b/group01/2137642225/work01/.project
@@ -0,0 +1,17 @@
+
+
+ work01
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group01/2137642225/work01/src/com/coding/mybasic/ArrayList.java b/group01/2137642225/work01/src/com/coding/mybasic/ArrayList.java
new file mode 100644
index 0000000000..1826ee7c50
--- /dev/null
+++ b/group01/2137642225/work01/src/com/coding/mybasic/ArrayList.java
@@ -0,0 +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];
+ }
+ }
+
+}
diff --git a/group01/2137642225/work01/src/com/coding/mybasic/BinaryTreeNode.java b/group01/2137642225/work01/src/com/coding/mybasic/BinaryTreeNode.java
new file mode 100644
index 0000000000..21bd8f696f
--- /dev/null
+++ b/group01/2137642225/work01/src/com/coding/mybasic/BinaryTreeNode.java
@@ -0,0 +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;
+ }
+
+}
diff --git a/group01/2137642225/work01/src/com/coding/mybasic/Iterator.java b/group01/2137642225/work01/src/com/coding/mybasic/Iterator.java
new file mode 100644
index 0000000000..622cc5b902
--- /dev/null
+++ b/group01/2137642225/work01/src/com/coding/mybasic/Iterator.java
@@ -0,0 +1,7 @@
+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
new file mode 100644
index 0000000000..ab37360e78
--- /dev/null
+++ b/group01/2137642225/work01/src/com/coding/mybasic/LinkedList.java
@@ -0,0 +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;
+ }
+
+
+ @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
new file mode 100644
index 0000000000..87a58a6c4c
--- /dev/null
+++ b/group01/2137642225/work01/src/com/coding/mybasic/List.java
@@ -0,0 +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();
+}
diff --git a/group01/2137642225/work01/src/com/coding/mybasic/Queue.java b/group01/2137642225/work01/src/com/coding/mybasic/Queue.java
new file mode 100644
index 0000000000..36d10fd668
--- /dev/null
+++ b/group01/2137642225/work01/src/com/coding/mybasic/Queue.java
@@ -0,0 +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() + " 空队列");
+ }
+ }
+}
diff --git a/group01/2137642225/work01/src/com/coding/mybasic/Stack.java b/group01/2137642225/work01/src/com/coding/mybasic/Stack.java
new file mode 100644
index 0000000000..f50e686317
--- /dev/null
+++ b/group01/2137642225/work01/src/com/coding/mybasic/Stack.java
@@ -0,0 +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() + " 空栈");
+ }
+ }
+}
diff --git a/group01/2137642225/work01/src/com/coding/test/TestArrayList.java b/group01/2137642225/work01/src/com/coding/test/TestArrayList.java
new file mode 100644
index 0000000000..8bd8952195
--- /dev/null
+++ b/group01/2137642225/work01/src/com/coding/test/TestArrayList.java
@@ -0,0 +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(){
+
+ }
+}
diff --git a/group01/2137642225/work01/src/com/coding/test/TestBinaryTreeNode.java b/group01/2137642225/work01/src/com/coding/test/TestBinaryTreeNode.java
new file mode 100644
index 0000000000..662bb55570
--- /dev/null
+++ b/group01/2137642225/work01/src/com/coding/test/TestBinaryTreeNode.java
@@ -0,0 +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());
+ }
+
+}
diff --git a/group01/2137642225/work01/src/com/coding/test/TestLinkedList.java b/group01/2137642225/work01/src/com/coding/test/TestLinkedList.java
new file mode 100644
index 0000000000..57a8b13bb8
--- /dev/null
+++ b/group01/2137642225/work01/src/com/coding/test/TestLinkedList.java
@@ -0,0 +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();
+ }
+}
diff --git a/group01/2137642225/work01/src/com/coding/test/TestQueue.java b/group01/2137642225/work01/src/com/coding/test/TestQueue.java
new file mode 100644
index 0000000000..367a44d151
--- /dev/null
+++ b/group01/2137642225/work01/src/com/coding/test/TestQueue.java
@@ -0,0 +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());
+ }
+
+}
diff --git a/group01/2137642225/work01/src/com/coding/test/TestStack.java b/group01/2137642225/work01/src/com/coding/test/TestStack.java
new file mode 100644
index 0000000000..0e278f2992
--- /dev/null
+++ b/group01/2137642225/work01/src/com/coding/test/TestStack.java
@@ -0,0 +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());
+ }
+
+}
diff --git a/group01/275150374/275150374Learning/.idea/compiler.xml b/group01/275150374/275150374Learning/.idea/compiler.xml
new file mode 100644
index 0000000000..217af471a9
--- /dev/null
+++ b/group01/275150374/275150374Learning/.idea/compiler.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/group01/275150374/275150374Learning/.idea/description.html b/group01/275150374/275150374Learning/.idea/description.html
new file mode 100644
index 0000000000..db5f129556
--- /dev/null
+++ b/group01/275150374/275150374Learning/.idea/description.html
@@ -0,0 +1 @@
+Simple Java application that includes a class with main()
method
\ No newline at end of file
diff --git a/group01/275150374/275150374Learning/.idea/encodings.xml b/group01/275150374/275150374Learning/.idea/encodings.xml
new file mode 100644
index 0000000000..e206d70d85
--- /dev/null
+++ b/group01/275150374/275150374Learning/.idea/encodings.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/group01/275150374/275150374Learning/.idea/misc.xml b/group01/275150374/275150374Learning/.idea/misc.xml
new file mode 100644
index 0000000000..de8f7c75a3
--- /dev/null
+++ b/group01/275150374/275150374Learning/.idea/misc.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/group01/275150374/275150374Learning/.idea/modules.xml b/group01/275150374/275150374Learning/.idea/modules.xml
new file mode 100644
index 0000000000..5534fceb30
--- /dev/null
+++ b/group01/275150374/275150374Learning/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/group01/275150374/275150374Learning/.idea/vcs.xml b/group01/275150374/275150374Learning/.idea/vcs.xml
new file mode 100644
index 0000000000..c2365ab11f
--- /dev/null
+++ b/group01/275150374/275150374Learning/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/group01/275150374/275150374Learning/275150374Learning.iml b/group01/275150374/275150374Learning/275150374Learning.iml
new file mode 100644
index 0000000000..d5c0743275
--- /dev/null
+++ b/group01/275150374/275150374Learning/275150374Learning.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/group01/275150374/275150374Learning/src/task01/ArrayList.java b/group01/275150374/275150374Learning/src/task01/ArrayList.java
new file mode 100644
index 0000000000..8d604f109e
--- /dev/null
+++ b/group01/275150374/275150374Learning/src/task01/ArrayList.java
@@ -0,0 +1,86 @@
+package task01;
+
+import java.util.Arrays;
+
+/**第一周作业
+ * 自己实现一个 ArrayList
+ * Created by eurry on 2017/2/26.
+ */
+public class ArrayList {
+ /**
+ * ArrayList的长度
+ */
+ private int size = 0;
+
+ private Object[] elementData = {};
+
+ public void add(Object o){
+ elementData = Arrays.copyOf(elementData, size+1);
+ elementData[size] = o;
+ size++;
+ }
+
+ public void add(int index, Object o){
+ if(index < size){
+ elementData = Arrays.copyOf(elementData, size+1);
+ System.arraycopy(elementData, index, elementData, index+1, size-index);
+ elementData[index] = o;
+ size++;
+ }else{
+ elementData = Arrays.copyOf(elementData, index+1);
+ elementData[index] = o;
+ size = index+1;
+ }
+ }
+
+ public Object get(int index){
+ if(index < size){
+ return elementData[index];
+ }else{
+ throw new IndexOutOfBoundsException("导致对数组范围以外的数据的访问");
+ }
+ }
+
+ public Object remove(int index){
+ if(index < size){
+ Object re = elementData[index];
+ System.arraycopy(elementData, index+1, elementData, index, size-index-1);
+ elementData = Arrays.copyOf(elementData, size-1);
+ size--;
+ return re;
+ }else{
+ throw new IndexOutOfBoundsException("导致对数组范围以外的数据的访问");
+ }
+ }
+
+ public int size(){
+ return size;
+ }
+
+ public String toString(){
+ String str = null;
+ if(elementData.length > 0){
+ str = "";
+ for (Object anElementData : elementData) {
+ str += anElementData.toString() + ",";
+ }
+ str = str.substring(0, str.length()-1);
+ }
+ return str;
+ }
+
+ /**
+ * 测试
+ */
+ public static void main(String[] str){
+ ArrayList list = new ArrayList();
+ list.add("A");
+ list.add("B");
+ list.add(1, "C");
+ list.add("D");
+ Object d = list.get(3);
+ Object dd = list.remove(3);
+ System.out.println(list.size());
+ System.out.println(list.toString());
+ }
+}
diff --git a/group01/275150374/275150374Learning/src/task01/LinkedList.java b/group01/275150374/275150374Learning/src/task01/LinkedList.java
new file mode 100644
index 0000000000..23eb1adaae
--- /dev/null
+++ b/group01/275150374/275150374Learning/src/task01/LinkedList.java
@@ -0,0 +1,162 @@
+package task01;
+
+import java.util.Arrays;
+
+/**第一周作业
+ * 自己实现一个 LinkedList
+ * Created by eurry on 2017/2/26.
+ */
+public class LinkedList {
+
+ private int size = 0;
+ private Node head=null;
+
+ public void add(Object o){
+ if(size == 0){
+ head = new Node(o);
+ }else{
+ Node next = head;
+ while(next.next != null){
+ next = next.next;
+ }
+ next.next = new Node(o);
+ }
+ size++;
+ }
+
+ public void add(int index, Object o){
+ if(index <= size){
+ if(size == 0){
+ add(o);
+ }else{
+ if(index==0){
+ addFirst(o);
+ }else if(index==size){
+ add(o);
+ }else{
+ Node next = head;
+ for(int i=0; i 0){
+ Node ele = null;
+ Node next = head;
+ for(int i=0; i
+
+
+ root
+ com.coding2017
+ 1.0-SNAPSHOT
+
+ 4.0.0
+
+ basic
+
+
+
+
+ junit
+ junit
+
+
+ junit
+ junit-dep
+
+
+
+
+
\ No newline at end of file
diff --git a/group01/280646174/basic/src/main/java/com/coding2017/basic/ArrayList.java b/group01/280646174/basic/src/main/java/com/coding2017/basic/ArrayList.java
new file mode 100644
index 0000000000..a4199bdbdb
--- /dev/null
+++ b/group01/280646174/basic/src/main/java/com/coding2017/basic/ArrayList.java
@@ -0,0 +1,100 @@
+package com.coding2017.basic;
+
+import java.util.Arrays;
+
+public class ArrayList implements List {
+
+ private int size = 0;
+
+ private Object[] elementData = new Object[4];
+
+ public void add(Object o) {
+ if (noSpace()) {
+ extendSpace();
+ }
+
+ elementData[size++] = o;
+ }
+
+ private void extendSpace() {
+ elementData = Arrays.copyOf(elementData, elementData.length * 2);
+ }
+
+ private boolean noSpace() {
+ return size == elementData.length;
+ }
+
+ public void add(int index, Object o) {
+ if (index < 0 || index > size) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (noSpace()) {
+ extendSpace();
+ }
+
+ if (index == size) {
+ add(o);
+ return;
+ }
+
+ System.arraycopy(elementData, index, elementData, index + 1, size - index);
+ elementData[index] = o;
+ size++;
+ }
+
+ public Object get(int index) {
+ if (index < 0 || index >= size) {
+ throw new IndexOutOfBoundsException();
+ }
+ return elementData[index];
+ }
+
+ public Object remove(int index) {
+ if (index < 0 || index >= size) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (index == size - 1) {
+ return elementData[--size];
+ }
+
+ Object removed = elementData[index];
+ System.arraycopy(elementData, index + 1, elementData, index, size - index - 1);
+ size--;
+ return removed;
+ }
+
+ public int size() {
+ return size;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder("[");
+ if (size > 0) {
+ builder.append(get(0));
+ }
+ for (int i = 1; i < size; i++) {
+ builder.append(", ").append(get(i));
+ }
+ builder.append("]");
+ return builder.toString();
+ }
+
+ public Iterator iterator() {
+ return new ArrayListIterator();
+ }
+
+ private class ArrayListIterator implements Iterator {
+ private int pos;
+
+ @Override
+ public boolean hasNext() {
+ return pos < size();
+ }
+
+ @Override
+ public Object next() {
+ return ArrayList.this.get(pos++);
+ }
+ }
+}
diff --git a/group01/280646174/basic/src/main/java/com/coding2017/basic/BinaryTreeNode.java b/group01/280646174/basic/src/main/java/com/coding2017/basic/BinaryTreeNode.java
new file mode 100644
index 0000000000..acf4798b9e
--- /dev/null
+++ b/group01/280646174/basic/src/main/java/com/coding2017/basic/BinaryTreeNode.java
@@ -0,0 +1,57 @@
+package com.coding2017.basic;
+
+public class BinaryTreeNode {
+
+ private Integer data;
+ private BinaryTreeNode left;
+ private BinaryTreeNode right;
+
+ public BinaryTreeNode insert(Integer o) {
+ if (o <= data) {
+ if (left == null) {
+ left = new BinaryTreeNode(o);
+ return left;
+ }
+ return left.insert(o);
+ } else {
+ if (right == null) {
+ right = new BinaryTreeNode(o);
+ return right;
+ }
+ return right.insert(o);
+ }
+ }
+
+ public BinaryTreeNode(Integer data) {
+ this.data = data;
+ }
+
+ public Integer 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;
+ }
+
+ @Override
+ public String toString() {
+ return data + " " + left + " " + right;
+ }
+}
diff --git a/group01/280646174/basic/src/main/java/com/coding2017/basic/Iterator.java b/group01/280646174/basic/src/main/java/com/coding2017/basic/Iterator.java
new file mode 100644
index 0000000000..19e214cfbb
--- /dev/null
+++ b/group01/280646174/basic/src/main/java/com/coding2017/basic/Iterator.java
@@ -0,0 +1,7 @@
+package com.coding2017.basic;
+
+public interface Iterator {
+ public boolean hasNext();
+ public Object next();
+
+}
diff --git a/group01/280646174/basic/src/main/java/com/coding2017/basic/LinkedList.java b/group01/280646174/basic/src/main/java/com/coding2017/basic/LinkedList.java
new file mode 100644
index 0000000000..5aeeb7c7f8
--- /dev/null
+++ b/group01/280646174/basic/src/main/java/com/coding2017/basic/LinkedList.java
@@ -0,0 +1,179 @@
+package com.coding2017.basic;
+
+public class LinkedList implements List {
+
+ private Node head;
+
+ private Node tail;
+
+ private int size;
+
+ public void add(Object o) {
+ addLast(o);
+ }
+
+ public void add(int index, Object o) {
+ if (index < 0 || index > size) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (index == size) {
+ addLast(o);
+ } else if (index == 0) {
+ addFirst(o);
+ } else {
+ Node node = new Node(o);
+ Node prevNode = getNode(index - 1);
+ Node nextNode = prevNode.next;
+ prevNode.next = node;
+ node.prev = prevNode;
+ nextNode.prev = node;
+ node.next = nextNode;
+ size++;
+ }
+ }
+
+ private Node getNode(int index) {
+ if (index < 0 || index >= size) {
+ throw new IndexOutOfBoundsException();
+ }
+ Node node = head;
+ for (int j = 0; j < index; j++) {
+ node = node.next;
+ }
+ return node;
+ }
+
+ public Object get(int index) {
+ if (index < 0 || index >= size) {
+ throw new IndexOutOfBoundsException();
+ }
+ return getNode(index).data;
+ }
+
+ public Object remove(int index) {
+ if (index < 0 || index >= size) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (index == 0) {
+ return removeFirst();
+ } else if (index == size - 1) {
+ return removeLast();
+ } else {
+ Node node = getNode(index);
+ node.prev.next = node.next;
+ node.next.prev = node.prev;
+ size--;
+ return node.data;
+ }
+ }
+
+ public int size() {
+ return size;
+ }
+
+ public void addFirst(Object o) {
+ Node node = new Node(o);
+ if (size == 0) {
+ head = node;
+ tail = node;
+ } else {
+ head.prev = node;
+ node.next = head;
+ head = node;
+ }
+ size++;
+ }
+
+ public void addLast(Object o) {
+ if (size == 0) {
+ addFirst(o);
+ } else {
+ Node node = new Node(o);
+ tail.next = node;
+ node.prev = tail;
+ tail = node;
+ size++;
+ }
+ }
+
+ public Object removeFirst() {
+ if (size == 0) {
+ throw new IndexOutOfBoundsException();
+ }
+ Node node = head;
+ if (size == 1) {
+ head = null;
+ tail = null;
+ size--;
+ } else {
+ head.next.prev = null;
+ head = head.next;
+ size--;
+ }
+ return node.data;
+ }
+
+ public Object removeLast() {
+ if (size == 0) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (size == 1) {
+ return removeFirst();
+ }
+ Node node = tail;
+ tail.prev.next = null;
+ tail = tail.prev;
+ size--;
+ return node.data;
+ }
+
+ public Iterator iterator() {
+ return new LinkedListIterator();
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder("[");
+ if (size > 0) {
+ builder.append(get(0));
+ }
+ for(Node node = head.next; node != null; node = node.next) {
+ builder.append(", ").append(node.data);
+ }
+ builder.append("]");
+ return builder.toString();
+ }
+
+ private static class Node {
+ private Object data;
+ private Node next;
+ private Node prev;
+
+ public Node() {}
+
+ private Node(Object data) {
+ this.data = data;
+ }
+ }
+
+ private class LinkedListIterator implements Iterator {
+ private Node node;
+
+ public LinkedListIterator() {
+ this.node = LinkedList.this.head;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return node != null;
+ }
+
+ @Override
+ public Object next() {
+ Node temp = node;
+ node = node.next;
+ return temp.data;
+ }
+ }
+}
diff --git a/group16/214074094/src/com/coding/basic/List.java b/group01/280646174/basic/src/main/java/com/coding2017/basic/List.java
similarity index 84%
rename from group16/214074094/src/com/coding/basic/List.java
rename to group01/280646174/basic/src/main/java/com/coding2017/basic/List.java
index 5da9b0d4c6..0fee4d7a42 100644
--- a/group16/214074094/src/com/coding/basic/List.java
+++ b/group01/280646174/basic/src/main/java/com/coding2017/basic/List.java
@@ -1,7 +1,6 @@
-package coding.basic;
+package com.coding2017.basic;
public interface List {
-
void add(Object o);
void add(int index, Object o);
@@ -11,5 +10,4 @@ public interface List {
Object remove(int index);
int size();
-
}
diff --git a/group01/280646174/basic/src/main/java/com/coding2017/basic/Queue.java b/group01/280646174/basic/src/main/java/com/coding2017/basic/Queue.java
new file mode 100644
index 0000000000..f611b874e0
--- /dev/null
+++ b/group01/280646174/basic/src/main/java/com/coding2017/basic/Queue.java
@@ -0,0 +1,22 @@
+package com.coding2017.basic;
+
+public class Queue {
+
+ LinkedList list = new LinkedList();
+
+ public void enQueue(Object o) {
+ list.addLast(o);
+ }
+
+ public Object deQueue() {
+ return list.removeFirst();
+ }
+
+ public boolean isEmpty() {
+ return list.size() == 0;
+ }
+
+ public int size() {
+ return list.size();
+ }
+}
diff --git a/group01/280646174/basic/src/main/java/com/coding2017/basic/Stack.java b/group01/280646174/basic/src/main/java/com/coding2017/basic/Stack.java
new file mode 100644
index 0000000000..3ec7b5788b
--- /dev/null
+++ b/group01/280646174/basic/src/main/java/com/coding2017/basic/Stack.java
@@ -0,0 +1,25 @@
+package com.coding2017.basic;
+
+public class Stack {
+ private ArrayList elementData = new ArrayList();
+
+ public void push(Object o) {
+ elementData.add(o);
+ }
+
+ public Object pop() {
+ return elementData.remove(elementData.size() - 1);
+ }
+
+ public Object peek() {
+ return elementData.get(elementData.size() - 1);
+ }
+
+ public boolean isEmpty() {
+ return elementData.size() == 0;
+ }
+
+ public int size() {
+ return elementData.size();
+ }
+}
diff --git a/group01/280646174/basic/src/test/java/com/coding2017/basic/ArrayListTest.java b/group01/280646174/basic/src/test/java/com/coding2017/basic/ArrayListTest.java
new file mode 100644
index 0000000000..21e9d59694
--- /dev/null
+++ b/group01/280646174/basic/src/test/java/com/coding2017/basic/ArrayListTest.java
@@ -0,0 +1,79 @@
+package com.coding2017.basic;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Created by kaitao.li on 17/2/21.
+ */
+public class ArrayListTest {
+ @Test
+ public void testAdd() throws Exception {
+ ArrayList arrayList = new ArrayList();
+ arrayList.add("0");
+ Assert.assertTrue(arrayList.get(0).equals("0"));
+ }
+
+ @Test
+ public void testAddWithIndex() throws Exception {
+ ArrayList arrayList = new ArrayList();
+ arrayList.add("0");
+ arrayList.add("1");
+ arrayList.add(1, "2");
+ Assert.assertTrue(arrayList.get(1).equals("2"));
+ Assert.assertTrue(arrayList.get(2).equals("1"));
+ Assert.assertTrue(arrayList.size() == 3);
+ }
+
+ @Test
+ public void get() throws Exception {
+ ArrayList arrayList = new ArrayList();
+ arrayList.add("0");
+ arrayList.add("1");
+ Assert.assertTrue(arrayList.get(1).equals("1"));
+ }
+
+ @Test
+ public void remove() throws Exception {
+ ArrayList arrayList = new ArrayList();
+ arrayList.add("0");
+ arrayList.add("1");
+ arrayList.add("2");
+ Object remove = arrayList.remove(1);
+ Assert.assertTrue(remove.equals("1"));
+ Assert.assertTrue(arrayList.size() == 2);
+ }
+
+ @Test
+ public void size() throws Exception {
+ ArrayList arrayList = new ArrayList();
+ arrayList.add("0");
+ arrayList.add("1");
+ Assert.assertEquals(arrayList.size(), 2);
+ }
+
+ @Test
+ public void testExtend() {
+ ArrayList arrayList = new ArrayList();
+ arrayList.add("0");
+ arrayList.add("1");
+ arrayList.add("2");
+ arrayList.add("3");
+ arrayList.add("4");
+ Assert.assertTrue(arrayList.get(4).equals("4"));
+ }
+
+ @Test
+ public void iterator() throws Exception {
+ ArrayList arrayList = new ArrayList();
+ arrayList.add("0");
+ arrayList.add("1");
+ Iterator iterator = arrayList.iterator();
+ Assert.assertTrue(iterator.hasNext());
+ Assert.assertTrue(iterator.next().equals("0"));
+ Assert.assertTrue(iterator.hasNext());
+ Assert.assertTrue(iterator.next().equals("1"));
+ Assert.assertTrue(!iterator.hasNext());
+ }
+
+}
\ No newline at end of file
diff --git a/group01/280646174/basic/src/test/java/com/coding2017/basic/BinaryTreeNodeTest.java b/group01/280646174/basic/src/test/java/com/coding2017/basic/BinaryTreeNodeTest.java
new file mode 100644
index 0000000000..3a9877c596
--- /dev/null
+++ b/group01/280646174/basic/src/test/java/com/coding2017/basic/BinaryTreeNodeTest.java
@@ -0,0 +1,24 @@
+package com.coding2017.basic;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by kaitao.li on 17/2/24.
+ */
+public class BinaryTreeNodeTest {
+
+ @Test
+ public void insert() throws Exception {
+ BinaryTreeNode binaryTreeNode = new BinaryTreeNode(5);
+ binaryTreeNode.insert(4);
+ binaryTreeNode.insert(6);
+ binaryTreeNode.insert(5);
+ assertTrue(binaryTreeNode.getLeft().getData() == 4);
+ assertTrue(binaryTreeNode.getRight().getData() == 6);
+ assertTrue(binaryTreeNode.getLeft().getRight().getData() == 5);
+ System.out.println(binaryTreeNode);
+ }
+
+}
\ No newline at end of file
diff --git a/group01/280646174/basic/src/test/java/com/coding2017/basic/LinkedListTest.java b/group01/280646174/basic/src/test/java/com/coding2017/basic/LinkedListTest.java
new file mode 100644
index 0000000000..f6855d3583
--- /dev/null
+++ b/group01/280646174/basic/src/test/java/com/coding2017/basic/LinkedListTest.java
@@ -0,0 +1,83 @@
+package com.coding2017.basic;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by kaitao.li on 17/2/21.
+ */
+public class LinkedListTest {
+ @Test
+ public void testAdd() throws Exception {
+ LinkedList list = new LinkedList();
+ list.add("0");
+ Assert.assertTrue(list.get(0).equals("0"));
+ }
+
+ @Test
+ public void testAddWithIndex() throws Exception {
+ LinkedList list = new LinkedList();
+ list.add("0");
+ list.add("1");
+ list.add(1, "2");
+ Assert.assertTrue(list.get(1).equals("2"));
+ Assert.assertTrue(list.get(2).equals("1"));
+ Assert.assertTrue(list.size() == 3);
+ }
+
+ @Test
+ public void get() throws Exception {
+ LinkedList list = new LinkedList();
+ list.add("0");
+ list.add("1");
+ Assert.assertTrue(list.get(1).equals("1"));
+ }
+
+ @Test
+ public void remove() throws Exception {
+ LinkedList list = new LinkedList();
+ list.add("0");
+ list.add("1");
+ list.add("2");
+ Object remove = list.remove(1);
+ Assert.assertTrue(remove.equals("1"));
+ Assert.assertTrue(list.size() == 2);
+ }
+
+ @Test
+ public void size() throws Exception {
+ LinkedList list = new LinkedList();
+ list.add("0");
+ list.add("1");
+ Assert.assertEquals(list.size(), 2);
+ }
+
+ @Test
+ public void testAddFirst() {
+ LinkedList list = new LinkedList();
+ list.addFirst("0");
+ Assert.assertTrue(list.get(0).equals("0"));
+ list.addFirst("1");
+ Assert.assertTrue(list.get(0).equals("1"));
+ list.removeFirst();
+ Assert.assertTrue(list.get(0).equals("0"));
+ list.removeLast();
+ Assert.assertTrue(list.size() == 0);
+ }
+
+ @Test
+ public void iterator() throws Exception {
+ ArrayList arrayList = new ArrayList();
+ arrayList.add("0");
+ arrayList.add("1");
+ Iterator iterator = arrayList.iterator();
+ Assert.assertTrue(iterator.hasNext());
+ Assert.assertTrue(iterator.next().equals("0"));
+ Assert.assertTrue(iterator.hasNext());
+ Assert.assertTrue(iterator.next().equals("1"));
+ Assert.assertTrue(!iterator.hasNext());
+ }
+
+}
\ No newline at end of file
diff --git a/group01/280646174/basic/src/test/java/com/coding2017/basic/QueueTest.java b/group01/280646174/basic/src/test/java/com/coding2017/basic/QueueTest.java
new file mode 100644
index 0000000000..5fde883433
--- /dev/null
+++ b/group01/280646174/basic/src/test/java/com/coding2017/basic/QueueTest.java
@@ -0,0 +1,23 @@
+package com.coding2017.basic;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by kaitao.li on 17/2/21.
+ */
+public class QueueTest {
+ @Test
+ public void enQueue() throws Exception {
+ Queue queue = new Queue();
+ queue.enQueue(1);
+ queue.enQueue(2);
+ Assert.assertTrue(queue.size() == 2);
+ Assert.assertTrue(queue.deQueue().equals(1));
+ Assert.assertTrue(queue.deQueue().equals(2));
+ Assert.assertTrue(queue.isEmpty());
+ }
+
+}
\ No newline at end of file
diff --git a/group01/280646174/basic/src/test/java/com/coding2017/basic/StackTest.java b/group01/280646174/basic/src/test/java/com/coding2017/basic/StackTest.java
new file mode 100644
index 0000000000..145d22d371
--- /dev/null
+++ b/group01/280646174/basic/src/test/java/com/coding2017/basic/StackTest.java
@@ -0,0 +1,24 @@
+package com.coding2017.basic;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by kaitao.li on 17/2/21.
+ */
+public class StackTest {
+ @Test
+ public void push() throws Exception {
+ Stack stack = new Stack();
+ stack.push(1);
+ stack.push(2);
+ Assert.assertTrue(stack.size() == 2);
+ Assert.assertTrue(stack.peek().equals(2));
+ Assert.assertTrue(stack.pop().equals(2));
+ Assert.assertTrue(stack.pop().equals(1));
+ Assert.assertTrue(stack.isEmpty());
+ }
+
+}
\ No newline at end of file
diff --git a/group01/280646174/pom.xml b/group01/280646174/pom.xml
new file mode 100644
index 0000000000..c99644072b
--- /dev/null
+++ b/group01/280646174/pom.xml
@@ -0,0 +1,38 @@
+
+
+ 4.0.0
+
+ com.coding2017
+ root
+ pom
+ 1.0-SNAPSHOT
+
+ basic
+
+
+
+ 4.12
+ 4.11
+
+
+
+
+
+
+ junit
+ junit
+ ${junit.junit.version}
+ test
+
+
+ junit
+ junit-dep
+ ${junit.junit-dep.version}
+ test
+
+
+
+
+
\ No newline at end of file
diff --git a/group01/349209948/.gitignore b/group01/349209948/.gitignore
new file mode 100644
index 0000000000..b3d8633e2b
--- /dev/null
+++ b/group01/349209948/.gitignore
@@ -0,0 +1,3 @@
+/bin/
+*.project
+*.classpath
\ No newline at end of file
diff --git a/group01/349209948/src/week1_0226/ArrayList.java b/group01/349209948/src/week1_0226/ArrayList.java
new file mode 100644
index 0000000000..57d25187f8
--- /dev/null
+++ b/group01/349209948/src/week1_0226/ArrayList.java
@@ -0,0 +1,68 @@
+package week1_0226;
+import java.util.Arrays;
+public class ArrayList implements List {
+
+ private int size = 0;
+
+ private Object[] elementData = new Object[100];
+
+ public void add(Object o){
+ ensureCapacity(size + 1);
+ elementData[size++] = o;
+ }
+ private void ensureCapacity(int size){
+ if (size > elementData.length){
+ grow();
+ }
+ }
+ private void grow(){
+ elementData = Arrays.copyOf(elementData, size * 2);
+ }
+ public void add(int index, Object o){
+ rangeCheckForAdd(index);
+ ensureCapacity(size + 1);
+ System.arraycopy(elementData,index, elementData, index + 1, size - index);
+ elementData[index] = o;
+ size ++;
+ }
+ private void rangeCheckForAdd(int index){
+ //index = size时不需要报错?
+ if (index > size || index < 0){
+ throw new IndexOutOfBoundsException();
+ }
+ }
+ public Object get(int index){
+ rangeCheck(index);
+ return elementData[index];
+ }
+ private void rangeCheck(int index){
+ if (index >= size || index < 0){
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+ public Object remove(int index){
+ rangeCheck(index);
+ Object dest = elementData[index];
+ System.arraycopy(elementData, index +1, elementData, index, size-index-1);
+ size --;
+ return dest;
+ }
+
+ public int size(){
+ return size;
+ }
+
+ public Iterator iterator(){
+ return new Iterator(){
+ private int index = 0;
+ public Object next(){
+ return elementData[index++];
+ }
+ public boolean hasNext(){
+ return index >= size;
+ }
+ };
+ }
+
+}
diff --git a/group01/349209948/src/week1_0226/BinaryTreeNode.java b/group01/349209948/src/week1_0226/BinaryTreeNode.java
new file mode 100644
index 0000000000..e667bdf15a
--- /dev/null
+++ b/group01/349209948/src/week1_0226/BinaryTreeNode.java
@@ -0,0 +1,37 @@
+package week1_0226;
+
+public class BinaryTreeNode {
+
+ private Object data;
+ private BinaryTreeNode left;
+ private BinaryTreeNode right;
+
+ public BinaryTreeNode(Object o){
+ this.data = o;
+ }
+ 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){
+ BinaryTreeNode node = new BinaryTreeNode(o);
+ this.setRight(node);
+ return node;
+ }
+
+}
diff --git a/group01/349209948/src/week1_0226/Iterator.java b/group01/349209948/src/week1_0226/Iterator.java
new file mode 100644
index 0000000000..3eddc2b726
--- /dev/null
+++ b/group01/349209948/src/week1_0226/Iterator.java
@@ -0,0 +1,6 @@
+package week1_0226;
+
+public interface Iterator {
+ public boolean hasNext();
+ public Object next();
+}
diff --git a/group01/349209948/src/week1_0226/LinkedList.java b/group01/349209948/src/week1_0226/LinkedList.java
new file mode 100644
index 0000000000..51c9ab8844
--- /dev/null
+++ b/group01/349209948/src/week1_0226/LinkedList.java
@@ -0,0 +1,129 @@
+package week1_0226;
+
+import java.util.NoSuchElementException;
+
+public class LinkedList implements List {
+
+ private Node head;
+ private int size = 0;
+
+ public void add(Object o){
+ if (head == null) {
+ head = new Node(o);
+ } else {
+ //遍历到链表的尾部
+ Node tail = head;
+ while (tail.next != null) {
+ tail = tail.next;
+ }
+ Node node = new Node(o);
+ tail.next = node;
+ }
+ size ++;
+ }
+ public void add(int index , Object o){
+ rangeCheckForAdd(index);
+ if (index ==0) {
+ Node node = new Node(o);
+ node.next = head;
+ head = node;
+ } else {
+ Node preHead = head;
+ for (int i = 0; i < index -1; i ++){
+ preHead = head.next;
+ }
+ Node node = new Node(o);
+ node.next = preHead.next;
+ preHead.next = node;
+ }
+ }
+ public Object get(int index){
+ rangeCheck(index);
+ Node dest = head;
+ for (int i = 0; i< index; i++){
+ dest = dest.next;
+ }
+ return dest.data;
+ }
+ private void rangeCheck(int index){
+ if (index >= size || index <0){
+ throw new IndexOutOfBoundsException();
+ }
+ }
+ public Object remove(int index){
+ rangeCheck(index);
+ Node preDest = head;
+ for (int i = 0; i < index; i++){
+ preDest = preDest.next;
+ }
+ Node dest = preDest.next;
+ preDest.next = dest.next;
+ size --;
+ return dest;
+ }
+
+ public int size(){
+ return size;
+ }
+
+ public void addFirst(Object o){
+ Node node = new Node(o);
+ node.next = head;
+ head = node;
+ size ++;
+ }
+ public void addLast(Object o){
+ Node lastNode = head;
+ while (lastNode.next != null){
+ lastNode = lastNode.next;
+ }
+ Node node = new Node(o);
+ lastNode.next = node;
+ size++;
+ }
+ public Object removeFirst(){
+ if (head == null) {
+ throw new NoSuchElementException();
+ }
+ Node headTmp = head;
+ head = head.next;
+ size --;
+ return headTmp;
+ }
+ public Object removeLast(){
+ if (head == null) {
+ throw new NoSuchElementException();
+ }
+ if (head.next == null) {
+ Node dest = head;
+ head = null;
+ size --;
+ return dest;
+ }
+ Node preLastNode = head;
+ while(preLastNode.next.next != null) {
+ preLastNode = preLastNode.next;
+ }
+ Node dest = preLastNode.next;
+ preLastNode.next = null;
+ size --;
+ return dest;
+ }
+ public Iterator iterator(){
+ return null;
+ }
+ private void rangeCheckForAdd(int index){
+ if (index > size || index <0){
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+ private static class Node{
+ Object data;
+ Node next;
+ Node (Object data) {
+ this.data = data;
+ next = null;
+ }
+ }
+}
diff --git a/group01/349209948/src/week1_0226/List.java b/group01/349209948/src/week1_0226/List.java
new file mode 100644
index 0000000000..ba1577cfaa
--- /dev/null
+++ b/group01/349209948/src/week1_0226/List.java
@@ -0,0 +1,9 @@
+package week1_0226;
+
+public interface List {
+ public void add(Object o);
+ public void add(int index, Object o);
+ public Object get(int index);
+ public Object remove(int index);
+ public int size();
+}
diff --git a/group01/349209948/src/week1_0226/Queue.java b/group01/349209948/src/week1_0226/Queue.java
new file mode 100644
index 0000000000..a20d6a303e
--- /dev/null
+++ b/group01/349209948/src/week1_0226/Queue.java
@@ -0,0 +1,21 @@
+package week1_0226;
+
+public class Queue {
+
+ private LinkedList list = new LinkedList();
+ public void enQueue(Object o){
+ list.add(o);
+ }
+
+ public Object deQueue(){
+ return list.removeFirst();
+ }
+
+ public boolean isEmpty(){
+ return list.size() == 0;
+ }
+
+ public int size(){
+ return list.size();
+ }
+}
diff --git a/group01/349209948/src/week1_0226/Stack.java b/group01/349209948/src/week1_0226/Stack.java
new file mode 100644
index 0000000000..f5d6add66d
--- /dev/null
+++ b/group01/349209948/src/week1_0226/Stack.java
@@ -0,0 +1,29 @@
+package week1_0226;
+import java.util.EmptyStackException;
+public class Stack {
+ private ArrayList elementData = new ArrayList();
+
+ public void push(Object o){
+ elementData.add(o);
+ }
+
+ public Object pop(){
+ checkStack();
+ return elementData.remove(elementData.size() - 1);
+ }
+ private void checkStack(){
+ if (elementData.size() == 0){
+ throw new EmptyStackException();
+ }
+ }
+ public Object peek(){
+ checkStack();
+ return elementData.get(elementData.size() - 1);
+ }
+ public boolean isEmpty(){
+ return elementData.size() == 0;
+ }
+ public int size(){
+ return elementData.size();
+ }
+}
diff --git a/group01/360176196/.classpath b/group01/360176196/.classpath
new file mode 100644
index 0000000000..fb5011632c
--- /dev/null
+++ b/group01/360176196/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/group01/360176196/.gitignore b/group01/360176196/.gitignore
new file mode 100644
index 0000000000..5e56e040ec
--- /dev/null
+++ b/group01/360176196/.gitignore
@@ -0,0 +1 @@
+/bin
diff --git a/group01/360176196/.project b/group01/360176196/.project
new file mode 100644
index 0000000000..a895f05a76
--- /dev/null
+++ b/group01/360176196/.project
@@ -0,0 +1,17 @@
+
+
+ xqfGit
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group01/360176196/src/xqfGit/dataStructure/ArrayList.java b/group01/360176196/src/xqfGit/dataStructure/ArrayList.java
new file mode 100644
index 0000000000..5996182fbe
--- /dev/null
+++ b/group01/360176196/src/xqfGit/dataStructure/ArrayList.java
@@ -0,0 +1,73 @@
+package xqfGit.dataStructure;
+
+import java.util.Arrays;
+
+public class ArrayList implements List {
+
+ private int size = 0;
+
+ private Object[] elementData = new Object[100];
+
+
+ public void add(Object o){
+ if(this.size >= elementData.length){
+ elementData = Arrays.copyOf(elementData, size+1);
+ elementData[size] = o;
+ size++;
+ }
+ else{
+ elementData[size-1] = o;
+ size++;
+ }
+
+ }
+
+ public void add(int index, Object o){
+ if(index<0 || index>elementData.length){
+ throw new ArrayIndexOutOfBoundsException("OutOfBounds");
+ }
+ else{
+ System.arraycopy(elementData, index, elementData, index+1, elementData.length+1);
+ elementData[index] = o;
+ size++;
+ }
+ }
+
+
+ public Object get(int index){
+ if(index<0 || index>elementData.length){
+ throw new ArrayIndexOutOfBoundsException("OutOfBounds");
+ }
+ else{
+ return elementData[index];
+ }
+ }
+
+
+ public Object remove(int index){
+ if(index<0 || index>elementData.length){
+ throw new ArrayIndexOutOfBoundsException("OutOfBounds");
+ }
+ else{
+ Object reObject = elementData[index];
+ System.arraycopy(elementData, index+1, elementData, index, elementData.length-1);
+ size--;
+ return reObject;
+ }
+ }
+
+ public int size(){
+ if(this.size < elementData.length){
+ return size;
+ }else{
+ elementData = Arrays.copyOf(elementData, size);
+ return size;
+ }
+ }
+
+
+ public Iterator iterator(){
+ return null;
+ }
+
+}
diff --git a/group01/360176196/src/xqfGit/dataStructure/BinaryTreeNode.java b/group01/360176196/src/xqfGit/dataStructure/BinaryTreeNode.java
new file mode 100644
index 0000000000..7662484884
--- /dev/null
+++ b/group01/360176196/src/xqfGit/dataStructure/BinaryTreeNode.java
@@ -0,0 +1,49 @@
+package xqfGit.dataStructure;
+
+import com.sun.swing.internal.plaf.basic.resources.basic;
+
+public class BinaryTreeNode {
+
+ private Integer data;
+ private BinaryTreeNode left;
+ private BinaryTreeNode right;
+
+
+
+
+ public Integer 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 i){
+
+ return null;
+ }
+
+ public BinaryTreeNode (){
+
+ }
+
+
+
+ public BinaryTreeNode(BinaryTreeNode b1,BinaryTreeNode b2){
+ this.left = b1;
+ this.right = b2;
+ }
+
+}
diff --git a/group01/360176196/src/xqfGit/dataStructure/Iterator.java b/group01/360176196/src/xqfGit/dataStructure/Iterator.java
new file mode 100644
index 0000000000..ee4842739f
--- /dev/null
+++ b/group01/360176196/src/xqfGit/dataStructure/Iterator.java
@@ -0,0 +1,7 @@
+package xqfGit.dataStructure;
+
+public interface Iterator {
+ public boolean hasNext();
+ public Object next();
+
+}
diff --git a/group01/360176196/src/xqfGit/dataStructure/LinkedList.java b/group01/360176196/src/xqfGit/dataStructure/LinkedList.java
new file mode 100644
index 0000000000..a663f85b15
--- /dev/null
+++ b/group01/360176196/src/xqfGit/dataStructure/LinkedList.java
@@ -0,0 +1,116 @@
+package xqfGit.dataStructure;
+
+public class LinkedList implements List {
+
+ private Node first;
+ private Node last;
+ private int size;
+
+ public void add(Object o){
+ Node l = new Node(o);
+ l = last.next;
+ size++;
+ }
+
+ public void add(int index , Object o){
+ Node l = new Node(o);
+ Node n = first;
+ if(size == index){
+ l = last.next;
+ l = last;
+ size++;
+ }else{
+ Node m = first;
+ for(int i =0;i
+
+
+
+
+
diff --git a/group01/378213871/.gitignore b/group01/378213871/.gitignore
new file mode 100644
index 0000000000..ae3c172604
--- /dev/null
+++ b/group01/378213871/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/group01/378213871/.project b/group01/378213871/.project
new file mode 100644
index 0000000000..a6666f301e
--- /dev/null
+++ b/group01/378213871/.project
@@ -0,0 +1,17 @@
+
+
+ coding
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group01/378213871/src/com/coding/basic/week01/ArrayList.java b/group01/378213871/src/com/coding/basic/week01/ArrayList.java
new file mode 100644
index 0000000000..5745209a08
--- /dev/null
+++ b/group01/378213871/src/com/coding/basic/week01/ArrayList.java
@@ -0,0 +1,74 @@
+package com.coding.basic.week01;
+
+import java.util.Arrays;
+
+public class ArrayList implements List {
+
+ private int size = 0;
+
+ private Object[] elementData = new Object[100];
+
+ public void add(Object o){
+ ensureCapacity(size + 1);
+ elementData[size++] = o;
+ }
+
+ public void ensureCapacity(int size) {
+ if (size > elementData.length) {
+ grow();
+ }
+ }
+
+ public void grow() {
+ elementData = Arrays.copyOf(elementData, size * 2);
+ }
+
+ public void add(int index, Object o){
+ if (index < 0 || index >= size) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ ensureCapacity(size + 1);
+ System.arraycopy(elementData, index, elementData, index + 1, size - index);
+ elementData[index] = o;
+ size++;
+ }
+
+ public Object get(int index){
+ if (index < 0 || index >= size) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ return elementData[index];
+ }
+
+ public Object remove(int index){
+ if (index < 0 || index >= size) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ Object removedItem = elementData[index];
+ System.arraycopy(elementData, index + 1, elementData, index, size - index - 1);
+ size--;
+ return removedItem;
+ }
+
+ public int size(){
+ return size;
+ }
+
+ public Iterator iterator(){
+ return new Iterator() {
+ private int current = 0;
+
+ public boolean hasNext() {
+ return current < size();
+ }
+
+ public Object next() {
+ if(!hasNext()) {
+ throw new java.util.NoSuchElementException();
+ }
+ return elementData[current++];
+ }
+ };
+ }
+
+}
diff --git a/group01/378213871/src/com/coding/basic/week01/BinaryTreeNode.java b/group01/378213871/src/com/coding/basic/week01/BinaryTreeNode.java
new file mode 100644
index 0000000000..36e20a95c5
--- /dev/null
+++ b/group01/378213871/src/com/coding/basic/week01/BinaryTreeNode.java
@@ -0,0 +1,32 @@
+package com.coding.basic.week01;
+
+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/378213871/src/com/coding/basic/week01/Iterator.java b/group01/378213871/src/com/coding/basic/week01/Iterator.java
new file mode 100644
index 0000000000..365e98e8b4
--- /dev/null
+++ b/group01/378213871/src/com/coding/basic/week01/Iterator.java
@@ -0,0 +1,7 @@
+package com.coding.basic.week01;
+
+public interface Iterator {
+ public boolean hasNext();
+ public Object next();
+
+}
diff --git a/group01/378213871/src/com/coding/basic/week01/LinkedList.java b/group01/378213871/src/com/coding/basic/week01/LinkedList.java
new file mode 100644
index 0000000000..dd6f3fb2e6
--- /dev/null
+++ b/group01/378213871/src/com/coding/basic/week01/LinkedList.java
@@ -0,0 +1,129 @@
+package com.coding.basic.week01;
+
+import java.util.NoSuchElementException;
+
+public class LinkedList implements List {
+
+ private Node head;
+
+ private int size;
+
+ public void add(Object o){
+ if (head == null) {
+ head = new Node(o);
+ size++;
+ } else{
+ addLast(o);
+ }
+ }
+ public void add(int index , Object o){
+ if (index < 0 || index > size) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (index == 0) {
+ addFirst(o);
+ } else {
+ //定义标记节点sentinelNode,标记节点的下一个节点即为要新加的元素
+ Node sentinelNode = head;
+ for (int i = 0; i < index - 1; i++) {
+ sentinelNode = sentinelNode.next;
+ }
+ Node node = new Node(o);
+ node.next = sentinelNode.next;
+ sentinelNode.next = node;
+ size++;
+ }
+ }
+ public Object get(int index){
+ if (index < 0 || index > size) {
+ throw new IndexOutOfBoundsException();
+ } else {
+ Node indexNode = head;
+ for (int i = 0; i < index; i++) {
+ indexNode = indexNode.next;
+ }
+ return indexNode.data;
+ }
+ }
+ public Object remove(int index){
+ if (index < 0 || index > size) {
+ throw new IndexOutOfBoundsException();
+ } else {
+ /**
+ * sentinelNode是所删除节点的上一个节点;
+ * indexNode是需要被删除的节点
+ */
+ Node sentinelNode = head;
+ Node indexNode = head;
+ for (int i = 0; i < index - 1; i++) {
+ sentinelNode = sentinelNode.next;
+ }
+ for (int i = 0; i < index; i++) {
+ indexNode = indexNode.next;
+ }
+ Node nextIndexNode = indexNode.next;
+ sentinelNode.next = nextIndexNode;
+ indexNode.next = null;
+ size--;
+ return indexNode.data;
+ }
+ }
+
+ public int size(){
+ return size;
+ }
+
+ public void addFirst(Object o){
+ Node node = new Node(o);
+ node.next = head;
+ head = node;
+ size++;
+ }
+ public void addLast(Object o){
+ //定义尾节点并通过while循环找到当前链表的尾节点
+ Node tailNode = head;
+ while (tailNode.next != null) {
+ tailNode = tailNode.next;
+ }
+ Node node = new Node(o);
+ tailNode.next = node;
+ size++;
+ }
+ public Object removeFirst(){
+ if (head == null) {
+ throw new NoSuchElementException();
+ }
+ Node newNode = head;
+ head = head.next;
+ size--;
+ return newNode.data;
+ }
+ public Object removeLast(){
+ if (head == null) {
+ throw new NoSuchElementException();
+ }
+ Node newNode = head;
+ while (newNode.next.next != null) {
+ newNode = newNode.next;
+ }
+ Node lastNode = newNode.next;
+ newNode.next = null;
+ size--;
+ return lastNode.data;
+ }
+
+ public Iterator iterator(){
+ return null;
+ }
+
+
+ private static class Node{
+ Object data;
+ Node next; // 下一个节点
+
+ private Node(Object data) {
+ this.data = data;
+ next = null;
+ }
+ }
+}
diff --git a/group01/378213871/src/com/coding/basic/week01/List.java b/group01/378213871/src/com/coding/basic/week01/List.java
new file mode 100644
index 0000000000..966ca016e8
--- /dev/null
+++ b/group01/378213871/src/com/coding/basic/week01/List.java
@@ -0,0 +1,9 @@
+package com.coding.basic.week01;
+
+public interface List {
+ public void add(Object o);
+ public void add(int index, Object o);
+ public Object get(int index);
+ public Object remove(int index);
+ public int size();
+}
diff --git a/group01/378213871/src/com/coding/basic/week01/Queue.java b/group01/378213871/src/com/coding/basic/week01/Queue.java
new file mode 100644
index 0000000000..1b25880f67
--- /dev/null
+++ b/group01/378213871/src/com/coding/basic/week01/Queue.java
@@ -0,0 +1,24 @@
+package com.coding.basic.week01;
+
+public class Queue {
+ private LinkedList list = new LinkedList();
+ //入队列
+ public void enQueue(Object o){
+ list.add(o);
+ }
+ //出队列
+ public Object deQueue(){
+ if(list.size() == 0) {
+ return null;
+ }
+ return list.removeFirst();
+ }
+
+ public boolean isEmpty(){
+ return list.size() == 0;
+ }
+
+ public int size(){
+ return list.size();
+ }
+}
diff --git a/group01/378213871/src/com/coding/basic/week01/Stack.java b/group01/378213871/src/com/coding/basic/week01/Stack.java
new file mode 100644
index 0000000000..64cfa30da6
--- /dev/null
+++ b/group01/378213871/src/com/coding/basic/week01/Stack.java
@@ -0,0 +1,35 @@
+package com.coding.basic.week01;
+
+import java.util.EmptyStackException;
+
+public class Stack {
+ private ArrayList elementData = new ArrayList();
+
+ //入栈
+ public void push(Object o){
+ elementData.add(o);
+
+ }
+
+ //出栈
+ public Object pop(){
+ if(elementData.size() == 0) {
+ throw new EmptyStackException();
+ }
+ return elementData.remove(elementData.size() - 1);
+ }
+
+ //读取栈顶元素
+ public Object peek(){
+ if(elementData.size() == 0) {
+ throw new EmptyStackException();
+ }
+ return elementData.get(elementData.size() - 1);
+ }
+ public boolean isEmpty(){
+ return size() == 0;
+ }
+ public int size(){
+ return elementData.size();
+ }
+}
diff --git a/group01/496740686/src/Impl/MyArraryList.java b/group01/496740686/src/Impl/MyArraryList.java
new file mode 100644
index 0000000000..20fb5dcfdf
--- /dev/null
+++ b/group01/496740686/src/Impl/MyArraryList.java
@@ -0,0 +1,141 @@
+package Impl;
+
+import Interface.ArrayList;
+import Interface.Iterator;
+import ex.MyArrest;
+
+/**
+ * Created by Administrator on 2017/2/25.
+ */
+public class MyArraryList extends ArrayList {
+ private Object[] objArr;
+ private int size;
+ private int postion;
+
+ public MyArraryList() {
+ this.objArr = new Object[10];
+ this.size = 10;
+ this.postion = 0;
+ }
+
+
+ public MyArraryList(int size) {
+ this.objArr = new Object[size];
+ this.size = size;
+ this.postion = 0;
+ }
+
+ public MyArraryList(Object[] objArr) {
+ this.objArr = objArr;
+ this.size = objArr.length;
+ this.postion = objArr.length - 1;
+ }
+
+ @Override
+ public void add(Object o) {
+ int limit = this.size + (this.size / 2);
+ Object[] newObjArr = new Object[limit];
+ //public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length)从指定源数组中复制一个数组,
+ // 复制从指定的位置开始,到目标数组的指定位置结束。从src引用的源数组到dest引用的目标数组,
+ // 数组组件的一个子序列被复制下来。被复制的组件的编号等于length参数。
+ // 源数组中位置在srcPos到srcPos+length-1之间的组件被分别复制到目标数组中的destPos到destPos+length-1位置。
+ System.arraycopy(this.objArr, 0, newObjArr, 0, objArr.length);
+ this.postion = this.size - 1;
+ newObjArr[this.postion] = o;
+ this.size = limit;
+ objArr = null;
+ this.objArr = newObjArr;
+ }
+
+ @Override
+ public void add(int index, Object o) {
+ arrIndexVildate(index);
+ objArr[index - 1] = o;
+ size++;
+ }
+
+ @Override
+ public Object get(int index) {
+ arrIndexVildate(index);
+ return objArr[index - 1];
+ }
+
+ @Override
+ public Object remove(int index) {
+ arrIndexVildate(index);
+ Object remoteObj = objArr[index - 1];
+ objArr[index - 1] = null;
+ size--;
+ //TODO need GC ccontrol
+ return remoteObj;
+ }
+
+ @Override
+ public int size() {
+ return this.size;
+ }
+
+ @Override
+ public Iterator iterator() {
+ return new ArrayListIterator(this);
+ }
+
+ private class ArrayListIterator implements Iterator {
+ private MyArraryList arraryList;
+ private int index;
+
+ public ArrayListIterator(MyArraryList arraryList) {
+ this.arraryList = arraryList;
+ this.index = arraryList.size - 1;
+ }
+
+ @Override
+ public boolean hasNext() {
+ if (index > arraryList.size) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public Object next() {
+ Object obj = arraryList.get(index);
+ index++;
+ return obj;
+ }
+ }
+
+ private void arrIndexVildate(int index) {
+ if (index > size - 1 || index < 0) {
+ new Exception(String.format("cant than that array index %s,but got %", size - 1, index));
+ }
+ }
+
+ //test method
+ public static void main(String[] args) {
+ MyArraryList myArrary = new MyArraryList();
+ MyArrest.arrestEq(10, myArrary.size());
+ myArrary.add(1, 10);
+ MyArrest.arrestEq(10, myArrary.get(1));
+ myArrary.add(100);
+ System.out.println(myArrary.get(11));
+ myArrary.remove(1);
+ MyArrest.arrestIsNull(myArrary.get(1));
+ if (myArrary.iterator().hasNext()) {
+ myArrary.iterator().next();
+ }
+ System.out.println("test myArrary2");
+ MyArraryList myArrary2 = new MyArraryList(20);
+ MyArrest.arrestEq(20, myArrary2.size());
+ myArrary2.add(1, 10);
+ MyArrest.arrestEq(10, myArrary2.get(1));
+ myArrary2.add(100);
+ MyArrest.arrestIsNull(myArrary2.get(20));
+ myArrary2.remove(1);
+ MyArrest.arrestIsNull(myArrary2.get(1));
+ if (myArrary.iterator().hasNext()) {
+ myArrary2.iterator().next();
+ }
+ }
+}
diff --git a/group01/496740686/src/Impl/MyLinkedList.java b/group01/496740686/src/Impl/MyLinkedList.java
new file mode 100644
index 0000000000..017bac5baf
--- /dev/null
+++ b/group01/496740686/src/Impl/MyLinkedList.java
@@ -0,0 +1,177 @@
+package Impl;
+
+import Interface.Iterator;
+import Interface.LinkedList;
+import ex.MyArrest;
+
+/**
+ * Created by Administrator on 2017/2/26.
+ */
+public class MyLinkedList extends LinkedList {
+ private MyLinkedList.Node head;
+ private int size = 1;
+
+ public MyLinkedList() {
+
+ }
+
+ private static class Node {
+ Object data;
+ MyLinkedList.Node next;
+
+ public Node(Object data, Node next) {
+ this.data = data;
+ this.next = next;
+ }
+ }
+
+ public void add(Object o) {
+ if (this.size == 1) {
+ head.data = o;
+ return;
+ }
+ MyLinkedList.Node newHead = new MyLinkedList.Node(o, this.head);
+ this.size += 1;
+ this.head = newHead;
+ }
+
+
+ public void add(int index, Object o) {
+ IndexVildate(index);
+ int pos = 0;
+ if (index == 1) {
+ this.head = new Node(o, null);
+ return;
+ }
+ for (MyLinkedList.Node node = this.head; node != null; node = node.next) {
+ pos += 1;
+ if (pos == index - 1) {
+ node.data = o;
+ this.size += 1;
+ }
+ }
+ }
+
+
+ public Object get(int index) {
+ int pos = 0;
+ for (MyLinkedList.Node node = this.head; node != null; node = node.next) {
+ if (pos == index - 1) {
+ return node.data;
+ }
+ pos += 1;
+ }
+ return null;
+ }
+
+
+ public Object remove(int index) {
+ IndexVildate(index);
+ int pos = 0;
+ MyLinkedList.Node preNode;
+ for (MyLinkedList.Node node = this.head; node != null; node = node.next) {
+ pos += 1;
+ if (pos == index - 2) {
+ //record previous node
+ preNode = node;
+ if (pos == index - 1) {
+ MyLinkedList.Node willDelNode = node;
+ preNode.next = node.next;
+ node = null;
+ this.size -= 1;
+ return willDelNode;
+ }
+ }
+ }
+ return null;
+ }
+
+
+ public int size() {
+ return this.size;
+ }
+
+
+ public void addFirst(Object o) {
+ MyLinkedList.Node newHead = this.head;
+ newHead.data = o;
+ newHead.next = this.head;
+ this.size += 1;
+ this.head = newHead;
+ }
+
+
+ public void addLast(Object o) {
+ for (MyLinkedList.Node node = this.head; node != null; node = node.next) {
+ if (node.next == null) {
+ MyLinkedList.Node lastNode = new MyLinkedList.Node(o, null);
+ node.next = lastNode;
+ this.size += 1;
+ }
+ }
+ }
+
+
+ public Object removeFirst() {
+ MyLinkedList.Node oldHead = this.head;
+ this.head = oldHead.next;
+ this.size -= 1;
+ return oldHead;
+ }
+
+
+ public Object removeLast() {
+ for (MyLinkedList.Node node = this.head; node != null; node = node.next) {
+ if (node.next == null) {
+ MyLinkedList.Node willDelNode = node.next;
+ node.next = null;
+ this.size -= 1;
+ return willDelNode;
+ }
+ }
+ return null;
+ }
+
+ public Iterator iterator() {
+ return new LinkedListIterator(this);
+ }
+
+ private class LinkedListIterator implements Iterator {
+ private MyLinkedList linkedList;
+ private int index;
+
+ public LinkedListIterator(MyLinkedList linkedList) {
+ this.linkedList = linkedList;
+ this.index = linkedList.size;
+ }
+
+ @Override
+ public boolean hasNext() {
+ if (index > linkedList.size) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public Object next() {
+ Object obj = linkedList.get(index);
+ index++;
+ return obj;
+ }
+ }
+
+ private void IndexVildate(int index) {
+ if (index > this.size || index < 0) {
+ System.out.println("happend error");
+ }
+ }
+
+ public static void main(String[] args) {
+ MyLinkedList linkedList = new MyLinkedList();
+ linkedList.add(1, 23);
+ MyArrest.arrestEqByBasicType(1, linkedList.size());
+
+ }
+}
diff --git a/group01/496740686/src/Impl/MyQueue.java b/group01/496740686/src/Impl/MyQueue.java
new file mode 100644
index 0000000000..1a029738d2
--- /dev/null
+++ b/group01/496740686/src/Impl/MyQueue.java
@@ -0,0 +1,68 @@
+package Impl;
+
+import Interface.Queue;
+
+/**
+ * Created by Administrator on 2017/2/26.
+ */
+public class MyQueue extends Queue {
+
+ private Node first; // beginning of queue
+ private Node last; // end of queue
+ private int size; // number of elements on queue
+
+ private static class Node {
+ private Object value;
+ private Node next;
+
+ public Node(Object value, Node next) {
+ this.value = value;
+ this.next = next;
+ }
+ }
+
+ public MyQueue() {
+ first = null;
+ last = null;
+ int n = 0;
+ }
+
+ @Override
+ public void enQueue(Object o) {
+ Node oldlast = this.last;
+ this.last = new Node(o, null);
+ size += 1;
+ //第一个进队列
+ if (isEmpty()) {
+ first = last;
+ } else {
+ oldlast.next = this.last;
+ }
+
+ }
+
+ @Override
+ public Object deQueue() {
+ if (isEmpty()) {
+ return null;
+ } else {
+ Node oldFirst = this.first;
+ Node newFirst = this.first.next;
+ this.first = null;
+ this.first = newFirst;
+ this.size -= 1;
+ return oldFirst;
+
+ }
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return first == null;
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+}
diff --git a/group01/496740686/src/Impl/MyStack.java b/group01/496740686/src/Impl/MyStack.java
new file mode 100644
index 0000000000..3a7c119e99
--- /dev/null
+++ b/group01/496740686/src/Impl/MyStack.java
@@ -0,0 +1,70 @@
+package Impl;
+
+import Interface.ArrayList;
+import Interface.Stack;
+
+
+/**
+ * Created by Administrator on 2017/2/26.
+ */
+public class MyStack extends Stack {
+
+ private MyStack.Node first; // beginning of queue
+ private MyStack.Node last; // end of queue
+ private int size; // number of elements on queue
+
+ private static class Node {
+ private Object value;
+ private MyStack.Node next;
+
+ public Node(Object value, MyStack.Node next) {
+ this.value = value;
+ this.next = next;
+ }
+ }
+
+ public MyStack() {
+ first = null;
+ last = null;
+ int n = 0;
+ }
+
+ @Override
+ public void push(Object o) {
+ if (isEmpty()) {
+ MyStack.Node oldFirst = this.first;
+ this.first = new MyStack.Node(o, null);
+ size += 1;
+ //第一个进栈
+ if (isEmpty()) {
+ first = last;
+ } else {
+ oldFirst.next = this.last;
+ }
+ }
+ }
+
+ @Override
+ public Object pop() {
+ if (isEmpty()) {
+ return null;
+ } else {
+ MyStack.Node oldFirst = this.first;
+ this.first = oldFirst.next;
+ this.size -= 1;
+ return oldFirst;
+
+ }
+
+ }
+
+ @Override
+ public Object peek() {
+ return this.first;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return first == null;
+ }
+}
diff --git a/group01/496740686/src/Interface/ArrayList.java b/group01/496740686/src/Interface/ArrayList.java
new file mode 100644
index 0000000000..567c1996b1
--- /dev/null
+++ b/group01/496740686/src/Interface/ArrayList.java
@@ -0,0 +1,34 @@
+package Interface;
+
+
+
+public class ArrayList implements List {
+
+ private int size = 0;
+
+ private Object[] elementData = new Object[100];
+
+ public void add(Object o){
+
+ }
+ public void add(int index, Object o){
+
+ }
+
+ public Object get(int index){
+ return null;
+ }
+
+ public Object remove(int index){
+ return null;
+ }
+
+ public int size(){
+ return -1;
+ }
+
+ public Iterator iterator(){
+ return null;
+ }
+
+}
diff --git a/group01/496740686/src/Interface/BinaryTreeNode.java b/group01/496740686/src/Interface/BinaryTreeNode.java
new file mode 100644
index 0000000000..c5480a614f
--- /dev/null
+++ b/group01/496740686/src/Interface/BinaryTreeNode.java
@@ -0,0 +1,32 @@
+package Interface;
+
+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/496740686/src/Interface/Iterator.java b/group01/496740686/src/Interface/Iterator.java
new file mode 100644
index 0000000000..77e3c0b216
--- /dev/null
+++ b/group01/496740686/src/Interface/Iterator.java
@@ -0,0 +1,7 @@
+package Interface;
+
+public interface Iterator {
+ public boolean hasNext();
+ public Object next();
+
+}
diff --git a/group01/496740686/src/Interface/LinkedList.java b/group01/496740686/src/Interface/LinkedList.java
new file mode 100644
index 0000000000..b7166a1731
--- /dev/null
+++ b/group01/496740686/src/Interface/LinkedList.java
@@ -0,0 +1,47 @@
+package Interface;
+
+public class LinkedList implements List {
+
+ private Node head;
+
+ public void add(Object o){
+
+ }
+ public void add(int index , Object o){
+
+ }
+ public Object get(int index){
+ return null;
+ }
+ public Object remove(int index){
+ return null;
+ }
+
+ public int size(){
+ return -1;
+ }
+
+ public void addFirst(Object o){
+
+ }
+ public void addLast(Object o){
+
+ }
+ public Object removeFirst(){
+ return null;
+ }
+ public Object removeLast(){
+ return null;
+ }
+ public Iterator iterator(){
+ return null;
+ }
+
+
+ private static class Node{
+ Object data;
+ Node next;
+
+ }
+
+}
diff --git a/group01/496740686/src/Interface/List.java b/group01/496740686/src/Interface/List.java
new file mode 100644
index 0000000000..98d6a4da0a
--- /dev/null
+++ b/group01/496740686/src/Interface/List.java
@@ -0,0 +1,9 @@
+package Interface;
+
+public interface List {
+ public void add(Object o);
+ public void add(int index, Object o);
+ public Object get(int index);
+ public Object remove(int index);
+ public int size();
+}
diff --git a/group01/496740686/src/Interface/Queue.java b/group01/496740686/src/Interface/Queue.java
new file mode 100644
index 0000000000..8e3a5d5f43
--- /dev/null
+++ b/group01/496740686/src/Interface/Queue.java
@@ -0,0 +1,19 @@
+package Interface;
+
+public class Queue {
+
+ public void enQueue(Object o){
+ }
+
+ public Object deQueue(){
+ return null;
+ }
+
+ public boolean isEmpty(){
+ return false;
+ }
+
+ public int size(){
+ return -1;
+ }
+}
diff --git a/group20/592146505/data _structure/src/cn/wsc/utils/Stack.java b/group01/496740686/src/Interface/Stack.java
similarity index 92%
rename from group20/592146505/data _structure/src/cn/wsc/utils/Stack.java
rename to group01/496740686/src/Interface/Stack.java
index 3f156461e8..7e536e250a 100644
--- a/group20/592146505/data _structure/src/cn/wsc/utils/Stack.java
+++ b/group01/496740686/src/Interface/Stack.java
@@ -1,4 +1,4 @@
-package cn.wsc.utils;
+package Interface;
public class Stack {
private ArrayList elementData = new ArrayList();
diff --git a/group01/496740686/src/ex/MyArrest.java b/group01/496740686/src/ex/MyArrest.java
new file mode 100644
index 0000000000..9987b83535
--- /dev/null
+++ b/group01/496740686/src/ex/MyArrest.java
@@ -0,0 +1,75 @@
+package ex;
+
+/**
+ * Created by Administrator on 2017/2/26.
+ */
+public class MyArrest {
+
+
+ public static void arrestEq(T expect, T value) {
+ if (expect == null || value == null) {
+ if (expect == value) {
+ System.out.println("it's ok \n" );
+ return;
+ } else {
+ System.out.println("happend error \n" );
+ return;
+ }
+ }
+ if (expect.equals(value)) {
+ System.out.println("it's ok \n" );
+ return;
+ } else {
+ System.out.println("happend error \n" );
+ return;
+ }
+ }
+
+ public static void arrestEq(T expect, T value, String errorInfo) {
+ if (expect == null || value == null) {
+ if (expect == value) {
+ System.out.println("it's ok \n" );
+ return;
+ } else {
+ System.out.println("happend error \n" );
+ return;
+ }
+ }
+ if (expect.equals(value)) {
+ System.out.println("it's ok \n" );
+ return;
+ } else {
+ System.out.println("happend error \n" );
+ return;
+ }
+ }
+
+ public static void arrestEqByBasicType(T expect, T value) {
+ if (expect == null || value == null) {
+ if (expect == value) {
+ System.out.println("it's ok \n" );
+ return;
+ } else {
+ System.out.println("happend error \n" );
+ return;
+ }
+ }
+ if (expect == value) {
+ System.out.println("it's ok \n" );
+ return;
+ } else {
+ System.out.println("happend error \n" );
+ return;
+ }
+ }
+
+ public static void arrestIsNull(Object obj) {
+ if (obj == null) {
+ System.out.println("it's null , you're right \n" );
+ return;
+ } else {
+ System.out.println("happend error \n" );
+ return;
+ }
+ }
+}
diff --git a/group01/751425278/.classpath b/group01/751425278/.classpath
new file mode 100644
index 0000000000..fb5011632c
--- /dev/null
+++ b/group01/751425278/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/group01/751425278/.gitignore b/group01/751425278/.gitignore
new file mode 100644
index 0000000000..ae3c172604
--- /dev/null
+++ b/group01/751425278/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/group01/751425278/.project b/group01/751425278/.project
new file mode 100644
index 0000000000..85d6b2c816
--- /dev/null
+++ b/group01/751425278/.project
@@ -0,0 +1,17 @@
+
+
+ basicDataStructure
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group01/751425278/src/com/sanmubird/basicDataStructure/ArrayList.java b/group01/751425278/src/com/sanmubird/basicDataStructure/ArrayList.java
new file mode 100644
index 0000000000..3e6c874d90
--- /dev/null
+++ b/group01/751425278/src/com/sanmubird/basicDataStructure/ArrayList.java
@@ -0,0 +1,156 @@
+package com.sanmubird.basicDataStructure;
+
+import java.util.Arrays;
+
+public class ArrayList implements List {
+
+ /** ArrayList 是一个类,一个类就会有对象,属性,构造方法,方法
+ * ArrayList 是基于数组来实现List接口; 那么它的元素就会有 存储在数组中的元素, 和ArrayList的长度
+ * 这个地方需要区分size= ArrayList.size() 和 length = Array.length ;
+ * size 是 已经占用的长度;
+ * length 是数组的长度; length 》= size 当,size > length 时,数组要动态扩容;
+ * */
+
+// 数组默认的长度
+ private static final int DEFAULT_SIZE = 10;
+
+// ArrayList的大小
+ private int size ;
+
+// 数组中存储的元素
+ private Object[] elementData = null;
+
+ private int count ;
+
+// ArrayList 的构造方法 通过构造方法 可以得到这个类的对象
+// 有参构造方法
+ public ArrayList(int i){
+ if(i <= 0 ){
+ throw new RuntimeException("数组的长度不能小于等于0");
+ }else{
+ this.elementData = new Object[i];
+ this.size = 0 ; // 集合ArrayList的大小;
+ }
+ }
+ // 无参构造方法
+ public ArrayList(){
+ this(DEFAULT_SIZE); // this 会调用本类中 相同参数(相同的参数个数和参数类型)的构造方法;
+ }
+
+ /** ArrayList 其他方法分析
+ * 目标方法:
+ * size(); Array的length就是ArrayList的大小
+ * get(int index); Array的【index-1】就是 ArrayList的第index位元素
+ * add(Object o) ; 这个方法是在数组的末尾顺序添加一个元素; 找到数组的长度size,将array【size-1】= Object
+ * add(int index , Object o); 这个方法是在数组的指定位置添加一个元素;找到index位,将index位起往后挪一位,并将array【index】=Object
+ * remove(int index); 这个方法是 删除指定位上的元素,直接将这个位至最后的元素往前挪移一位。
+ *
+ * 工具方法:
+ * argumentCheck(int index); 判断输入的参数是否合法;比如传入的参数不能比数组长度大,或者不能为负数等
+ * ensureCapacity(); 判断当前数组的长度是否足够大,能再容纳下一个元素。
+ *
+ * */
+
+
+// 对传入的参数进行验证是否合法 如果输入的参数不合法 就抛出异常
+ public void argumentCheck(int index){
+ if(index >= size || index < 0 ){ // 此处我觉得需要 ‘=’ 因为 index 我觉得是下标
+ throw new IndexOutOfBoundsException("插入的下标是:"+index +",但ArrayLsit的长度是:"+size);
+ }
+ }
+
+ // 判断是否数组是否溢出的方法 如果数组现在的长度小于所需的最小长度,就需要对数组进行扩容
+ public void ensureCapacity(int minCapacity){
+ int length = elementData.length; // 得出当前数组的长度
+ if(minCapacity > length){
+ int newCapacity = length * 3 / 2 + 1 ; //你是否对此有疑问?得出的结果会不会是小数? 答案是不会的,java中算术运算符“/”;两个int类型相除,结果一定是int类型
+ if(minCapacity > newCapacity ){
+ newCapacity = minCapacity ;
+ }
+ count++;
+ System.out.println("扩容"+count+"次");
+ elementData = Arrays.copyOf(elementData, newCapacity);//此处为什么用Arrays.copyOf()而不用System.arraycopy()?
+ // Arrays.copyOf(): 不仅仅copy数组中的元素,还会创建一个新的数组来存放copy的对象
+ // System.arraycopy():仅仅是copy数组中的元素,不会新建一个数组对象,也不会改变原有的数组长度。
+ // 在原有数组长度不够的情况下,只能选择新建一个数组,并将原有的数组复制到新数组的办法来解决。
+ }
+ }
+
+ // 得到ArrayList 大小的方法 ; 此处的size 不是Array的length,而是ArrayList中元素的个数
+ public int size(){
+ return size;
+ }
+
+// 传入下标得到元素
+ public Object get(int index){
+ argumentCheck(index); //需要判断传入的参数是否合法;
+ return elementData[index];
+ }
+
+// 按顺序在数字尾部添加元素
+ public void add(Object o){
+ ensureCapacity(size+1); // 判断是否会溢出
+ elementData[size++] = o ; //此处使用 size++ 的好处:elementData[size+1];size++;
+ }
+
+ public void add(int index, Object o){ //这个地方需要搞清楚index的含义:index在此处是下标的意思
+ argumentCheck(index); //判断输入的下标是否合法 --->
+ // 刚开始的时候 ; 我觉得这个地方不需要加这个判断,因为ArrayList是动态增长的;
+ // 我还需要想明白这个问题;
+ ensureCapacity(size+1); // 判断是否会溢出
+ int moveLength = size - (index + 1) + 1; // 此处index是下标;下标是从0开始计算的;所以第n位的下标就是(n-1);所以,n = index + 1
+ // 此处的 +1 刚开始没想明白,后来组长给举了个例子,1-3 有三个数,但不是通过3-1=2 算出来的
+ System.arraycopy(elementData, index, elementData, index+1, moveLength );
+ elementData[index] = o ;
+ size++;
+ }
+
+ public Object remove(int index){
+ argumentCheck(index); //判断输入的下标是否合法
+ Object o = elementData[index];
+ System.arraycopy(elementData, index, elementData, index-1, size-index);
+ elementData[size] = null ;
+ size--;
+ return o;
+ }
+
+ public Iterator iterator(){
+ return new Iterator(){
+ private int index = 0 ;
+
+ @Override
+ public Object next(){
+ return elementData[index++];
+ }
+ @Override
+ public boolean hasNext() {
+ return index < size ;
+ }
+ };
+ }
+
+ public static void main(String [] args){
+ ArrayList al = new ArrayList();
+ al.add(1);
+ al.add(2);
+ al.add(4);
+ al.add(5);
+ al.add(6);
+ al.add(7);
+ al.add(2,3);
+ al.add(8);
+ al.add(9);
+ al.add(10);
+ al.add(11);
+ al.add(13);
+ al.add(9,12);
+ al.add(14);
+ al.add(15);
+ al.remove(9);
+ for(int i = 0 ; i < al.size() ; i++ ){
+ System.out.println(al.get(i));
+ }
+ System.out.println("al的size是"+al.size());
+ System.out.println(al.get(15));
+ }
+}
\ No newline at end of file
diff --git a/group01/751425278/src/com/sanmubird/basicDataStructure/BinaryTreeNode.java b/group01/751425278/src/com/sanmubird/basicDataStructure/BinaryTreeNode.java
new file mode 100644
index 0000000000..4096c79e36
--- /dev/null
+++ b/group01/751425278/src/com/sanmubird/basicDataStructure/BinaryTreeNode.java
@@ -0,0 +1,58 @@
+package com.sanmubird.basicDataStructure;
+
+public class BinaryTreeNode {
+ /** 二叉树同时具有数组和链表各自的特点:它可以像数组一样迅速查找;也可以像链表一样快速添加;
+ * 但 删除操作复杂;
+ * 二叉树是每个节点最多有两个子树的有序树;
+ * 一个节点的左子点的关键值必须小于此节点,右节点的关键值必须大于或者等于此节点,
+ * */
+
+
+ private Integer data;
+ private BinaryTreeNode left;
+ private BinaryTreeNode right;
+
+ public BinaryTreeNode(Integer i){
+ this.data = i ;
+ }
+
+
+ public Object getData() {
+ return data;
+ }
+ public void setData(Integer i) {
+ this.data = i;
+ }
+ 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 i){
+ BinaryTreeNode node = new BinaryTreeNode(i);
+ if(i > this.data){
+ if(this.getRight() == null ){
+ this.setRight(node);
+ return node;
+ }else{
+ return this.getRight().insert(i);
+ }
+ }else{
+ if(this.getLeft() == null ){
+ this.setLeft(node);
+ return node ;
+ }else{
+ return this.getLeft().insert(i);
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/group01/751425278/src/com/sanmubird/basicDataStructure/Iterator.java b/group01/751425278/src/com/sanmubird/basicDataStructure/Iterator.java
new file mode 100644
index 0000000000..df4a1e3a6d
--- /dev/null
+++ b/group01/751425278/src/com/sanmubird/basicDataStructure/Iterator.java
@@ -0,0 +1,6 @@
+package com.sanmubird.basicDataStructure;
+
+public interface Iterator {
+ public boolean hasNext();
+ public Object next();
+}
\ No newline at end of file
diff --git a/group01/751425278/src/com/sanmubird/basicDataStructure/LinkedList.java b/group01/751425278/src/com/sanmubird/basicDataStructure/LinkedList.java
new file mode 100644
index 0000000000..31703dd5f1
--- /dev/null
+++ b/group01/751425278/src/com/sanmubird/basicDataStructure/LinkedList.java
@@ -0,0 +1,159 @@
+package com.sanmubird.basicDataStructure;
+
+import java.util.NoSuchElementException;
+
+public class LinkedList implements List {
+ /** 链表:是由节点(Node)组成的,
+ * 而向外暴露的只有一个头节点;我们对链表的所有操作,都是直接或简洁地通过头节点来实现的。
+ * 节点(Node)是由 一个 存储的对象和一个对下个节点的引用组成的。
+ * Node中最重要的就是引用了,如果说对ArrayList的增删是ArrayCopy的话,那对LinkedList的增删就是改变引用的指向。
+ * 因为节点的添加顺序是自右向左的,且最左边的节点是头节点;
+ * 所以,新添加的节点会在左边,而是新添加的节点会成为新的t头节点。
+ * 头节点可以通过对下一个节点的引用,来找到所有的节点;
+ * 所以:链表里面的属性就有两个,一个是头节点,一个是节点的数量。
+ ***/
+ private Node head; //定义一个头节点
+ private int size ; //节点的数量
+
+ public LinkedList(){
+ this.head = null ;
+ this.size = 0 ;
+ }
+
+// 检查输入的参数是否合法
+ public void argumentCheckForAdd(int index){
+ if(index > size || index < 0 ){ //这个地反需要验证 index = 0 的情况
+ throw new IndexOutOfBoundsException("输入的参数超出了边界!");
+ }
+ }
+
+// 检查输入的参数是否合法
+ public void argumentCheckForOther(int index){
+ if(index >= size || index < 0 ){
+ throw new IndexOutOfBoundsException("输入的参数超出了边界!");
+ }
+ }
+
+
+ public Node getHead(){
+ return head ;
+ }
+
+ public Object get(int index){
+ argumentCheckForOther(index);
+ Node node = head ;
+ for(int i = 0 ; i < index ; i++){
+ node = head.next ;
+ }
+ return node.data;
+ }
+ public int size(){
+ return size; // return this.size 跟 return size ;有区别没有?
+ }
+
+//
+ public void add(Object o){
+ Node newNode = new Node(o); //实例化一个要添加的节点
+ if(head == null ){
+ head = newNode ;
+ }else{
+ Node temp = head ;
+ while (temp.next != null ){ //这个地方为什么是 temp.next != null ?
+ // 这个地方的作用就是:取出下一个节点;那么当然是在存在下个节点的情况下,才能取出下个节点
+ temp = temp.next ;
+ // 这样就找到了最后一个节点: temp
+ }
+ temp.next = newNode ;
+ }
+ size++;
+ }
+
+// 这个通过画图,然后看图说话就很容易弄出来。
+ public void add(int index , Object o){
+ argumentCheckForAdd(index);
+ if(size == index )
+ add(o);
+ else{
+ Node preNode = head ;
+ for (int i = 0 ; i < index ; i++){
+ preNode = preNode.next;
+ }
+ Node nextNode = preNode.next ;
+ Node node = new Node(o);
+ preNode.next = node;
+ node.next = nextNode;
+ size++;
+ }
+ }
+
+ public Object remove(int index){
+ argumentCheckForOther(index);
+ Node temp = head ;
+ for(int i = 0 ; i < index ; i++){
+ temp = temp.next ;
+ }
+ Node removedNode = temp.next ;
+ Node nextNode = removedNode.next ;
+ temp.next = nextNode ;
+ size--;
+ return removedNode.data;
+ }
+
+
+ public void addFirst(Object o){
+ Node node = new Node(o);
+ node.next = head ;
+ head = node ;
+ size++;
+ }
+
+ public void addLast(Object o){
+ Node lastNode = head ;
+ while(lastNode.next != null ){
+ lastNode = lastNode.next ;
+ }
+ Node node = new Node(o);
+ lastNode.next = node ;
+ size++;
+ }
+
+ public void noSuchElement(){
+ if(head.next == null){
+ throw new NoSuchElementException("没有这个元素");
+ }
+ }
+
+
+ public Object removeFirst(){
+ noSuchElement();
+ Node node = head.next ;
+ head.next = node.next ;
+ size--;
+ return node.data;
+ }
+
+ public Object removeLast(){
+ noSuchElement();
+ Node temp = head ;
+ for(int i = 0 ; i 0){
+ this.queArray = new Object[initialSize];
+ this.maxSize = initialSize;
+ this.front = this.rear = 0 ;
+ }else{
+ throw new RuntimeException("初始化的大小不能小于0;"+ initialSize);
+ }
+}
+
+ public void enQueue(Object o){
+ if(rear == maxSize){
+ throw new RuntimeException("队列已满,无法插入新的元素!");
+ }else{
+ queArray[rear++] = o ;
+ }
+ }
+
+ public Object deQueue(){
+ if(isEmpty()){
+ throw new RuntimeException("空队列异常!");
+ }else{
+ Object obj = (Object) queArray[front];
+ queArray[front++] = null;
+ return obj;
+ }
+ }
+
+ //判空
+ public boolean isEmpty(){
+ return rear == front?true:false;
+ }
+
+ public int size(){
+ return rear-front;
+ }
+ */
+
+
+ /** 采用链表实现对队列;队列的特点是:先进先出,而且不能插队;所以只能从尾进,从头出。
+ *
+ * */
+ private LinkedList ll ;
+
+ public Queue(){
+ this.ll = new LinkedList();
+ }
+
+ public void enQueue(Object o){
+ ll.addLast(o);
+ }
+
+ public Object deQueue(){
+ return ll.removeLast();
+ }
+
+ public boolean isEmpty(){
+ return ll.getHead().next == null ? true: false;
+ }
+
+ public int size(){
+ return ll.size();
+ }
+}
\ No newline at end of file
diff --git a/group01/751425278/src/com/sanmubird/basicDataStructure/Stack.java b/group01/751425278/src/com/sanmubird/basicDataStructure/Stack.java
new file mode 100644
index 0000000000..7c6b03b3df
--- /dev/null
+++ b/group01/751425278/src/com/sanmubird/basicDataStructure/Stack.java
@@ -0,0 +1,50 @@
+package com.sanmubird.basicDataStructure;
+
+public class Stack {
+
+ private Object[] arrayStack ;//
+ private int maxSize ; //栈容量
+ private int top ; //栈指针;
+
+ public Stack(int initialSize){
+ if(initialSize >= 0 ){
+ this.arrayStack = new Object[initialSize];
+ this.maxSize = initialSize ;
+ this.top = -1 ;
+ }else{
+ throw new RuntimeException("初始化的大小不能小于0"+initialSize);
+ }
+ }
+
+ // 进栈,进栈的第一个元素的top = 0 ;
+ public void push(Object o){
+ if(top == maxSize -1 ){
+ throw new RuntimeException("栈已满,无法将元素插入栈");
+ }else{
+ arrayStack[++top] = o ;
+ }
+ }
+
+ public Object pop(){
+ if(top == -1){
+ throw new RuntimeException("栈为空!");
+ }else{
+ return arrayStack[top--];
+ }
+ }
+
+// 查看栈顶元素,但是不移除
+ public Object peek(){
+ if(top == -1){
+ throw new RuntimeException("栈为空!");
+ }else{
+ return arrayStack[top];
+ }
+ }
+ public boolean isEmpty(){
+ return top == -1 ? true : false;
+ }
+ public int size(){
+ return arrayStack.length;
+ }
+}
\ No newline at end of file
diff --git a/group01/765324639/src/zavier/week01/basic/ArrayList.java b/group01/765324639/src/zavier/week01/basic/ArrayList.java
new file mode 100644
index 0000000000..38e5739fb8
--- /dev/null
+++ b/group01/765324639/src/zavier/week01/basic/ArrayList.java
@@ -0,0 +1,85 @@
+package zavier.week01.basic;
+
+import java.util.Arrays;
+
+public class ArrayList implements List {
+
+ private int size = 0;
+
+ private Object[] elementData = new Object[100];
+
+ @Override
+ public void add(Object o) {
+ ensureCapacity(size + 1);
+ elementData[size++] = o;
+ }
+
+ private void ensureCapacity(int size) {
+ if (size > elementData.length) {
+ grow();
+ }
+ }
+
+ private void grow() {
+ elementData = Arrays.copyOf(elementData, size * 2);
+ }
+
+ @Override
+ public void add(int index, Object o) {
+ rangeCheckForAdd(index);
+ ensureCapacity(size + 1);
+ System.arraycopy(elementData, index, elementData, index + 1, size - index);
+ elementData[index] = o;
+ size++;
+ }
+
+ private void rangeCheckForAdd(int index) {
+ if (index < 0 || index > size) {
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+ @Override
+ public Object get(int index) {
+ rangeCheck(index);
+ return elementData[index];
+ }
+
+ private void rangeCheck(int index) {
+ if (index >= size || index < 0) {
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+ @Override
+ public Object remove(int index) {
+ rangeCheck(index);
+ Object dest = elementData[index];
+ System.arraycopy(elementData, index + 1, elementData, index, size - index - 1);
+ size--;
+ return dest;
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ public Iterator iterator() {
+ return new Iterator() {
+
+ private int index = 0;
+
+ @Override
+ public Object next() {
+ return elementData[index++];
+ }
+
+ @Override
+ public boolean hasNext() {
+ return index < size;
+ }
+ };
+ }
+
+}
diff --git a/group01/765324639/src/zavier/week01/basic/BinaryTreeNode.java b/group01/765324639/src/zavier/week01/basic/BinaryTreeNode.java
new file mode 100644
index 0000000000..6ef26e8f9a
--- /dev/null
+++ b/group01/765324639/src/zavier/week01/basic/BinaryTreeNode.java
@@ -0,0 +1,63 @@
+package zavier.week01.basic;
+
+public class BinaryTreeNode {
+
+ private Integer data;
+ private BinaryTreeNode left;
+ private BinaryTreeNode right;
+
+ public BinaryTreeNode(Integer data) {
+ this.data = data;
+ }
+
+ public Integer 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 > this.data) {
+
+ if (this.getRight() == null) {
+ BinaryTreeNode node = new BinaryTreeNode(o);
+ this.setRight(node);
+ return node;
+ } else {
+ return this.getRight().insert(o);
+ }
+
+ } else {
+
+ if (this.getLeft() == null) {
+ BinaryTreeNode node = new BinaryTreeNode(o);
+ this.setLeft(node);
+ return node;
+ } else {
+ return this.getLeft().insert(o);
+ }
+
+ }
+
+ }
+
+}
diff --git a/group01/765324639/src/zavier/week01/basic/Iterator.java b/group01/765324639/src/zavier/week01/basic/Iterator.java
new file mode 100644
index 0000000000..664983e0fd
--- /dev/null
+++ b/group01/765324639/src/zavier/week01/basic/Iterator.java
@@ -0,0 +1,8 @@
+package zavier.week01.basic;
+
+public interface Iterator {
+ public boolean hasNext();
+
+ public Object next();
+
+}
diff --git a/group01/765324639/src/zavier/week01/basic/LinkedList.java b/group01/765324639/src/zavier/week01/basic/LinkedList.java
new file mode 100644
index 0000000000..c876b48f1b
--- /dev/null
+++ b/group01/765324639/src/zavier/week01/basic/LinkedList.java
@@ -0,0 +1,148 @@
+package zavier.week01.basic;
+
+import java.util.NoSuchElementException;
+
+public class LinkedList implements List {
+
+ private Node head;
+
+ private int size = 0;
+
+ @Override
+ public void add(Object o) {
+ if (head == null) {
+ head = new Node(o);
+ } else {
+ Node tail = head;
+ while (tail.next != null) {
+ tail = tail.next;
+ }
+ Node node = new Node(o);
+
+ tail.next = node;
+ }
+ size++;
+ }
+
+ @Override
+ public void add(int index, Object o) {
+ rangeCheckForAdd(index);
+ if (index == 0) {
+ Node node = new Node(o);
+ node.next = head;
+ head = node;
+ } else {
+ Node preDest = head;
+ for (int i = 0; i < index - 1; i++) {
+ preDest = preDest.next;
+ }
+ Node node = new Node(o);
+ node.next = preDest.next;
+ preDest.next = node;
+ }
+
+ size++;
+ }
+
+ private void rangeCheckForAdd(int index) {
+ if (index > size || index < 0) {
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+ @Override
+ public Object get(int index) {
+ rangeCheck(index);
+
+ Node dest = head;
+ for (int i = 0; i < index; i++) {
+ dest = dest.next;
+ }
+ return dest.data;
+ }
+
+ private void rangeCheck(int index) {
+ if (index >= size || index < 0) {
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+ @Override
+ public Object remove(int index) {
+ rangeCheck(index);
+
+ Node preDest = head;
+ for (int i = 0; i < index - 1; i++) {
+ preDest = preDest.next;
+ }
+ Node dest = preDest.next;
+ preDest.next = dest.next;
+
+ size--;
+ return dest.data;
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ public void addFirst(Object o) {
+ Node node = new Node(o);
+ node.next = head;
+ head = node;
+ size++;
+ }
+
+ public void addLast(Object o) {
+ Node lastNode = head;
+ while (lastNode.next != null) {
+ lastNode = lastNode.next;
+ }
+
+ Node node = new Node(o);
+ lastNode.next = node;
+ size++;
+ }
+
+ public Object removeFirst() {
+ if (head == null) {
+ throw new NoSuchElementException();
+ }
+ Node target = head;
+ head = head.next;
+ size--;
+ return target.data;
+ }
+
+ public Object removeLast() {
+ if (head == null) {
+ throw new NoSuchElementException();
+ }
+
+ Node preDest = head;
+ while (preDest.next.next != null) {
+ preDest = preDest.next;
+ }
+ Node dest = preDest.next;
+ preDest.next = null;
+
+ size--;
+ return dest.data;
+ }
+
+ public Iterator iterator() {
+ return null;
+ }
+
+
+ private static class Node {
+ Object data;
+ Node next;
+
+ Node(Object data) {
+ this.data = data;
+ next = null;
+ }
+ }
+}
diff --git a/group01/765324639/src/zavier/week01/basic/List.java b/group01/765324639/src/zavier/week01/basic/List.java
new file mode 100644
index 0000000000..4f2d49bd73
--- /dev/null
+++ b/group01/765324639/src/zavier/week01/basic/List.java
@@ -0,0 +1,13 @@
+package zavier.week01.basic;
+
+public interface List {
+ public void add(Object o);
+
+ public void add(int index, Object o);
+
+ public Object get(int index);
+
+ public Object remove(int index);
+
+ public int size();
+}
diff --git a/group01/765324639/src/zavier/week01/basic/Queue.java b/group01/765324639/src/zavier/week01/basic/Queue.java
new file mode 100644
index 0000000000..5a212d46c1
--- /dev/null
+++ b/group01/765324639/src/zavier/week01/basic/Queue.java
@@ -0,0 +1,25 @@
+package zavier.week01.basic;
+
+public class Queue {
+
+ private LinkedList list = new LinkedList();
+
+ public void enQueue(Object o) {
+ list.add(o);
+ }
+
+ public Object deQueue() {
+ if (list.size() == 0) {
+ return null;
+ }
+ return list.removeFirst();
+ }
+
+ public boolean isEmpty() {
+ return list.size() == 0;
+ }
+
+ public int size() {
+ return list.size();
+ }
+}
diff --git a/group01/765324639/src/zavier/week01/basic/Stack.java b/group01/765324639/src/zavier/week01/basic/Stack.java
new file mode 100644
index 0000000000..ebe4afb19f
--- /dev/null
+++ b/group01/765324639/src/zavier/week01/basic/Stack.java
@@ -0,0 +1,33 @@
+package zavier.week01.basic;
+
+import java.util.EmptyStackException;
+
+public class Stack {
+ private ArrayList elementData = new ArrayList();
+
+ public void push(Object o) {
+ elementData.add(o);
+ }
+
+ public Object pop() {
+ if (elementData.size() == 0) {
+ throw new EmptyStackException();
+ }
+ return elementData.remove(elementData.size() - 1);
+ }
+
+ public Object peek() {
+ if (elementData.size() == 0) {
+ throw new EmptyStackException();
+ }
+ return elementData.get(elementData.size() - 1);
+ }
+
+ public boolean isEmpty() {
+ return elementData.size() == 0;
+ }
+
+ public int size() {
+ return elementData.size();
+ }
+}
diff --git a/group01/765324639/src/zavier/week01/test/AllTests.java b/group01/765324639/src/zavier/week01/test/AllTests.java
new file mode 100644
index 0000000000..c1755f6803
--- /dev/null
+++ b/group01/765324639/src/zavier/week01/test/AllTests.java
@@ -0,0 +1,12 @@
+package zavier.week01.test;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+@RunWith(Suite.class)
+@SuiteClasses({ArrayListTest.class, LinkedListTest.class, QueueTest.class, StackTest.class,
+ BinaryTreeNodeTest.class})
+public class AllTests {
+
+}
diff --git a/group01/765324639/src/zavier/week01/test/ArrayListTest.java b/group01/765324639/src/zavier/week01/test/ArrayListTest.java
new file mode 100644
index 0000000000..6a475500df
--- /dev/null
+++ b/group01/765324639/src/zavier/week01/test/ArrayListTest.java
@@ -0,0 +1,91 @@
+package zavier.week01.test;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import zavier.week01.basic.ArrayList;
+import zavier.week01.basic.Iterator;
+
+public class ArrayListTest {
+
+ private ArrayList arrayList = new ArrayList();
+
+ @Before
+ public void setUp() {
+ for (int i = 0; i < 500; i++) {
+ arrayList.add(i);
+ }
+ }
+
+ @Test
+ public void testAddObject() {
+ for (int i = 0; i < 500; i++) {
+ arrayList.add(i);
+ }
+ }
+
+ @Test
+ public void testAddIntObject() {
+ arrayList.add(100, -100);
+ Assert.assertEquals(-100, arrayList.get(100));
+ Assert.assertEquals(100, arrayList.get(101));
+ Assert.assertEquals(501, arrayList.size());
+ }
+
+ @Test(expected = IndexOutOfBoundsException.class)
+ public void testAddIllegalIntObject() {
+ arrayList.add(1000, 5);
+ }
+
+ @Test(expected = IndexOutOfBoundsException.class)
+ public void testAddNegativeIntObject() {
+ arrayList.add(-1, 5);
+ }
+
+ @Test
+ public void testGet() {
+ for (int i = 0; i < 500; i++) {
+ Assert.assertEquals(i, ((Integer) arrayList.get(i)).intValue());
+ }
+ }
+
+ @Test(expected = IndexOutOfBoundsException.class)
+ public void testIllegalGet() {
+ arrayList.get(500);
+ }
+
+ @Test(expected = IndexOutOfBoundsException.class)
+ public void testNegativeGet() {
+ arrayList.get(-10);
+ }
+
+ @Test
+ public void testRemove() {
+ Assert.assertEquals(100, arrayList.remove(100));
+ Assert.assertEquals(101, arrayList.get(100));
+ Assert.assertEquals(499, arrayList.size());
+ }
+
+ @Test(expected = IndexOutOfBoundsException.class)
+ public void testIllegalRemove() {
+ arrayList.remove(500);
+ }
+
+ @Test
+ public void testSize() {
+ Assert.assertEquals(500, arrayList.size());
+ }
+
+ @Test
+ public void testIterator() {
+ Iterator iterator = arrayList.iterator();
+ int i = 0;
+ while (iterator.hasNext()) {
+ Assert.assertEquals(i, iterator.next());
+ i++;
+ }
+ Assert.assertEquals(500, i);
+ }
+
+}
diff --git a/group01/765324639/src/zavier/week01/test/BinaryTreeNodeTest.java b/group01/765324639/src/zavier/week01/test/BinaryTreeNodeTest.java
new file mode 100644
index 0000000000..30a096a350
--- /dev/null
+++ b/group01/765324639/src/zavier/week01/test/BinaryTreeNodeTest.java
@@ -0,0 +1,33 @@
+package zavier.week01.test;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import zavier.week01.basic.BinaryTreeNode;
+
+public class BinaryTreeNodeTest {
+
+ private BinaryTreeNode root = new BinaryTreeNode(5);
+
+ @Test
+ public void testInsert() {
+ root.insert(2);
+ root.insert(7);
+ root.insert(1);
+ root.insert(6);
+
+ Assert.assertEquals((Integer) 5, root.getData());
+ Assert.assertEquals((Integer) 2, root.getLeft().getData());
+ Assert.assertEquals((Integer) 1, root.getLeft().getLeft().getData());
+ Assert.assertEquals(null, root.getLeft().getRight());
+ Assert.assertEquals((Integer) 7, root.getRight().getData());
+ Assert.assertEquals((Integer) 6, root.getRight().getLeft().getData());
+ Assert.assertEquals(null, root.getRight().getRight());
+
+ root.insert(4);
+ root.insert(8);
+ Assert.assertEquals((Integer) 4, root.getLeft().getRight().getData());
+ Assert.assertEquals((Integer) 8, root.getRight().getRight().getData());
+ }
+
+}
diff --git a/group01/765324639/src/zavier/week01/test/LinkedListTest.java b/group01/765324639/src/zavier/week01/test/LinkedListTest.java
new file mode 100644
index 0000000000..de7436a350
--- /dev/null
+++ b/group01/765324639/src/zavier/week01/test/LinkedListTest.java
@@ -0,0 +1,109 @@
+package zavier.week01.test;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import zavier.week01.basic.LinkedList;
+
+
+public class LinkedListTest {
+
+ private LinkedList linkedList = new LinkedList();
+
+ @Before
+ public void setUp() {
+ for (int i = 0; i < 500; i++) {
+ linkedList.add(i);
+ }
+ }
+
+ @Test
+ public void testAddObject() {
+ for (int i = 0; i < 100; i++) {
+ linkedList.add(i);
+ }
+ Assert.assertEquals(600, linkedList.size());
+ }
+
+ @Test
+ public void testAddIntObject() {
+ linkedList.add(100, -100);
+ Assert.assertEquals(-100, linkedList.get(100));
+ Assert.assertEquals(100, linkedList.get(101));
+ }
+
+ @Test(expected = IndexOutOfBoundsException.class)
+ public void testAddIllegalIntObject() {
+ linkedList.add(1000, 10);
+ }
+
+ @Test(expected = IndexOutOfBoundsException.class)
+ public void testAddNegativeIntObject() {
+ linkedList.add(-10, 10);
+ }
+
+ @Test
+ public void testGet() {
+ for (int i = 0; i < 500; i++) {
+ Assert.assertEquals(i, ((Integer) linkedList.get(i)).intValue());
+ }
+ }
+
+ @Test(expected = IndexOutOfBoundsException.class)
+ public void testIllegalGet() {
+ linkedList.get(500);
+ }
+
+ @Test(expected = IndexOutOfBoundsException.class)
+ public void testNegativeGet() {
+ linkedList.get(-10);
+ }
+
+ @Test
+ public void testRemove() {
+ Assert.assertEquals(100, linkedList.remove(100));
+ Assert.assertEquals(101, linkedList.get(100));
+ Assert.assertEquals(499, linkedList.size());
+ }
+
+ @Test
+ public void testSize() {
+ Assert.assertEquals(500, linkedList.size());
+ linkedList.add(10);
+ Assert.assertEquals(501, linkedList.size());
+ }
+
+ @Test
+ public void testAddFirst() {
+ linkedList.addFirst(-10);
+ Assert.assertEquals(-10, linkedList.get(0));
+ linkedList.addFirst(-100);
+ Assert.assertEquals(-100, linkedList.get(0));
+ Assert.assertEquals(-10, linkedList.get(1));
+ }
+
+ @Test
+ public void testAddLast() {
+ linkedList.addLast(-9);
+ Assert.assertEquals(-9, linkedList.get(linkedList.size() - 1));
+ linkedList.addLast(-8);
+ Assert.assertEquals(-8, linkedList.get(linkedList.size() - 1));
+ Assert.assertEquals(-9, linkedList.get(linkedList.size() - 2));
+ }
+
+ @Test
+ public void testRemoveFirst() {
+ Assert.assertEquals(0, linkedList.removeFirst());
+ Assert.assertEquals(1, linkedList.removeFirst());
+ Assert.assertEquals(498, linkedList.size());
+ }
+
+ @Test
+ public void testRemoveLast() {
+ Assert.assertEquals(499, linkedList.removeLast());
+ Assert.assertEquals(498, linkedList.removeLast());
+ Assert.assertEquals(498, linkedList.size());
+ }
+
+}
diff --git a/group01/765324639/src/zavier/week01/test/QueueTest.java b/group01/765324639/src/zavier/week01/test/QueueTest.java
new file mode 100644
index 0000000000..99d6466c8a
--- /dev/null
+++ b/group01/765324639/src/zavier/week01/test/QueueTest.java
@@ -0,0 +1,49 @@
+package zavier.week01.test;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import zavier.week01.basic.Queue;
+
+public class QueueTest {
+
+ private Queue queue = new Queue();
+
+ @Before
+ public void setUp() {
+ for (int i = 0; i < 500; i++) {
+ queue.enQueue(i);
+ }
+ }
+
+ @Test
+ public void testEnQueue() {
+ for (int i = 0; i < 100; i++) {
+ queue.enQueue(i);
+ }
+ Assert.assertEquals(600, queue.size());
+ }
+
+ @Test
+ public void testDeQueue() {
+ for (int i = 0; i < 500; i++) {
+ Assert.assertEquals(i, queue.deQueue());
+ }
+ Assert.assertNull(queue.deQueue());
+ Assert.assertNull(queue.deQueue());
+ }
+
+ @Test
+ public void testIsEmpty() {
+ Assert.assertFalse(queue.isEmpty());
+ Queue q = new Queue();
+ Assert.assertTrue(q.isEmpty());
+ }
+
+ @Test
+ public void testSize() {
+ Assert.assertEquals(500, queue.size());
+ }
+
+}
diff --git a/group01/765324639/src/zavier/week01/test/StackTest.java b/group01/765324639/src/zavier/week01/test/StackTest.java
new file mode 100644
index 0000000000..8138f97d3d
--- /dev/null
+++ b/group01/765324639/src/zavier/week01/test/StackTest.java
@@ -0,0 +1,60 @@
+package zavier.week01.test;
+
+import java.util.EmptyStackException;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import zavier.week01.basic.Stack;
+
+
+public class StackTest {
+
+ private Stack stack = new Stack();
+
+ @Before
+ public void setUp() {
+ for (int i = 0; i < 500; i++) {
+ stack.push(i);
+ }
+ }
+
+ @Test
+ public void testPush() {
+ for (int i = 0; i < 100; i++) {
+ stack.push(i);
+ }
+ Assert.assertEquals(600, stack.size());
+ }
+
+ @Test(expected = EmptyStackException.class)
+ public void testPop() {
+ for (int i = 0; i < 500; i++) {
+ Assert.assertEquals(499 - i, stack.pop());
+ }
+ stack.pop();
+ }
+
+ @Test
+ public void testPeek() {
+ Assert.assertEquals(499, stack.peek());
+ Assert.assertEquals(499, stack.peek());
+ stack.pop();
+ Assert.assertEquals(498, stack.peek());
+ }
+
+ @Test
+ public void testIsEmpty() {
+ Assert.assertFalse(stack.isEmpty());
+ Assert.assertTrue(new Stack().isEmpty());
+ }
+
+ @Test
+ public void testSize() {
+ Assert.assertEquals(500, stack.size());
+ stack.pop();
+ Assert.assertEquals(499, stack.size());
+ }
+
+}
diff --git a/group01/819048836/lvxg2017/src/basic/BinaryTree.java b/group01/819048836/lvxg2017/src/basic/BinaryTree.java
new file mode 100644
index 0000000000..f966389ea5
--- /dev/null
+++ b/group01/819048836/lvxg2017/src/basic/BinaryTree.java
@@ -0,0 +1,41 @@
+package basic;
+
+public class BinaryTree {
+ private BinaryTreeNode root;//根节点
+
+ //插入操作
+ public void insert(int value){
+ BinaryTreeNode newNode = new BinaryTreeNode(value);
+ if(root==null){
+ root = newNode;
+ root.setLeft(null);
+ root.setRight(null);
+ }else{
+ BinaryTreeNode currentNode = root;
+ BinaryTreeNode parentNode;
+ while(true)
+ {
+ parentNode = currentNode;
+ //往右放
+ if(newNode.getData()>currentNode.getData()){
+ currentNode = currentNode.getRight();
+ if(currentNode ==null){
+ parentNode.setRight(newNode);
+ return;
+ }
+ }else if(newNode.getData()<=currentNode.getData()){
+ currentNode = currentNode.getLeft();
+ if(currentNode ==null){
+ parentNode.setLeft(newNode);
+ return;
+ }
+ }
+
+ }
+
+ }
+
+
+ }
+
+}
diff --git a/group01/819048836/lvxg2017/src/basic/BinaryTreeNode.java b/group01/819048836/lvxg2017/src/basic/BinaryTreeNode.java
new file mode 100644
index 0000000000..7f984b6131
--- /dev/null
+++ b/group01/819048836/lvxg2017/src/basic/BinaryTreeNode.java
@@ -0,0 +1,34 @@
+package basic;
+
+//������
+public class BinaryTreeNode {
+ private int data;//节点值
+ private BinaryTreeNode left; //左子节点
+ private BinaryTreeNode right;//右子节点
+ public BinaryTreeNode(int data){
+ this.data =data;
+ this.left = null;
+ this.right = null;
+ }
+ public void setDate(int data){
+ this.data =data;
+ }
+ public int getData(){
+ return data;
+ }
+ public BinaryTreeNode getLeft(){
+ return left;
+ }
+ public BinaryTreeNode getRight(){
+ return right;
+ }
+ public void setLeft(BinaryTreeNode left){
+ this.left = left;
+ }
+ public void setRight(BinaryTreeNode right){
+ this.right =right;
+ }
+
+
+
+}
diff --git a/group01/819048836/lvxg2017/src/basic/MyArrayList.java b/group01/819048836/lvxg2017/src/basic/MyArrayList.java
new file mode 100644
index 0000000000..064acf941e
--- /dev/null
+++ b/group01/819048836/lvxg2017/src/basic/MyArrayList.java
@@ -0,0 +1,88 @@
+package basic;
+/**
+ *
+ *
+ * @author lvxg
+ *
+ */
+public class MyArrayList {
+ private Object[] element;
+ private int size;
+ private static final Object[] EMPTY = new Object[10];
+
+ public MyArrayList() {
+ this.element = EMPTY;
+ }
+
+ public boolean add(Object o) {
+ if (size < element.length) {
+ element[size] = o;
+ size++;
+ } else {
+ //数组扩容
+ grow();
+ element[size] = o;
+ size++;
+ }
+ return true;
+ }
+
+ //根据索引添加
+ public boolean add(int index, Object o) {
+ rangeCheckForAdd(index);
+ if (size < element.length + 1) {
+ Object[] e = new Object[element.length+1];
+ System.arraycopy(element, 0, e, 0, index);
+ e[index] = o;
+ System.arraycopy(element, index, e, index + 1, element.length-index);
+ element = e;
+ size++;
+ }
+ return true;
+ }
+
+ public Object get(int index) {
+ rangeCheck(index);
+ return element[index];
+ }
+
+ public Object remove(int index) {
+ rangeCheck(index);
+ Object oldValue = element[index];
+ int numMoved = size - index-1;
+ if(numMoved>0){
+ System.arraycopy(element, index+1, element, index, numMoved);
+ }
+ element[--size] =null;
+ return oldValue;
+ }
+ public int size() {
+ return size;
+ }
+ private void rangeCheck(int index) {
+ if (index >= size)
+ throw new IndexOutOfBoundsException();
+ }
+ private void rangeCheckForAdd(int index) {
+ if (index > size || index < 0) {
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+ //数组扩容方法
+ private void grow() {
+ Object[] e = new Object[size * 2];
+ System.arraycopy(element, 0, e, 0, element.length);
+ element = e;
+
+ }
+
+ public static void main(String[] args) {
+ MyArrayList m = new MyArrayList();
+ for (int i = 0; i < 10; i++) {
+ m.add(i);
+ }
+ m.add(2, "123");
+ }
+
+}
diff --git a/group01/819048836/lvxg2017/src/basic/MyLinkedList.java b/group01/819048836/lvxg2017/src/basic/MyLinkedList.java
new file mode 100644
index 0000000000..c79c0e1b81
--- /dev/null
+++ b/group01/819048836/lvxg2017/src/basic/MyLinkedList.java
@@ -0,0 +1,168 @@
+package basic;
+
+
+
+/**
+ * 链表
+ *
+ * @author lvxg
+ *
+ */
+public class MyLinkedList {
+ // 头节点
+ private Node first;
+ // 尾节点
+ private Node last;
+ // 链表长度
+ private int size = 0;
+
+ public boolean add(Object o) {
+ linklast(o);
+ return true;
+ }
+ /**
+ * 根据索引添加节点
+ * @param index
+ * @param o
+ */
+ public void add(int index, Object o) {
+ checkPositionIndex(index);
+ if (index == size) {
+ linklast(o);
+ } else {
+ final Node succ = node(index);
+ final Node pred = succ.prev;
+ Node newNode = new Node(o, pred, succ);
+ if (pred == null) {
+ first = newNode;
+ } else {
+ pred.next = newNode;
+ }
+ size++;
+ }
+ }
+ //根据索引删除节点
+ private Object remove(int index){
+ Object x= unllink(node(index));
+ return x;
+ }
+ private Object remove(){
+ Object x = unllink(node(size));
+ return x;
+ }
+ @SuppressWarnings("unused")
+ private Object get(int index)
+ {
+ Node f = first;
+ for (int i = 0; i < index; i++) {
+ f = f.next;
+ }
+ return f.data;
+ }
+ @SuppressWarnings("unused")
+ private int size(){
+ return size;
+ }
+ @SuppressWarnings("unused")
+ private void addFirst(Object o){
+ Node f= first;
+ Node newNode = new Node(o, f, null);
+ f.prev = newNode;
+ first = newNode;
+ }
+ @SuppressWarnings("unused")
+ private void addLast(Object o){
+ Node l = last;
+ Node newNode = new Node(o, null, l);
+ l.next = newNode;
+ last = newNode;
+ }
+ public Object removeFirst(){
+ return null;
+ }
+ public Object removeLast(){
+ return null;
+ }
+
+ private void linklast(Object e) {
+ final Node l = last;
+ final Node newNode = new Node(e, null, l);
+ last = newNode;
+ if (l == null) {
+ first = newNode;
+ } else {
+ l.next = newNode;
+ }
+ size++;
+
+ }
+
+ private Object unllink(Node x) {
+ final Object element = x.data;
+ final Node next = x.next;
+ final Node prev = x.prev;
+ if (prev == null) {
+ first = next;
+ } else {
+ prev.next = next;
+ x.next = null;
+ x.prev = null;
+ }
+ if (next == null) {
+ last = prev;
+ x.next = null;
+ }
+ size--;
+ x.data = null;
+ return element;
+ }
+
+ private Node node(int index) {
+ if (index < (size >> 1)) {
+ Node x = first;
+ for (int i = 0; i < index; i++) {
+ x = x.next;
+ }
+ return x;
+ } else {
+ Node x = last;
+ for (int i = size - 1; i > index; i--) {
+ x = x.prev;
+ }
+ return x;
+ }
+ }
+
+ private static class Node {
+ Object data; // 节点值
+ Node next;// 后继节点
+ Node prev;// 前驱节点
+
+ public Node(Object o, Node n, Node p) {
+ this.data = o;
+ this.prev = p;
+ this.next = n;
+ }
+ }
+
+ private void checkPositionIndex(int index) {
+ if (!isPositionIndex(index)) {
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+ private boolean isPositionIndex(int index) {
+ return index >= 0 && index <= size;
+ }
+
+ public static void main(String[] args) {
+ MyLinkedList l = new MyLinkedList();
+ l.add("1");
+ l.add("2");
+ l.add("3");
+ l.add(2, "4");
+ l.remove();
+ l.remove(1);
+ }
+
+}
diff --git a/group01/819048836/lvxg2017/src/basic/Queue.java b/group01/819048836/lvxg2017/src/basic/Queue.java
new file mode 100644
index 0000000000..e29bf6fa4f
--- /dev/null
+++ b/group01/819048836/lvxg2017/src/basic/Queue.java
@@ -0,0 +1,43 @@
+package basic;
+
+public class Queue {
+ private Node first;
+ private Node last;
+ private int size = 0;
+
+ //入列
+ @SuppressWarnings("unused")
+ private void enQueue(Object o) {
+ final Node f = first;
+ final Node newNode = new Node(o, f, null);
+ f.prev = newNode;
+ }
+ public int size(){
+ return size;
+ }
+public boolean isEmpty(){
+ return size>=0;
+}
+ // 出列
+ @SuppressWarnings("unused")
+ private Object deQueue() {
+ final Node l = last;
+ final Node p = l.prev;
+ last = p;
+ p.next = null;
+ return l;
+ }
+
+ private static class Node {
+ Object data;
+ Node next;
+ Node prev;
+
+ public Node(Object o, Node n, Node p) {
+ this.data = o;
+ this.prev = p;
+ this.next = n;
+ }
+ }
+
+}
diff --git a/group01/819048836/lvxg2017/src/basic/Stack.java b/group01/819048836/lvxg2017/src/basic/Stack.java
new file mode 100644
index 0000000000..916eac298a
--- /dev/null
+++ b/group01/819048836/lvxg2017/src/basic/Stack.java
@@ -0,0 +1,58 @@
+package basic;
+
+//ջ
+public class Stack {
+ private Node first;
+ private Node last;
+ private int size = 0;
+
+ // 出栈
+ private void pop() {
+ removeLast();
+ }
+
+ // 入栈
+ private void push(Object o) {
+ addLast(o);
+ }
+ private boolean isEmpty(){
+ if(size==0){
+ return true;
+ }else{
+ return false;
+ }
+ }
+ private int size(){
+ return size;
+ }
+ private void removeLast(){
+ final Node f = last.prev;
+ last = f;
+ f.next =null;
+ }
+
+
+ private void addLast(Object o){
+ final Node f= first;
+ final Node l = last;
+ final Node newNode = new Node(o, last, null);
+ if(f==null){
+ first =newNode;
+ }else{
+ l.next = newNode;
+ }
+ size++;
+ }
+
+ private static class Node {
+ Object data;
+ Node next;
+ Node prev;
+
+ public Node(Object o, Node n, Node p) {
+ this.data = o;
+ this.prev = p;
+ this.next = n;
+ }
+ }
+}
diff --git a/group01/895457260/code/src/datastructure/basic/ArrayList.java b/group01/895457260/code/src/datastructure/basic/ArrayList.java
new file mode 100644
index 0000000000..28eb439c1b
--- /dev/null
+++ b/group01/895457260/code/src/datastructure/basic/ArrayList.java
@@ -0,0 +1,136 @@
+package datastructure.basic;
+
+public class ArrayList implements List {
+
+ private int size = 0;
+
+ private Object[] elementData;
+
+ public ArrayList() {
+ elementData = new Object[100];
+ }
+
+ public ArrayList(int initCapacity) {
+ elementData = new Object[initCapacity];
+ }
+
+ public void add(Object o) {
+ autoGrow();
+ elementData[size()] = o;
+ size++;
+ }
+
+ public void add(int index, Object o) {
+ autoGrow();
+ System.arraycopy(elementData, index, elementData, index + 1, size() - index);
+ elementData[index] = o;
+ size++;
+ }
+
+ public Object get(int index) {
+ checkIndex(index);
+ return elementData[index];
+ }
+
+ public Object remove(int index) {
+ checkIndex(index);
+ Object removed = elementData[index];
+ System.arraycopy(elementData, index + 1, elementData, index, size() - index - 1);
+ size--;
+ return removed;
+ }
+
+ public int size() {
+ return size;
+ }
+
+ public Iterator iterator() {
+ return new Iterator() {
+ int index = -1;
+ @Override
+ public boolean hasNext() {
+ return index + 1 < size();
+ }
+
+ @Override
+ public Object next() {
+ index++;
+ return elementData[index];
+ }
+ };
+ }
+
+ private void autoGrow() {
+ if (size >= elementData.length) {
+ Object[] newArray = new Object[nextCapacity()];
+ System.arraycopy(elementData, 0, newArray, 0, elementData.length);
+ elementData = newArray;
+ }
+ }
+
+ private int nextCapacity() {
+ return elementData.length * 2;
+ }
+
+ private void checkIndex(int index) {
+ if (index >= size() || index < 0) {
+ throw new IndexOutOfBoundsException(indexOutOfBoundMessage(index));
+ }
+ }
+
+ private String indexOutOfBoundMessage(int index) {
+ return "index: " + index + ", size: " + size();
+ }
+
+ public static void main(String[] args) {
+ ArrayList list = new ArrayList();
+ for (int i = 0; i < 10; ++i) {
+ list.add(i);
+ list.add(10 - i);
+ }
+ System.out.println("------------------size");
+ System.out.println("size: " + list.size());
+
+ System.out.println("------------------for(int i)");
+ for (int i = 0; i < list.size(); ++i) {
+ System.out.print(list.get(i) + " ");
+ }
+
+ System.out.println("\n-----------------iterator");
+ Iterator iterator = list.iterator();
+ while (iterator.hasNext()) {
+ System.out.print(iterator.next() + " ");
+ }
+
+ System.out.println("\n-----------------add at index 0 100~104");
+ for (int i = 100; i < 105; ++i) {
+ list.add(0, i);
+ }
+ list.print();
+ System.out.println("-----------------add at last 200~204");
+ for (int i = 200; i < 205; ++i) {
+ list.add(list.size(), i);
+ }
+ list.print();
+
+ System.out.println("-----------------removeFirst x4");
+ for (int i = 0; i < 4; ++i) {
+ list.remove(0);
+ }
+ list.print();
+
+ System.out.println("\n-----------------removeLast x4");
+ for (int i = 0; i < 4; ++i) {
+ list.remove(list.size() - 1);
+ }
+ list.print();
+ }
+
+ public void print() {
+ Iterator iterator = iterator();
+ while (iterator.hasNext()) {
+ System.out.print(iterator.next() + " ");
+ }
+ System.out.println("\nsize: " + size());
+ }
+}
diff --git a/group01/895457260/code/src/datastructure/basic/BinarySortedTree.java b/group01/895457260/code/src/datastructure/basic/BinarySortedTree.java
new file mode 100644
index 0000000000..b251ff02ee
--- /dev/null
+++ b/group01/895457260/code/src/datastructure/basic/BinarySortedTree.java
@@ -0,0 +1,61 @@
+package datastructure.basic;
+
+/**
+ * Created by Haochen on 2017/2/24.
+ * TODO:
+ */
+public class BinarySortedTree {
+
+ private BinaryTreeNode root = null;
+
+ public void traverse(Visitor visitor) {
+ traverse(root, visitor);
+ }
+
+ private void traverse(BinaryTreeNode node, Visitor visitor) {
+ if (node == null) {
+ return;
+ }
+ traverse(node.getLeft(), visitor);
+ visitor.visit(node);
+ traverse(node.getRight(), visitor);
+ }
+
+ public interface Visitor {
+ void visit(BinaryTreeNode node);
+ }
+
+ //不递归的写法
+ public void add(T o) {
+ //根节点空,直接加入
+ if (root == null) {
+ root = new BinaryTreeNode();
+ root.setData(o);
+ } else {
+ BinaryTreeNode target = root;
+ //从根结点不断向下比较target和o,o小则往左,o大则往右,相等不加入
+ while (true) {
+ int compare = o.compareTo(target.getData());
+ if (compare == 0) {//相等不加入
+ return;
+ } else if (compare < 0) {//o小往左
+ if (target.getLeft() == null) {//左空则加入
+ target.setLeft(new BinaryTreeNode());
+ target.getLeft().setData(o);
+ return;
+ } else {//不空继续比较
+ target = target.getLeft();
+ }
+ } else {//o大往右
+ if (target.getRight() == null) {
+ target.setRight(new BinaryTreeNode());
+ target.getRight().setData(o);
+ return;
+ } else {
+ target = target.getRight();
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/group01/895457260/code/src/datastructure/basic/BinaryTreeNode.java b/group01/895457260/code/src/datastructure/basic/BinaryTreeNode.java
new file mode 100644
index 0000000000..d3a9ff377b
--- /dev/null
+++ b/group01/895457260/code/src/datastructure/basic/BinaryTreeNode.java
@@ -0,0 +1,32 @@
+package datastructure.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/895457260/code/src/datastructure/basic/Iterator.java b/group01/895457260/code/src/datastructure/basic/Iterator.java
new file mode 100644
index 0000000000..c1fb7ae8a5
--- /dev/null
+++ b/group01/895457260/code/src/datastructure/basic/Iterator.java
@@ -0,0 +1,6 @@
+package datastructure.basic;
+
+public interface Iterator {
+ boolean hasNext();
+ Object next();
+}
diff --git a/group01/895457260/code/src/datastructure/basic/LinkedList.java b/group01/895457260/code/src/datastructure/basic/LinkedList.java
new file mode 100644
index 0000000000..174044c546
--- /dev/null
+++ b/group01/895457260/code/src/datastructure/basic/LinkedList.java
@@ -0,0 +1,132 @@
+package datastructure.basic;
+
+import datastructure.exception.EmptyListException;
+
+public class LinkedList implements List {
+
+ private Node head;
+ private int size;
+
+ public LinkedList() {
+ head = new Node();
+ }
+
+ @Override
+ public void add(Object o) {
+ addLast(o);
+ }
+
+ @Override
+ public void add(int index , Object o) {
+ Node pre = findNode(index - 1);
+ Node node = new Node();
+ node.data = o;
+ addNode(node, pre);
+ }
+
+ @Override
+ public Object get(int index) {
+ checkIndex(index);
+ return findNode(index).data;
+ }
+
+ @Override
+ public Object remove(int index) {
+ checkIndex(index);
+ Node pre = findNode(index - 1);
+ Node removed = pre.next;
+ removeNode(removed, pre);
+ return removed.data;
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ public void addFirst(Object o) {
+ Node node = new Node();
+ node.data = o;
+ addNode(node, head);
+ }
+
+ public void addLast(Object o) {
+ Node node = new Node();
+ node.data = o;
+ Node pre = findNode(size() - 1);
+ addNode(node, pre);
+ }
+
+ public Object removeFirst() {
+ if (size() == 0) {
+ throw new EmptyListException();
+ }
+ Node removed = head.next;
+ removeNode(head.next, head);
+ return removed.data;
+ }
+
+ public Object removeLast() {
+ if (size() == 0) {
+ throw new EmptyListException();
+ }
+ return remove(size() - 1);
+ }
+
+ @Override
+ public Iterator iterator() {
+ return new Iterator() {
+ Node node = head;
+ @Override
+ public boolean hasNext() {
+ return node.next != null;
+ }
+
+ @Override
+ public Object next() {
+ node = node.next;
+ return node.data;
+ }
+ };
+ }
+
+ private static class Node{
+ Object data;
+ Node next;
+ }
+
+ private Node findNode(int index) {
+ if (index == -1) {
+ return head;
+ } else {
+ checkIndex(index);
+ }
+ Node node = head.next;
+ for (int i = 0; i < index; ++i) {
+ node = node.next;
+ }
+ return node;
+ }
+
+ private void checkIndex(int index) {
+ if (index >= size() || index < 0) {
+ throw new IndexOutOfBoundsException(indexOutOfBoundMessage(index));
+ }
+ }
+
+ private String indexOutOfBoundMessage(int index) {
+ return "index: " + index + ", size: " + size();
+ }
+
+ private void addNode(Node node, Node pre) {
+ node.next = pre.next;
+ pre.next = node;
+ size++;
+ }
+
+ private void removeNode(Node node, Node pre) {
+ pre.next = node.next;
+ node.next = null;
+ size--;
+ }
+}
diff --git a/group01/895457260/code/src/datastructure/basic/List.java b/group01/895457260/code/src/datastructure/basic/List.java
new file mode 100644
index 0000000000..2f085701c5
--- /dev/null
+++ b/group01/895457260/code/src/datastructure/basic/List.java
@@ -0,0 +1,10 @@
+package datastructure.basic;
+
+public interface List {
+ void add(Object o);
+ void add(int index, Object o);
+ Object get(int index);
+ Object remove(int index);
+ int size();
+ Iterator iterator();
+}
diff --git a/group01/895457260/code/src/datastructure/basic/Queue.java b/group01/895457260/code/src/datastructure/basic/Queue.java
new file mode 100644
index 0000000000..edd0a6a29e
--- /dev/null
+++ b/group01/895457260/code/src/datastructure/basic/Queue.java
@@ -0,0 +1,68 @@
+package datastructure.basic;
+
+import datastructure.exception.EmptyQueueException;
+
+public class Queue {
+ //数组实现自增长的循环队列
+ private Object[] array;
+ private int head = 0;
+ private int rear = 0;
+
+ public Queue() {
+ this.array = new Object[10];
+ }
+
+ public Queue(int initCapacity) {
+ this.array = new Object[initCapacity];
+ }
+
+ public void enQueue(Object o) {
+ int target = mapIndex(rear);
+ autoGrow();
+ array[target] = o;
+ rear++;
+ }
+
+ public Object deQueue() {
+ if (isEmpty()) {
+ throw new EmptyQueueException();
+ }
+ Object obj = array[mapIndex(head)];
+ head++;
+ return obj;
+ }
+
+ public boolean isEmpty() {
+ return head == rear;
+ }
+
+ public int size() {
+ return rear - head;
+ }
+
+ private int capacity() {
+ return array.length;
+ }
+
+ private void autoGrow() {
+ if (size() >= capacity()) {
+ Object[] newArray = new Object[nextCapacity()];
+ System.arraycopy(array, 0, newArray, 0, capacity());
+
+ int increase = nextCapacity() - capacity();
+ int moveCount = size() - mapIndex(rear);
+ System.arraycopy(newArray, mapIndex(head), newArray, mapIndex(head) + increase, moveCount);
+ array = newArray;
+ head += increase;
+ rear += increase;
+ }
+ }
+
+ private int nextCapacity() {
+ return capacity() * 2;
+ }
+
+ private int mapIndex(int index) {
+ return index >= capacity() ? index % capacity() : index;
+ }
+}
diff --git a/group01/895457260/code/src/datastructure/basic/Stack.java b/group01/895457260/code/src/datastructure/basic/Stack.java
new file mode 100644
index 0000000000..ab4fc874ae
--- /dev/null
+++ b/group01/895457260/code/src/datastructure/basic/Stack.java
@@ -0,0 +1,32 @@
+package datastructure.basic;
+
+import java.util.EmptyStackException;
+
+public class Stack {
+ private ArrayList elementData = new ArrayList();
+
+ public void push(Object o) {
+ elementData.add(o);
+ }
+
+ public Object pop() {
+ if (isEmpty()) {
+ throw new EmptyStackException();
+ }
+ Object peek = peek();
+ elementData.remove(elementData.size() - 1);
+ return peek;
+ }
+
+ public Object peek() {
+ return elementData.get(elementData.size() - 1);
+ }
+
+ public boolean isEmpty() {
+ return size() == 0;
+ }
+
+ public int size() {
+ return elementData.size();
+ }
+}
diff --git a/group01/895457260/code/src/datastructure/exception/EmptyListException.java b/group01/895457260/code/src/datastructure/exception/EmptyListException.java
new file mode 100644
index 0000000000..6f38ed6c43
--- /dev/null
+++ b/group01/895457260/code/src/datastructure/exception/EmptyListException.java
@@ -0,0 +1,8 @@
+package datastructure.exception;
+
+/**
+ * Created by Haochen on 2017/2/24.
+ * TODO:
+ */
+public class EmptyListException extends RuntimeException {
+}
diff --git a/group01/895457260/code/src/datastructure/exception/EmptyQueueException.java b/group01/895457260/code/src/datastructure/exception/EmptyQueueException.java
new file mode 100644
index 0000000000..071a366ed8
--- /dev/null
+++ b/group01/895457260/code/src/datastructure/exception/EmptyQueueException.java
@@ -0,0 +1,7 @@
+package datastructure.exception;
+
+/**
+ * Created by Haochen on 2017/2/24.
+ * TODO:
+ */
+public class EmptyQueueException extends RuntimeException {}
diff --git a/group01/895457260/code/src/test/datastructure/basic/ArrayListTest.java b/group01/895457260/code/src/test/datastructure/basic/ArrayListTest.java
new file mode 100644
index 0000000000..42b9144d38
--- /dev/null
+++ b/group01/895457260/code/src/test/datastructure/basic/ArrayListTest.java
@@ -0,0 +1,152 @@
+package test.datastructure.basic;
+
+import datastructure.basic.ArrayList;
+import datastructure.basic.Iterator;
+import datastructure.basic.List;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+
+/**
+ * ArrayList Tester.
+ *
+ * @author
+ * @version 1.0
+ * @since 二月 24, 2017
+ */
+public class ArrayListTest {
+
+ @Before
+ public void before() throws Exception {
+ }
+
+ @After
+ public void after() throws Exception {
+ }
+
+ protected final List getList() {
+ List list = createList();
+ init(list);
+ return list;
+ }
+
+ List createList() {
+ return new ArrayList(5);
+ }
+
+ private void init(List list) {
+ for (int i = 1; i <= 5; ++i) {
+ list.add(i);
+ }
+ }
+
+ protected final Object[] toArray(List list) {
+ Object[] array = new Object[list.size()];
+ Iterator iterator = list.iterator();
+ int pos = 0;
+ while (iterator.hasNext()) {
+ array[pos++] = iterator.next();
+ }
+ return array;
+ }
+
+ /**
+ * Method: add(Object o)
+ */
+ @Test
+ public void testAddO() throws Exception {
+//TODO: Test goes here...
+ List list = getList();
+ for (int i = 6; i <= 10; ++i) {
+ list.add(i);
+ }
+ Assert.assertArrayEquals(toArray(list), new Object[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
+ Assert.assertEquals(list.size(), 10);
+ }
+
+ /**
+ * Method: add(int index, Object o)
+ */
+ @Test
+ public void testAddForIndexO() throws Exception {
+//TODO: Test goes here...
+ List list = getList();
+ int nowSize = list.size();
+ int[] indexes = {nowSize + 1, -1, nowSize, nowSize, 0, 1};
+ Object[] values = {0, 0, 300, 400, 100, 200};
+ boolean[] exceptions = new boolean[indexes.length];
+ for (int i = 0; i < indexes.length; ++i) {
+ try {
+ list.add(indexes[i], values[i]);
+ } catch (IndexOutOfBoundsException e) {
+ exceptions[i] = true;
+ }
+ }
+ Assert.assertArrayEquals(toArray(list), new Object[]{100, 200, 1, 2, 3, 4, 5, 400, 300});
+ Assert.assertArrayEquals(exceptions, new boolean[]{true, true, false, false, false, false});
+ Assert.assertEquals(list.size(), nowSize + 4);
+ }
+
+ /**
+ * Method: get(int index)
+ */
+ @Test
+ public void testGet() throws Exception {
+//TODO: Test goes here...
+ List list = getList();
+ int nowSize = list.size();
+ int[] indexes = {-1, nowSize, 0, 1, nowSize - 1, nowSize - 2};
+ Object[] values = new Object[indexes.length];
+ boolean[] exceptions = new boolean[indexes.length];
+ for (int i = 0; i < indexes.length; ++i) {
+ try {
+ values[i] = list.get(indexes[i]);
+ } catch (IndexOutOfBoundsException e) {
+ exceptions[i] = true;
+ }
+ }
+ Assert.assertArrayEquals(values, new Object[]{null, null, 1, 2, 5, 4});
+ Assert.assertArrayEquals(exceptions, new boolean[]{true, true, false, false, false, false});
+ Assert.assertEquals(list.size(), nowSize);
+ }
+
+ /**
+ * Method: remove(int index)
+ */
+ @Test
+ public void testRemove() throws Exception {
+//TODO: Test goes here...
+ List list = getList();
+ int nowSize = list.size();
+ int[] indexes = {-1, nowSize, nowSize - 2, nowSize - 2, 1, 0};
+ Object[] values = new Object[indexes.length];
+ boolean[] exceptions = new boolean[indexes.length];
+ for (int i = 0; i < indexes.length; ++i) {
+ try {
+ values[i] = list.remove(indexes[i]);
+ } catch (IndexOutOfBoundsException e) {
+ exceptions[i] = true;
+ }
+ }
+ Assert.assertArrayEquals(values, new Object[]{null, null, 4, 5, 2, 1});
+ Assert.assertArrayEquals(exceptions, new boolean[]{true, true, false, false, false, false});
+ Assert.assertEquals(list.size(), nowSize - 4);
+ }
+
+ /**
+ * Method: iterator()
+ */
+ @Test
+ public void testIterator() throws Exception {
+//TODO: Test goes here...
+ List list = getList();
+ Iterator iterator = list.iterator();
+ Object[] values = new Object[list.size()];
+ int pos = 0;
+ while (iterator.hasNext()) {
+ values[pos++] = iterator.next();
+ }
+ Assert.assertArrayEquals(values, new Object[]{1, 2, 3, 4, 5});
+ }
+}
diff --git a/group01/895457260/code/src/test/datastructure/basic/BinarySortedTreeTest.java b/group01/895457260/code/src/test/datastructure/basic/BinarySortedTreeTest.java
new file mode 100644
index 0000000000..ce15d5622c
--- /dev/null
+++ b/group01/895457260/code/src/test/datastructure/basic/BinarySortedTreeTest.java
@@ -0,0 +1,60 @@
+package test.datastructure.basic;
+
+import datastructure.basic.BinarySortedTree;
+import datastructure.basic.BinaryTreeNode;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+
+/**
+ * BinarySortedTree Tester.
+ *
+ * @author
+ * @version 1.0
+ * @since 二月 24, 2017
+ */
+public class BinarySortedTreeTest {
+
+ @Before
+ public void before() throws Exception {
+ }
+
+ @After
+ public void after() throws Exception {
+ }
+
+ private BinarySortedTree getTree() {
+ return new BinarySortedTree<>();
+ }
+
+ /**
+ * Method: add(T o)
+ */
+ @Test
+ public void testAdd() throws Exception {
+//TODO: Test goes here...
+ BinarySortedTree tree = getTree();
+ int[] addValues = {5, 3, 1, 7, 6, 4, 8};
+ for (int i : addValues) {
+ tree.add(i);
+ }
+
+ final Object[] left = new Object[addValues.length];
+ final Object[] value = new Object[addValues.length];
+ final Object[] right = new Object[addValues.length];
+ tree.traverse(new BinarySortedTree.Visitor() {
+ int pos = 0;
+ @Override
+ public void visit(BinaryTreeNode node) {
+ left[pos] = node.getLeft() == null ? null : (int) node.getLeft().getData();
+ value[pos] = node.getData();
+ right[pos] = node.getRight() == null ? null : (int) node.getRight().getData();
+ pos++;
+ }
+ });
+ Assert.assertArrayEquals(left, new Object[]{null, 1, null, 3, null, 6, null});
+ Assert.assertArrayEquals(value, new Object[]{1, 3, 4, 5, 6, 7, 8});
+ Assert.assertArrayEquals(right, new Object[]{null, 4, null, 7, null, 8, null});
+ }
+}
diff --git a/group01/895457260/code/src/test/datastructure/basic/LinkedListTest.java b/group01/895457260/code/src/test/datastructure/basic/LinkedListTest.java
new file mode 100644
index 0000000000..0ab03eb589
--- /dev/null
+++ b/group01/895457260/code/src/test/datastructure/basic/LinkedListTest.java
@@ -0,0 +1,88 @@
+package test.datastructure.basic;
+
+import datastructure.exception.EmptyListException;
+import datastructure.basic.LinkedList;
+import datastructure.basic.List;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * LinkedList Tester.
+ *
+ * @author
+ * @version 1.0
+ * @since 二月 24, 2017
+ */
+public class LinkedListTest extends ArrayListTest {
+
+ @Override
+ List createList() {
+ return new LinkedList();
+ }
+
+ /**
+ * Method: addFirst(Object o)
+ */
+ @Test
+ public void testAddFirst() throws Exception {
+//TODO: Test goes here...
+ LinkedList list = (LinkedList) getList();
+ list.addFirst(100);
+ Assert.assertArrayEquals(toArray(list), new Object[]{100, 1, 2, 3, 4, 5});
+ }
+
+ /**
+ * Method: addLast(Object o)
+ */
+ @Test
+ public void testAddLast() throws Exception {
+//TODO: Test goes here...
+ LinkedList list = (LinkedList) getList();
+ list.addLast(100);
+ Assert.assertArrayEquals(toArray(list), new Object[]{1, 2, 3, 4, 5, 100});
+ }
+
+ /**
+ * Method: removeFirst()
+ */
+ @Test
+ public void testRemoveFirst() throws Exception {
+//TODO: Test goes here...
+ LinkedList list = (LinkedList) getList();
+ int count = list.size() + 2;
+ Object[] values = new Object[count];
+ boolean[] exceptions = new boolean[count];
+ for (int i = 0; i < count; ++i) {
+ try {
+ values[i] = list.removeFirst();
+ } catch (EmptyListException e) {
+ exceptions[i] = true;
+ }
+ }
+ Assert.assertArrayEquals(values, new Object[]{1, 2, 3, 4, 5, null, null});
+ Assert.assertArrayEquals(exceptions, new boolean[]{false, false, false, false, false, true, true});
+ Assert.assertArrayEquals(toArray(list), new Object[0]);
+ }
+
+ /**
+ * Method: removeLast()
+ */
+ @Test
+ public void testRemoveLast() throws Exception {
+//TODO: Test goes here...
+ LinkedList list = (LinkedList) getList();
+ int count = list.size() + 2;
+ Object[] values = new Object[count];
+ boolean[] exceptions = new boolean[count];
+ for (int i = 0; i < count; ++i) {
+ try {
+ values[i] = list.removeLast();
+ } catch (EmptyListException e) {
+ exceptions[i] = true;
+ }
+ }
+ Assert.assertArrayEquals(values, new Object[]{5, 4, 3, 2, 1, null, null});
+ Assert.assertArrayEquals(exceptions, new boolean[]{false, false, false, false, false, true, true});
+ Assert.assertArrayEquals(toArray(list), new Object[0]);
+ }
+}
diff --git a/group01/895457260/code/src/test/datastructure/basic/QueueTest.java b/group01/895457260/code/src/test/datastructure/basic/QueueTest.java
new file mode 100644
index 0000000000..df7587bd3c
--- /dev/null
+++ b/group01/895457260/code/src/test/datastructure/basic/QueueTest.java
@@ -0,0 +1,108 @@
+package test.datastructure.basic;
+
+import datastructure.exception.EmptyQueueException;
+import datastructure.basic.Queue;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * Queue Tester.
+ *
+ * @author
+ * @version 1.0
+ * @since 二月 24, 2017
+ */
+public class QueueTest {
+
+ @Before
+ public void before() throws Exception {
+ }
+
+ @After
+ public void after() throws Exception {
+ }
+
+ private Queue getQueue() {
+ Queue queue = new Queue(5);
+ for (int i = 1; i <= 5; ++i) {
+ queue.enQueue(i);
+ }
+ return queue;
+ }
+
+ private void assertQueue(Queue queue, Object[] actual) {
+ Class clazz = Queue.class;
+ Object[] array = null;
+ int head = 0;
+ int rear = 0;
+ Method mapIndex = null;
+ try {
+ Field arrayField = clazz.getDeclaredField("array");
+ Field headField = clazz.getDeclaredField("head");
+ Field rearField = clazz.getDeclaredField("rear");
+ mapIndex = clazz.getDeclaredMethod("mapIndex", int.class);
+ arrayField.setAccessible(true);
+ headField.setAccessible(true);
+ rearField.setAccessible(true);
+ mapIndex.setAccessible(true);
+ array = (Object[]) arrayField.get(queue);
+ head = (int) headField.get(queue);
+ rear = (int) rearField.get(queue);
+ } catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException e) {
+ e.printStackTrace();
+ }
+ int size = queue.size();
+ Object[] excepted = new Object[size];
+ int pos = 0;
+ try {
+ while (head < rear) {
+ excepted[pos++] = array[(int) mapIndex.invoke(queue, head)];
+ head++;
+ }
+ } catch (IllegalAccessException | InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ Assert.assertArrayEquals(excepted, actual);
+ }
+
+ /**
+ * Method: enQueue(Object o)
+ */
+ @Test
+ public void testEnQueue() throws Exception {
+//TODO: Test goes here...
+ Queue queue = getQueue();
+ for (int i = 6; i <= 10; ++i) {
+ queue.enQueue(i);
+ }
+ assertQueue(queue, new Object[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
+ }
+
+ /**
+ * Method: deQueue()
+ */
+ @Test
+ public void testDeQueue() throws Exception {
+//TODO: Test goes here...
+ Queue queue = getQueue();
+ int count = queue.size() + 2;
+ Object[] values = new Object[count];
+ boolean[] exceptions = new boolean[count];
+ for (int i = 0; i < count; ++i) {
+ try {
+ values[i] = queue.deQueue();
+ } catch (EmptyQueueException e) {
+ exceptions[i] = true;
+ }
+ }
+ Assert.assertArrayEquals(values, new Object[]{1, 2, 3, 4, 5, null, null});
+ Assert.assertArrayEquals(exceptions, new boolean[]{false, false, false, false, false, true, true});
+ assertQueue(queue, new Object[0]);
+ }
+}
diff --git a/group01/895457260/code/src/test/datastructure/basic/StackTest.java b/group01/895457260/code/src/test/datastructure/basic/StackTest.java
new file mode 100644
index 0000000000..ac2bd31a22
--- /dev/null
+++ b/group01/895457260/code/src/test/datastructure/basic/StackTest.java
@@ -0,0 +1,93 @@
+package test.datastructure.basic;
+
+import datastructure.basic.*;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+
+import java.lang.reflect.Field;
+import java.util.EmptyStackException;
+
+/**
+ * Stack Tester.
+ *
+ * @author
+ * @version 1.0
+ * @since 二月 24, 2017
+ */
+public class StackTest {
+
+ @Before
+ public void before() throws Exception {
+ }
+
+ @After
+ public void after() throws Exception {
+ }
+
+ private Stack getStack() {
+ Stack stack = new Stack();
+ for (int i = 1; i <= 5; ++i) {
+ stack.push(i);
+ }
+ return stack;
+ }
+
+ private void assertStack(Stack stack, Object[] actual) {
+ Class clazz = Stack.class;
+ ArrayList elementData = null;
+ try {
+ Field field = clazz.getDeclaredField("elementData");
+ field.setAccessible(true);
+ elementData = (ArrayList) field.get(stack);
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+ e.printStackTrace();
+ }
+
+ Object[] excepted = null;
+ if (elementData != null) {
+ int size = stack.size();
+ excepted = new Object[size];
+ for (int i = 0; i < size; ++i) {
+ excepted[i] = elementData.get(i);
+ }
+ }
+ Assert.assertArrayEquals(excepted, actual);
+ }
+
+ /**
+ * Method: push(Object o)
+ */
+ @Test
+ public void testPush() throws Exception {
+//TODO: Test goes here...
+ Stack stack = getStack();
+ for (int i = 6; i <= 10; ++i) {
+ stack.push(i);
+ }
+ assertStack(stack, new Object[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
+ }
+
+ /**
+ * Method: pop()
+ */
+ @Test
+ public void testPop() throws Exception {
+//TODO: Test goes here...
+ Stack stack = getStack();
+ int count = stack.size() + 2;
+ Object[] values = new Object[count];
+ boolean[] exceptions = new boolean[count];
+ for (int i = 0; i < count; ++i) {
+ try {
+ values[i] = stack.pop();
+ } catch (EmptyStackException e) {
+ exceptions[i] = true;
+ }
+ }
+ Assert.assertArrayEquals(values, new Object[]{5, 4, 3, 2, 1, null, null});
+ Assert.assertArrayEquals(exceptions, new boolean[]{false, false, false, false, false, true, true});
+ assertStack(stack, new Object[0]);
+ }
+}
diff --git a/group01/895457260/code/src/test/datastructure/basic/TestSuite.java b/group01/895457260/code/src/test/datastructure/basic/TestSuite.java
new file mode 100644
index 0000000000..f7c5868383
--- /dev/null
+++ b/group01/895457260/code/src/test/datastructure/basic/TestSuite.java
@@ -0,0 +1,13 @@
+package test.datastructure.basic;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Created by Haochen on 2017/2/24.
+ * TODO:
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({ArrayListTest.class, LinkedListTest.class,
+ BinarySortedTreeTest.class, QueueTest.class, StackTest.class})
+public class TestSuite {}
diff --git a/group01/932573198/20170220/.classpath b/group01/932573198/20170220/.classpath
new file mode 100644
index 0000000000..b387714202
--- /dev/null
+++ b/group01/932573198/20170220/.classpath
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/group01/932573198/20170220/.gitignore b/group01/932573198/20170220/.gitignore
new file mode 100644
index 0000000000..65776c32fc
--- /dev/null
+++ b/group01/932573198/20170220/.gitignore
@@ -0,0 +1 @@
+/bin/
\ No newline at end of file
diff --git a/group01/932573198/20170220/.project b/group01/932573198/20170220/.project
new file mode 100644
index 0000000000..82b0a5ccfd
--- /dev/null
+++ b/group01/932573198/20170220/.project
@@ -0,0 +1,17 @@
+
+
+ 20170220
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/liuxin/.settings/org.eclipse.jdt.core.prefs b/group01/932573198/20170220/.settings/org.eclipse.jdt.core.prefs
similarity index 100%
rename from liuxin/.settings/org.eclipse.jdt.core.prefs
rename to group01/932573198/20170220/.settings/org.eclipse.jdt.core.prefs
diff --git a/group01/932573198/20170220/src/com/coding/basic/ArrayList.java b/group01/932573198/20170220/src/com/coding/basic/ArrayList.java
new file mode 100644
index 0000000000..039e83f095
--- /dev/null
+++ b/group01/932573198/20170220/src/com/coding/basic/ArrayList.java
@@ -0,0 +1,92 @@
+package com.coding.basic;
+
+import java.util.Arrays;
+
+public class ArrayList implements List {
+
+ private int size = 0;
+
+ private Object[] elementData = new Object[10];
+
+ /**
+ * 扩容
+ */
+ private void expansion() {
+ if (elementData.length <= size)
+ elementData = Arrays.copyOf(elementData, elementData.length * 3 / 2 + 1);
+ }
+
+ /**
+ * 越界
+ */
+ private void outOfBoundsForAdd(int index) {
+ if (index > size || index < 0)
+ throw new IndexOutOfBoundsException("数组下标越界");
+ }
+
+ private void outOfBoundsForOther(int index) {
+ if (index >= size || index < 0)
+ throw new IndexOutOfBoundsException("数组下标越界");
+ }
+
+ public void add(Object o) {
+ expansion();
+ elementData[size++] = o;
+ }
+
+ public void add(int index, Object o) {
+ outOfBoundsForAdd(index);
+ expansion();
+ for (int i = size - 1; i >= index; i--) {
+ elementData[i + 1] = elementData[i];
+ }
+ elementData[index] = o;
+ size++;
+ }
+
+ public Object get(int index) {
+ outOfBoundsForOther(index);
+ return elementData[index];
+ }
+
+ public Object remove(int index) {
+ outOfBoundsForOther(index);
+ Object re = elementData[index];
+ for (int i = index; i < size - 1; i++) {
+ elementData[i] = elementData[i + 1];
+ }
+ elementData[size - 1] = null;
+ size--;
+ return re;
+ }
+
+ public int size() {
+ return size;
+ }
+
+ @Override
+ public String toString() {
+ return Arrays.toString(elementData);
+ }
+
+ public Iterator iterator() {
+ return new ArrayIterator();
+ }
+
+ private class ArrayIterator implements Iterator {
+
+ int pos = -1;
+
+ @Override
+ public boolean hasNext() {
+ return size > ++pos ? true : false;
+ }
+
+ @Override
+ public Object next() {
+ return elementData[pos];
+ }
+
+ }
+
+}
diff --git a/group01/932573198/20170220/src/com/coding/basic/BinaryTree.java b/group01/932573198/20170220/src/com/coding/basic/BinaryTree.java
new file mode 100644
index 0000000000..730d7e7b3a
--- /dev/null
+++ b/group01/932573198/20170220/src/com/coding/basic/BinaryTree.java
@@ -0,0 +1,77 @@
+package com.coding.basic;
+
+public class BinaryTree {
+
+ private BinaryTreeNode tNode;
+
+ @Override
+ public String toString() {
+ return tNode + "";
+ }
+
+ public void insert(Object o) {
+ tNode = insert(o, tNode);
+ }
+
+ public BinaryTreeNode insert(Object o, BinaryTreeNode node) {
+ if (node == null) {
+ node = new BinaryTreeNode(o);
+ } else {
+ int result = o.toString().compareTo(node.getData().toString());
+ if (result < 0)
+ node.setLeft(insert(o, node.getLeft()));
+ if (result > 0)
+ node.setRight(insert(o, node.getRight()));
+ }
+ return node;
+ }
+
+ private static class BinaryTreeNode {
+
+ private BinaryTreeNode left;
+
+ private Object data;
+
+ private BinaryTreeNode right;
+
+ public BinaryTreeNode() {
+ }
+
+ public BinaryTreeNode(Object data) {
+ this.left = null;
+ this.data = data;
+ this.right = null;
+ }
+
+ public BinaryTreeNode getLeft() {
+ return left;
+ }
+
+ public void setLeft(BinaryTreeNode left) {
+ this.left = left;
+ }
+
+ public Object getData() {
+ return data;
+ }
+
+ public void setData(Object data) {
+ this.data = data;
+ }
+
+ public BinaryTreeNode getRight() {
+ return right;
+ }
+
+ public void setRight(BinaryTreeNode right) {
+ this.right = right;
+ }
+
+ @Override
+ public String toString() {
+ return "[" + left + ", " + data + ", " + right + "]";
+ }
+
+ }
+
+}
diff --git a/group01/932573198/20170220/src/com/coding/basic/Iterator.java b/group01/932573198/20170220/src/com/coding/basic/Iterator.java
new file mode 100644
index 0000000000..ff93e30377
--- /dev/null
+++ b/group01/932573198/20170220/src/com/coding/basic/Iterator.java
@@ -0,0 +1,6 @@
+package com.coding.basic;
+
+public interface Iterator {
+ public boolean hasNext();
+ public Object next();
+}
diff --git a/group01/932573198/20170220/src/com/coding/basic/LinkedList.java b/group01/932573198/20170220/src/com/coding/basic/LinkedList.java
new file mode 100644
index 0000000000..db61384e4c
--- /dev/null
+++ b/group01/932573198/20170220/src/com/coding/basic/LinkedList.java
@@ -0,0 +1,144 @@
+package com.coding.basic;
+
+import java.util.NoSuchElementException;
+
+public class LinkedList implements List {
+
+ private int size = 0;
+
+ private Node head;
+
+
+ public Node getHead() {
+ return head;
+ }
+
+ public LinkedList() {
+ this.head = new Node();
+ }
+
+ @Override
+ public String toString() {
+ return "[" + head + "]";
+ }
+
+ private void outOfBoundsForAdd(int index) {
+ if (index > size || index < 0)
+ throw new IndexOutOfBoundsException("数组下标越界");
+ }
+
+ private void outOfBoundsForOther(int index) {
+ if (index >= size || index < 0)
+ throw new IndexOutOfBoundsException("数组下标越界");
+ }
+
+ public void add(Object o) {
+ Node node = head;
+ while (node.next != null) {
+ node = node.next;
+ }
+ node.next = new Node(o);
+ size++;
+ }
+
+ public void add(int index, Object o) {
+ outOfBoundsForAdd(index);
+ if(size == index)
+ add(o);
+ else{
+ Node prevNode = head;
+ for (int i = 0; i < index; i++) {
+ prevNode = prevNode.next;
+ }
+ Node nextNode = prevNode.next;
+ Node node = new Node(o);
+ prevNode.next = node;
+ node.next = nextNode;
+ size++;
+ }
+ }
+
+ public Object get(int index) {
+ outOfBoundsForOther(index);
+ Node node = head;
+ for (int i = 0; i <= index; i++) {
+ node = node.next;
+ }
+ return node.data;
+ }
+
+ public Object remove(int index) {
+ outOfBoundsForOther(index);
+ Node prevNode = head;
+ for (int i = 0; i < index; i++) {
+ prevNode = prevNode.next;
+ }
+ Node node = prevNode.next;
+ prevNode.next = node.next;
+ size--;
+ return node.data;
+ }
+
+ public int size() {
+ return size;
+ }
+
+ public void addFirst(Object o) {
+ Node newNode = new Node(o);
+ Node node = head.next;
+ head.next = newNode;
+ newNode.next = node;
+ size++;
+ }
+
+ public void addLast(Object o) {
+ Node node = head;
+ while (node.next != null) {
+ node = node.next;
+ }
+ node.next = new Node(o);
+ size++;
+ }
+
+ private void noSuchEle() {
+ if (head.next == null)
+ throw new NoSuchElementException("没有这个元素");
+ }
+
+ public Object removeFirst() {
+ noSuchEle();
+ Node node = head.next;
+ head.next = node.next;
+ size--;
+ return node.data;
+ }
+
+ public Object removeLast() {
+ noSuchEle();
+ Node node = head;
+ for(int i=0;i
+
+ 4.0.0
+
+ com.aaront.execrise
+ coding2017
+ 1.0.0-SNAPSHOT
+ jar
+
+
+
+ UTF-8
+ 1.8
+
+
+
+
+ junit
+ junit
+ 4.12
+
+
+
\ No newline at end of file
diff --git a/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/basic/ArrayList.java b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/basic/ArrayList.java
new file mode 100644
index 0000000000..ae462ea905
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/basic/ArrayList.java
@@ -0,0 +1,90 @@
+package com.aaront.exercise.basic;
+
+import java.util.Arrays;
+
+public class ArrayList implements List {
+
+ private int size = 0;
+
+ private static final double factor = 0.75;
+
+ private Object[] elementData = new Object[100];
+
+ public void add(Object o) {
+ _ensureCapacityEnough();
+ elementData[size++] = o;
+ }
+
+ public void add(int index, Object o) {
+ if (index < 0 || index > size) throw new IndexOutOfBoundsException("index超出边界");
+ _ensureCapacityEnough();
+ int i = size;
+ for (; i > index; i--) {
+ elementData[i] = elementData[i - 1];
+ }
+ elementData[i] = o;
+ size++;
+ }
+
+ private void _ensureCapacityEnough() {
+ if (size >= elementData.length) {
+ dilatancy();
+ }
+ }
+
+ private void dilatancy() {
+ int newLength = elementData.length + (int) (elementData.length * factor);
+ elementData = Arrays.copyOf(elementData, newLength);
+ }
+
+ public Object get(int index) {
+ if(index < 0 || index >= size) throw new IndexOutOfBoundsException("index超出边界");
+ return elementData[index];
+ }
+
+ public Object remove(int index) {
+ if (index < 0 || index >= size) throw new IndexOutOfBoundsException("index超出边界");
+ Object element = elementData[index];
+ System.arraycopy(elementData, index + 1, elementData, index, size - 1 - index);
+ size--;
+ return element;
+
+ }
+
+ public int size() {
+ return size;
+ }
+
+ public Iterator iterator() {
+ return new ArrayListIterator(this);
+ }
+
+ public Object[] toArray() {
+ Object[] objects = new Object[size];
+ System.arraycopy(elementData, 0, objects, 0, size);
+ return objects;
+ }
+
+ private static class ArrayListIterator implements Iterator {
+
+ private ArrayList arrayList;
+ private int pos = 0;
+
+ private ArrayListIterator(ArrayList arrayList) {
+ this.arrayList = arrayList;
+ }
+
+ public boolean hasNext() {
+ return pos < arrayList.size();
+ }
+
+ public Object next() {
+ return arrayList.elementData[pos++];
+ }
+
+ public void remove() {
+ arrayList.remove(pos - 1);
+ pos--;
+ }
+ }
+}
diff --git a/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/basic/BinaryTree.java b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/basic/BinaryTree.java
new file mode 100644
index 0000000000..2c0d156561
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/basic/BinaryTree.java
@@ -0,0 +1,235 @@
+package com.aaront.exercise.basic;
+
+public class BinaryTree {
+
+ private BinaryTreeNode head = new BinaryTreeNode(null);
+ private BinaryTreeNode root;
+ private int size;
+ private int index = 0;
+
+ public static final int PREORDER = 0;
+ public static final int INORDER = 1;
+ public static final int POSTORDER = 2;
+ public static final int HIERARCHICAL = 3;
+
+ public static final int RECURSION = 10;
+ public static final int ITERATION = 11;
+
+ public void add(Integer o) {
+ BinaryTreeNode node = new BinaryTreeNode(o);
+ if (root == null) {
+ root = node;
+ head.setLeft(root);
+ } else {
+ insert(root, node);
+ }
+ size++;
+ }
+
+ private void insert(BinaryTreeNode node, BinaryTreeNode newNode) {
+ // 要插入的节点插入当前节点的左子树
+ if (node.getData() > newNode.getData()) {
+ if (node.getLeft() == null) {
+ node.setLeft(newNode);
+ } else {
+ insert(node.left, newNode);
+ }
+ } else { // 要插入的节点插入当前节点的右子树
+ if (node.getRight() == null) {
+ node.setRight(newNode);
+ } else {
+ insert(node.right, newNode);
+ }
+ }
+ }
+
+ public BinaryTreeNode search(int data) {
+ return search(data, ITERATION);
+ }
+
+ public BinaryTreeNode search(int data, int method) {
+ switch (method) {
+ case RECURSION:
+ return findNodeRecursion(root, data);
+ case ITERATION:
+ return findNodeIteration(data);
+ default:
+ throw new IllegalArgumentException("不支持的查找方法");
+ }
+ }
+
+ private BinaryTreeNode findNodeRecursion(BinaryTreeNode node, int data) {
+ if (node == null) return null;
+ if (node.getData() == data) return node;
+ if (node.getData() > data) return findNodeRecursion(node.getLeft(), data);
+ return findNodeRecursion(node.getRight(), data);
+ }
+
+ private BinaryTreeNode findNodeIteration(int data) {
+ BinaryTreeNode currentNode = root;
+ while (currentNode != null) {
+ if (currentNode.getData() == data) {
+ return currentNode;
+ }
+ if (currentNode.getData() > data) {
+ currentNode = currentNode.getLeft();
+ } else {
+ currentNode = currentNode.getRight();
+ }
+ }
+ return null;
+ }
+
+ public BinaryTreeNode min() {
+ return findMin(root);
+ }
+
+ private BinaryTreeNode findMin(BinaryTreeNode node) {
+ if (node == null) return null;
+ if (node.getLeft() == null) return node;
+ return findMin(node.getLeft());
+ }
+
+ public BinaryTreeNode max() {
+ return findMax(root);
+ }
+
+ private BinaryTreeNode findMax(BinaryTreeNode node) {
+ if (node == null) return null;
+ if (node.getRight() == null) return node;
+ return findMax(node.getRight());
+ }
+
+ public void delete(Integer data) {
+ BinaryTreeNode node = search(data);
+ if (node == null) return;
+ BinaryTreeNode parentNode = searchParentNode(node);
+ if (parentNode == null) return;
+ // 删除叶子节点
+ if (node.getLeft() == null && node.getRight() == null) {
+ if (parentNode.getLeft() == node) parentNode.setLeft(null);
+ else parentNode.setRight(null);
+ } else if (node.getLeft() != null && node.getRight() == null) { // 删除只有左子树的节点
+ if (parentNode.getLeft() == node) parentNode.setLeft(node.getLeft());
+ else parentNode.setRight(node.getLeft());
+ } else if (node.getRight() != null && node.getLeft() == null) { // 删除只有右子树的节点
+ if (parentNode.getLeft() == node) parentNode.setLeft(node.getRight());
+ else parentNode.setRight(node.getRight());
+ } else { // 删除有两个子树的节点
+ BinaryTreeNode replace = findMin(node.getRight());
+ BinaryTreeNode replaceParentNode = searchParentNode(replace);
+ replaceParentNode.setLeft(replace.getRight());
+ node.setData(replace.getData());
+ replace.setLeft(null);
+ replace.setRight(null);
+ }
+ size--;
+ }
+
+ private BinaryTreeNode searchParentNode(BinaryTreeNode node) {
+ if (node == null) return null;
+ if (node == root) return head;
+ BinaryTreeNode current = root;
+ while (current != null) {
+ if (current.getLeft() == node || current.getRight() == node) return current;
+ if (current.getData().compareTo(node.getData()) > 0) current = current.getLeft();
+ else current = current.getRight();
+ }
+ return null;
+ }
+
+ public int[] traversal() {
+ return traversal(PREORDER);
+ }
+
+ public int[] traversal(int order) {
+ int[] datas = new int[size];
+ if (order == PREORDER) {
+ preorderTraversal(root, datas);
+ } else if (order == INORDER) {
+ inorderTraversal(root, datas);
+ } else if (order == POSTORDER) {
+ postorderTraversal(root, datas);
+ } else {
+ hierarchicalTraversal(root, datas);
+ }
+ index = 0;
+ return datas;
+ }
+
+ private void preorderTraversal(BinaryTreeNode node, int[] datas) {
+ if (node == null) {
+ return;
+ }
+
+ datas[index++] = node.getData();
+ preorderTraversal(node.getLeft(), datas);
+ preorderTraversal(node.getRight(), datas);
+ }
+
+ private void inorderTraversal(BinaryTreeNode node, int[] datas) {
+ if (node == null) {
+ return;
+ }
+
+ inorderTraversal(node.getLeft(), datas);
+ datas[index++] = node.getData();
+ inorderTraversal(node.getRight(), datas);
+ }
+
+ private void postorderTraversal(BinaryTreeNode node, int[] datas) {
+ if (node == null) {
+ return;
+ }
+
+ postorderTraversal(node.getLeft(), datas);
+ postorderTraversal(node.getRight(), datas);
+ datas[index++] = node.getData();
+ }
+
+ private void hierarchicalTraversal(BinaryTreeNode node, int[] datas) {
+ if (node == null) return;
+ Queue queue = new Queue();
+ queue.enQueue(node);
+ while (!queue.isEmpty()) {
+ BinaryTreeNode tmp = (BinaryTreeNode) queue.deQueue();
+ datas[index++] = tmp.getData();
+ if (tmp.getLeft() != null) queue.enQueue(tmp.getLeft());
+ if (tmp.getRight() != null) queue.enQueue(tmp.getRight());
+ }
+ }
+
+ public class BinaryTreeNode {
+ private Integer data;
+ private BinaryTreeNode left;
+ private BinaryTreeNode right;
+
+ public BinaryTreeNode(Integer data) {
+ this.data = data;
+ }
+
+ public Integer 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;
+ }
+ }
+}
diff --git a/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/basic/Iterator.java b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/basic/Iterator.java
new file mode 100644
index 0000000000..e446dd8f65
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/basic/Iterator.java
@@ -0,0 +1,9 @@
+package com.aaront.exercise.basic;
+
+public interface Iterator {
+ boolean hasNext();
+
+ Object next();
+
+ void remove();
+}
diff --git a/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/basic/LinkedList.java b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/basic/LinkedList.java
new file mode 100644
index 0000000000..504e73580b
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/basic/LinkedList.java
@@ -0,0 +1,129 @@
+package com.aaront.exercise.basic;
+
+public class LinkedList implements List {
+
+ private Node head = new Node(null);
+ private int size = 0;
+
+ public void add(Object o) {
+ Node newNode = new Node(o);
+ Node first = head.next;
+ Node second = head;
+ while (first != null) {
+ second = first;
+ first = first.next;
+ }
+ second.next = newNode;
+ size++;
+ }
+
+ public void add(int index, Object o) {
+ if (index < 0 || index > size) throw new IndexOutOfBoundsException("索引超出范围");
+ Node first = head;
+ int i = 0;
+ while (i < index) {
+ first = first.next;
+ i++;
+ }
+ Node node = new Node(o);
+ node.next = first.next;
+ first.next = node;
+ size++;
+ }
+
+ public Object get(int index) {
+ if (index < 0 || index >= size) throw new IndexOutOfBoundsException("索引超出范围");
+ Node first = head.next;
+ int i = 0;
+ while (i < index) {
+ first = first.next;
+ i++;
+ }
+ return first.data;
+ }
+
+ public Object remove(int index) {
+ if (index < 0 || index >= size) throw new IndexOutOfBoundsException("索引超出范围");
+ Node first = head;
+ int i = 0;
+ while (i < index) {
+ first = first.next;
+ i++;
+ }
+ Node element = first.next;
+ first.next = first.next.next;
+ size--;
+ return element.data;
+ }
+
+ public int size() {
+ return size;
+ }
+
+ public void addFirst(Object o) {
+ add(0, o);
+ }
+
+ public void addLast(Object o) {
+ add(size, o);
+ }
+
+ public Object removeFirst() {
+ return remove(0);
+ }
+
+ public Object removeLast() {
+ return remove(size - 1);
+ }
+
+ public Iterator iterator() {
+ return new LinkedListIterator(this);
+ }
+
+ public Object[] toArray() {
+ Object[] objects = new Object[size];
+ Node first = head.next;
+ int pos = 0;
+ while (first!= null) {
+ objects[pos++] = first.data;
+ first = first.next;
+ }
+ return objects;
+ }
+
+ private static class LinkedListIterator implements Iterator {
+
+ private int pos = 0;
+ private LinkedList linkedList;
+
+ private LinkedListIterator(LinkedList linkList) {
+ this.linkedList = linkList;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return pos < linkedList.size();
+ }
+
+ @Override
+ public Object next() {
+ return linkedList.get(pos++);
+ }
+
+ @Override
+ public void remove() {
+ linkedList.remove(pos - 1);
+ pos--;
+ }
+ }
+
+
+ private static class Node {
+ private Object data;
+ private Node next;
+
+ private Node(Object data) {
+ this.data = data;
+ }
+ }
+}
diff --git a/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/basic/List.java b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/basic/List.java
new file mode 100644
index 0000000000..0988b60f4a
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/basic/List.java
@@ -0,0 +1,9 @@
+package com.aaront.exercise.basic;
+
+public interface List {
+ public void add(Object o);
+ public void add(int index, Object o);
+ public Object get(int index);
+ public Object remove(int index);
+ public int size();
+}
diff --git a/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/basic/Queue.java b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/basic/Queue.java
new file mode 100644
index 0000000000..7c310bca9e
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/basic/Queue.java
@@ -0,0 +1,26 @@
+package com.aaront.exercise.basic;
+
+public class Queue {
+
+ private LinkedList linkedList = new LinkedList();
+
+ public void enQueue(Object o) {
+ linkedList.add(o);
+ }
+
+ public Object deQueue() {
+ return linkedList.removeFirst();
+ }
+
+ public boolean isEmpty() {
+ return linkedList.size() == 0;
+ }
+
+ public int size() {
+ return linkedList.size();
+ }
+
+ public Object[] toArray() {
+ return linkedList.toArray();
+ }
+}
diff --git a/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/basic/Stack.java b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/basic/Stack.java
new file mode 100644
index 0000000000..450d21ee89
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/basic/Stack.java
@@ -0,0 +1,29 @@
+package com.aaront.exercise.basic;
+
+public class Stack {
+ private ArrayList elementData = new ArrayList();
+
+ public void push(Object o) {
+ elementData.add(o);
+ }
+
+ public Object pop() {
+ return elementData.remove(elementData.size() - 1);
+ }
+
+ public Object peek() {
+ return elementData.get(elementData.size() - 1);
+ }
+
+ public boolean isEmpty() {
+ return elementData.size() == 0;
+ }
+
+ public int size() {
+ return elementData.size();
+ }
+
+ public Object[] toArray() {
+ return elementData.toArray();
+ }
+}
diff --git a/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/generic/GenericArrayList.java b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/generic/GenericArrayList.java
new file mode 100644
index 0000000000..a099746b55
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/generic/GenericArrayList.java
@@ -0,0 +1,98 @@
+package com.aaront.exercise.generic;
+
+import java.util.Arrays;
+
+public class GenericArrayList implements GenericList {
+
+ private int size = 0;
+
+ private static final double factor = 0.75;
+
+ private Object[] elementData = new Object[100];
+
+ public void add(T o) {
+ _ensureCapacityEnough();
+ elementData[size++] = o;
+ }
+
+ public void add(int index, T o) {
+ if (index < 0 || index > size) throw new IndexOutOfBoundsException("index超出边界");
+ _ensureCapacityEnough();
+ int i = size;
+ for (; i > index; i--) {
+ elementData[i] = elementData[i - 1];
+ }
+ elementData[i] = o;
+ size++;
+ }
+
+ private void _ensureCapacityEnough() {
+ if (size >= elementData.length) {
+ dilatancy();
+ }
+ }
+
+ private void dilatancy() {
+ int newLength = elementData.length + (int) (elementData.length * factor);
+ elementData = Arrays.copyOf(elementData, newLength);
+ }
+
+ public T get(int index) {
+ if(index < 0 || index >= size) throw new IndexOutOfBoundsException("index超出边界");
+ return (T) elementData[index];
+ }
+
+ public T remove(int index) {
+ if (index < 0 || index >= size) throw new IndexOutOfBoundsException("index超出边界");
+ Object element = elementData[index];
+ System.arraycopy(elementData, index + 1, elementData, index, size - 1 - index);
+ size--;
+ return (T) element;
+
+ }
+
+ public int size() {
+ return size;
+ }
+
+ public GenericIterator iterator() {
+ return new ArrayListGenericIterator(this);
+ }
+
+ public Object[] toArray() {
+ Object[] objects = new Object[size];
+ System.arraycopy(elementData, 0, objects, 0, size);
+ return objects;
+ }
+
+ public T[] toArray(T[] a) {
+ if (a.length < size)
+ // Make a new array of a's runtime type, but my contents:
+ return (T[]) Arrays.copyOf(elementData, size, a.getClass());
+ System.arraycopy(elementData, 0, a, 0, size);
+ return a;
+ }
+
+ private static class ArrayListGenericIterator implements GenericIterator {
+
+ private GenericArrayList genericArrayList;
+ private int pos = 0;
+
+ private ArrayListGenericIterator(GenericArrayList genericArrayList) {
+ this.genericArrayList = genericArrayList;
+ }
+
+ public boolean hasNext() {
+ return pos < genericArrayList.size();
+ }
+
+ public T next() {
+ return (T) genericArrayList.elementData[pos++];
+ }
+
+ public void remove() {
+ genericArrayList.remove(pos - 1);
+ pos--;
+ }
+ }
+}
\ No newline at end of file
diff --git a/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/generic/GenericBinaryTree.java b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/generic/GenericBinaryTree.java
new file mode 100644
index 0000000000..e5cf3b439a
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/generic/GenericBinaryTree.java
@@ -0,0 +1,255 @@
+package com.aaront.exercise.generic;
+
+import java.util.Arrays;
+
+public class GenericBinaryTree> {
+
+ private BinaryTreeNode head = new BinaryTreeNode<>(null);
+ private BinaryTreeNode root;
+ private int size;
+ private int index = 0;
+ public static final int PREORDER = 0;
+ public static final int INORDER = 1;
+ public static final int POSTORDER = 2;
+ public static final int HIERARCHICAL = 3;
+
+ public static final int RECURSION = 10;
+ public static final int ITERATION = 11;
+
+ public void add(T o) {
+ BinaryTreeNode node = new BinaryTreeNode<>(o);
+ if (root == null) {
+ root = node;
+ head.setLeft(root);
+ } else {
+ insert(root, node);
+ }
+ size++;
+ }
+
+ private void insert(BinaryTreeNode node, BinaryTreeNode newNode) {
+ // 要插入的节点插入当前节点的左子树
+ if (node.getData().compareTo(newNode.getData()) > 0) {
+ if (node.getLeft() == null) {
+ node.setLeft(newNode);
+ } else {
+ insert(node.left, newNode);
+ }
+ } else { // 要插入的节点插入当前节点的右子树
+ if (node.getRight() == null) {
+ node.setRight(newNode);
+ } else {
+ insert(node.right, newNode);
+ }
+ }
+ }
+
+ public BinaryTreeNode search(T data) {
+ return search(data, ITERATION);
+ }
+
+ public BinaryTreeNode search(T data, int method) {
+ switch (method) {
+ case RECURSION:
+ return findNodeRecursion(root, data);
+ case ITERATION:
+ return findNodeIteration(data);
+ default:
+ throw new IllegalArgumentException("不支持的查找方法");
+ }
+ }
+
+ private BinaryTreeNode findNodeRecursion(BinaryTreeNode node, T data) {
+ if (node == null) return null;
+ if (node.getData().compareTo(data) == 0) return node;
+ if (node.getData().compareTo(data) > 0) return findNodeRecursion(node.getLeft(), data);
+ return findNodeRecursion(node.getRight(), data);
+ }
+
+ private BinaryTreeNode findNodeIteration(T data) {
+ BinaryTreeNode currentNode = root;
+ while (currentNode != null) {
+ if (currentNode.getData().compareTo(data) == 0) {
+ return currentNode;
+ }
+ if (currentNode.getData().compareTo(data) > 0) {
+ currentNode = currentNode.getLeft();
+ } else {
+ currentNode = currentNode.getRight();
+ }
+ }
+ return null;
+ }
+
+ public BinaryTreeNode min() {
+ return findMin(root);
+ }
+
+ private BinaryTreeNode findMin(BinaryTreeNode node) {
+ if (node == null) return null;
+ if (node.getLeft() == null) return node;
+ return findMin(node.getLeft());
+ }
+
+ public BinaryTreeNode max() {
+ return findMax(root);
+ }
+
+ private BinaryTreeNode findMax(BinaryTreeNode node) {
+ if (node == null) return null;
+ if (node.getRight() == null) return node;
+ return findMax(node.getRight());
+ }
+
+ public void delete(T data) {
+ BinaryTreeNode node = search(data);
+ if (node == null) return;
+ BinaryTreeNode parentNode = searchParentNode(node);
+ if (parentNode == null) return;
+ // 删除叶子节点
+ if (node.getLeft() == null && node.getRight() == null) {
+ if (parentNode.getLeft() == node) parentNode.setLeft(null);
+ else parentNode.setRight(null);
+ } else if (node.getLeft() != null && node.getRight() == null) { // 删除只有左子树的节点
+ if (parentNode.getLeft() == node) parentNode.setLeft(node.getLeft());
+ else parentNode.setRight(node.getLeft());
+ } else if (node.getRight() != null && node.getLeft() == null) { // 删除只有右子树的节点
+ if (parentNode.getLeft() == node) parentNode.setLeft(node.getRight());
+ else parentNode.setRight(node.getRight());
+ } else { // 删除有两个子树的节点
+ BinaryTreeNode replace = findMin(node.getRight());
+ BinaryTreeNode replaceParentNode = searchParentNode(replace);
+ replaceParentNode.setLeft(replace.getRight());
+ node.setData(replace.getData());
+ replace.setLeft(null);
+ replace.setRight(null);
+ }
+ size--;
+ }
+
+ private BinaryTreeNode searchParentNode(BinaryTreeNode node) {
+ if (node == null) return null;
+ if (node == root) return head;
+ BinaryTreeNode current = root;
+ while (current != null) {
+ if (current.getLeft() == node || current.getRight() == node) return current;
+ if (current.getData().compareTo(node.getData()) > 0) current = current.getLeft();
+ else current = current.getRight();
+ }
+ return null;
+ }
+
+ public Object[] traversal() {
+ return traversal(PREORDER);
+ }
+
+ public T[] traversal(T[] a) {
+ Object[] elementData = traversal(PREORDER);
+ return toArray(elementData, a);
+ }
+
+ public T[] traversal(int order, T[] a) {
+ Object[] elementData = traversal(order);
+ return toArray(elementData, a);
+ }
+
+ private T[] toArray(Object[] elementData, T[] a) {
+ if (a.length < size)
+ // Make a new array of a's runtime type, but my contents:
+ return (T[]) Arrays.copyOf(elementData, size, a.getClass());
+ System.arraycopy(elementData, 0, a, 0, size);
+ return a;
+ }
+
+ public Object[] traversal(int order) {
+ Object[] datas = new Object[size];
+ if (order == PREORDER) {
+ preorderTraversal(root, datas);
+ } else if (order == INORDER) {
+ inorderTraversal(root, datas);
+ } else if (order == POSTORDER) {
+ postorderTraversal(root, datas);
+ } else {
+ hierarchicalTraversal(root, datas);
+ }
+ index = 0;
+ return datas;
+ }
+
+ private void preorderTraversal(BinaryTreeNode node, Object[] datas) {
+ if (node == null) {
+ return;
+ }
+
+ datas[index++] = node.getData();
+ preorderTraversal(node.getLeft(), datas);
+ preorderTraversal(node.getRight(), datas);
+ }
+
+ private void inorderTraversal(BinaryTreeNode node, Object[] datas) {
+ if (node == null) {
+ return;
+ }
+
+ inorderTraversal(node.getLeft(), datas);
+ datas[index++] = node.getData();
+ inorderTraversal(node.getRight(), datas);
+ }
+
+ private void postorderTraversal(BinaryTreeNode node, Object[] datas) {
+ if (node == null) {
+ return;
+ }
+
+ postorderTraversal(node.getLeft(), datas);
+ postorderTraversal(node.getRight(), datas);
+ datas[index++] = node.getData();
+ }
+
+ private void hierarchicalTraversal(BinaryTreeNode node, Object[] datas) {
+ if (node == null) return;
+ GenericQueue> queue = new GenericQueue<>();
+ queue.enQueue(node);
+ while (!queue.isEmpty()) {
+ BinaryTreeNode tmp = queue.deQueue();
+ datas[index++] = tmp.getData();
+ if (tmp.getLeft() != null) queue.enQueue(tmp.getLeft());
+ if (tmp.getRight() != null) queue.enQueue(tmp.getRight());
+ }
+ }
+
+
+ class BinaryTreeNode> {
+ private T data;
+ private BinaryTreeNode left;
+ private BinaryTreeNode right;
+
+ public BinaryTreeNode(T data) {
+ this.data = data;
+ }
+
+ public T getData() {
+ return data;
+ }
+
+ public void setData(T 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;
+ }
+ }
+}
diff --git a/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/generic/GenericIterator.java b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/generic/GenericIterator.java
new file mode 100644
index 0000000000..565114dce7
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/generic/GenericIterator.java
@@ -0,0 +1,9 @@
+package com.aaront.exercise.generic;
+
+public interface GenericIterator {
+ boolean hasNext();
+
+ T next();
+
+ void remove();
+}
diff --git a/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/generic/GenericLinkedList.java b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/generic/GenericLinkedList.java
new file mode 100644
index 0000000000..7caf32eae1
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/generic/GenericLinkedList.java
@@ -0,0 +1,140 @@
+package com.aaront.exercise.generic;
+
+import java.util.Arrays;
+
+public class GenericLinkedList implements GenericList {
+
+ private Node head = new Node<>(null);
+ private int size = 0;
+
+ public void add(T o) {
+ Node newNode = new Node<>(o);
+ Node first = head.next;
+ Node second = head;
+ while (first != null) {
+ second = first;
+ first = first.next;
+ }
+ second.next = newNode;
+ size++;
+ }
+
+ public void add(int index, T o) {
+ if (index < 0 || index > size) throw new IndexOutOfBoundsException("索引超出范围");
+ Node first = head;
+ int i = 0;
+ while (i < index) {
+ first = first.next;
+ i++;
+ }
+ Node node = new Node<>(o);
+ node.next = first.next;
+ first.next = node;
+ size++;
+ }
+
+ public T get(int index) {
+ if (index < 0 || index >= size) throw new IndexOutOfBoundsException("索引超出范围");
+ Node first = head.next;
+ int i = 0;
+ while (i < index) {
+ first = first.next;
+ i++;
+ }
+ return first.data;
+ }
+
+ public T remove(int index) {
+ if (index < 0 || index >= size) throw new IndexOutOfBoundsException("索引超出范围");
+ Node first = head;
+ int i = 0;
+ while (i < index) {
+ first = first.next;
+ i++;
+ }
+ Node element = first.next;
+ first.next = first.next.next;
+ size--;
+ return element.data;
+ }
+
+ public int size() {
+ return size;
+ }
+
+ public void addFirst(T o) {
+ add(0, o);
+ }
+
+ public void addLast(T o) {
+ add(size, o);
+ }
+
+ public T removeFirst() {
+ return remove(0);
+ }
+
+ public T removeLast() {
+ return remove(size - 1);
+ }
+
+ public GenericIterator iterator() {
+ return new LinkedListGenericIterator<>(this);
+ }
+
+ public Object[] toArray() {
+ Object[] objects = new Object[size];
+ Node first = head.next;
+ int pos = 0;
+ while (first != null) {
+ objects[pos++] = first.data;
+ first = first.next;
+ }
+ return objects;
+ }
+
+ public T[] toArray(T[] a) {
+ Object[] elementData = toArray();
+ if (a.length < size)
+ // Make a new array of a's runtime type, but my contents:
+ return (T[]) Arrays.copyOf(elementData, size, a.getClass());
+ System.arraycopy(elementData, 0, a, 0, size);
+ return a;
+ }
+
+ private static class LinkedListGenericIterator implements GenericIterator {
+
+ private int pos = 0;
+ private GenericLinkedList genericLinkedList;
+
+ private LinkedListGenericIterator(GenericLinkedList linkList) {
+ this.genericLinkedList = linkList;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return pos < genericLinkedList.size();
+ }
+
+ @Override
+ public T next() {
+ return genericLinkedList.get(pos++);
+ }
+
+ @Override
+ public void remove() {
+ genericLinkedList.remove(pos - 1);
+ pos--;
+ }
+ }
+
+
+ private static class Node {
+ private T data;
+ private Node next;
+
+ private Node(T data) {
+ this.data = data;
+ }
+ }
+}
diff --git a/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/generic/GenericList.java b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/generic/GenericList.java
new file mode 100644
index 0000000000..94dc9f8a98
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/generic/GenericList.java
@@ -0,0 +1,9 @@
+package com.aaront.exercise.generic;
+
+public interface GenericList {
+ public void add(T o);
+ public void add(int index, T o);
+ public T get(int index);
+ public T remove(int index);
+ public int size();
+}
\ No newline at end of file
diff --git a/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/generic/GenericQueue.java b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/generic/GenericQueue.java
new file mode 100644
index 0000000000..d5cf5681e5
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/generic/GenericQueue.java
@@ -0,0 +1,30 @@
+package com.aaront.exercise.generic;
+
+public class GenericQueue {
+
+ private GenericLinkedList linkedList = new GenericLinkedList<>();
+
+ public void enQueue(T o) {
+ linkedList.add(o);
+ }
+
+ public T deQueue() {
+ return linkedList.removeFirst();
+ }
+
+ public boolean isEmpty() {
+ return linkedList.size() == 0;
+ }
+
+ public int size() {
+ return linkedList.size();
+ }
+
+ public Object[] toArray() {
+ return linkedList.toArray();
+ }
+
+ public T[] toArray(T[] a) {
+ return linkedList.toArray(a);
+ }
+}
diff --git a/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/generic/GenericStack.java b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/generic/GenericStack.java
new file mode 100644
index 0000000000..9efb2f2220
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/main/java/com/aaront/exercise/generic/GenericStack.java
@@ -0,0 +1,33 @@
+package com.aaront.exercise.generic;
+
+public class GenericStack {
+ private GenericArrayList elementData = new GenericArrayList<>();
+
+ public void push(T o) {
+ elementData.add(o);
+ }
+
+ public T pop() {
+ return elementData.remove(elementData.size() - 1);
+ }
+
+ public T peek() {
+ return elementData.get(elementData.size() - 1);
+ }
+
+ public boolean isEmpty() {
+ return elementData.size() == 0;
+ }
+
+ public int size() {
+ return elementData.size();
+ }
+
+ public Object[] toArray() {
+ return elementData.toArray();
+ }
+
+ public T[] toArray(T[] a) {
+ return elementData.toArray(a);
+ }
+}
diff --git a/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/basic/AllTest.java b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/basic/AllTest.java
new file mode 100644
index 0000000000..ebff633b23
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/basic/AllTest.java
@@ -0,0 +1,19 @@
+package com.aaront.execrise.basic;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * @author tonyhui
+ * @since 17/2/21
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ ArrayListTest.class,
+ BinaryTreeTest.class,
+ LinkListTest.class,
+ QueueTest.class,
+ StackTest.class
+})
+public class AllTest {
+}
diff --git a/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/basic/ArrayListTest.java b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/basic/ArrayListTest.java
new file mode 100644
index 0000000000..dcc45d792e
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/basic/ArrayListTest.java
@@ -0,0 +1,69 @@
+package com.aaront.execrise.basic;
+
+import com.aaront.exercise.basic.ArrayList;
+import com.aaront.exercise.basic.Iterator;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author tonyhui
+ * @since 17/2/20
+ */
+public class ArrayListTest {
+
+ private ArrayList arrayList = new ArrayList();
+
+ @Before
+ public void init() {
+ arrayList.add(1);
+ arrayList.add(2);
+ arrayList.add(3);
+ }
+
+ @Test
+ public void testAdd() {
+ Assert.assertEquals(arrayList.get(0), 1);
+ Assert.assertEquals(arrayList.get(1), 2);
+ Assert.assertEquals(arrayList.get(2), 3);
+ Assert.assertEquals(arrayList.size(), 3);
+ }
+
+ @Test
+ public void testAddIndex() {
+ arrayList.add(1, 4);
+ arrayList.add(2, 5);
+ Assert.assertArrayEquals(arrayList.toArray(), new Object[]{1, 4, 5, 2, 3});
+ }
+
+ @Test
+ public void testToArray() {
+ Assert.assertArrayEquals(arrayList.toArray(), new Object[]{1, 2, 3});
+ }
+
+ @Test
+ public void testGet() {
+ Assert.assertEquals(arrayList.get(2), 3);
+ Assert.assertEquals(arrayList.get(0), 1);
+ Assert.assertEquals(arrayList.get(1), 2);
+ }
+
+ @Test
+ public void testRemove() {
+ testAddIndex();
+ arrayList.remove(2);
+ arrayList.add(4, 10);
+ arrayList.add(3, 9);
+ Assert.assertArrayEquals(arrayList.toArray(), new Object[]{1, 4, 2, 9, 3, 10});
+ }
+
+ @Test
+ public void testIterator() {
+ Iterator iterator = arrayList.iterator();
+ while (iterator.hasNext()) {
+ iterator.next();
+ iterator.remove();
+ }
+ Assert.assertArrayEquals(arrayList.toArray(), new Object[]{});
+ }
+}
diff --git a/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/basic/BinaryTreeTest.java b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/basic/BinaryTreeTest.java
new file mode 100644
index 0000000000..11fb7ad66b
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/basic/BinaryTreeTest.java
@@ -0,0 +1,94 @@
+package com.aaront.execrise.basic;
+
+import com.aaront.exercise.basic.BinaryTree;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author tonyhui
+ * @since 17/2/20
+ */
+public class BinaryTreeTest {
+
+ private BinaryTree binaryTree = null;
+
+ @Before
+ public void init() {
+ int[] datas = new int[]{9, 4, 5, 7, 1, 2, 3, 10, 17, 9};
+ binaryTree = new BinaryTree();
+ for (int data : datas) {
+ binaryTree.add(data);
+ }
+ }
+
+
+ @Test
+ public void testAdd() {
+ int[] preorderDatas = binaryTree.traversal(BinaryTree.PREORDER);
+ Assert.assertArrayEquals(preorderDatas, new int[]{9, 4, 1, 2, 3, 5, 7, 10, 9, 17});
+ int[] inorderDatas = binaryTree.traversal(BinaryTree.INORDER);
+ Assert.assertArrayEquals(inorderDatas, new int[]{1, 2, 3, 4, 5, 7, 9, 9, 10, 17});
+ int[] postorderDatas = binaryTree.traversal(BinaryTree.POSTORDER);
+ Assert.assertArrayEquals(postorderDatas, new int[]{3, 2, 1, 7, 5, 4, 9, 17, 10, 9});
+ int[] hierarchicalDatas = binaryTree.traversal(BinaryTree.HIERARCHICAL);
+ Assert.assertArrayEquals(hierarchicalDatas, new int[]{9, 4, 10, 1, 5, 9, 17, 2, 7, 3});
+ }
+
+ @Test
+ public void testSearch() {
+ BinaryTree.BinaryTreeNode node1 = binaryTree.search(5, BinaryTree.RECURSION);
+ Assert.assertTrue(node1.getData() == 5);
+ BinaryTree.BinaryTreeNode node2 = binaryTree.search(17, BinaryTree.RECURSION);
+ Assert.assertTrue(node2.getData() == 17);
+ BinaryTree.BinaryTreeNode node3 = binaryTree.search(100, BinaryTree.RECURSION);
+ Assert.assertTrue(node3 == null);
+ }
+
+ @Test
+ public void testMin() {
+ BinaryTree.BinaryTreeNode min = binaryTree.min();
+ Assert.assertTrue(min.getData() == 1);
+ }
+
+ @Test
+ public void testMax() {
+ BinaryTree.BinaryTreeNode max = binaryTree.max();
+ Assert.assertTrue(max.getData() == 17);
+ }
+
+ @Test
+ public void testDelete() {
+ buildTree(new int[]{50, 25, 12, 11, 40, 14, 35, 45, 44, 43, 42, 75, 55, 70, 60, 65, 63, 61, 90, 80, 85, 82, 88});
+ // 删除叶子节点
+ binaryTree.delete(11);
+ int[] preOrderDatas = binaryTree.traversal();
+ Assert.assertArrayEquals(preOrderDatas, new int[]{50, 25, 12, 14, 40, 35, 45, 44, 43, 42, 75, 55, 70, 60, 65, 63, 61, 90, 80, 85, 82, 88});
+ binaryTree.delete(88);
+ preOrderDatas = binaryTree.traversal();
+ Assert.assertArrayEquals(preOrderDatas, new int[]{50, 25, 12, 14, 40, 35, 45, 44, 43, 42, 75, 55, 70, 60, 65, 63, 61, 90, 80, 85, 82});
+
+ // 删除一个子节点的节点
+ binaryTree.delete(70);
+ preOrderDatas = binaryTree.traversal();
+ Assert.assertArrayEquals(preOrderDatas, new int[]{50, 25, 12, 14, 40, 35, 45, 44, 43, 42, 75, 55, 60, 65, 63, 61, 90, 80, 85, 82});
+ binaryTree.delete(80);
+ preOrderDatas = binaryTree.traversal();
+ Assert.assertArrayEquals(preOrderDatas, new int[]{50, 25, 12, 14, 40, 35, 45, 44, 43, 42, 75, 55, 60, 65, 63, 61, 90, 85, 82});
+
+ // 删除两个子节点的节点
+ binaryTree.delete(40);
+ preOrderDatas = binaryTree.traversal();
+ Assert.assertArrayEquals(preOrderDatas, new int[]{50, 25, 12, 14, 42, 35, 45, 44, 43, 75, 55, 60, 65, 63, 61, 90, 85, 82});
+ binaryTree.delete(50);
+ preOrderDatas = binaryTree.traversal();
+ Assert.assertArrayEquals(preOrderDatas, new int[]{55, 25, 12, 14, 42, 35, 45, 44, 43, 75, 60, 65, 63, 61, 90, 85, 82});
+ }
+
+ private void buildTree(int[] datas) {
+ binaryTree = new BinaryTree();
+ for (int data : datas) {
+ binaryTree.add(data);
+ }
+ }
+}
\ No newline at end of file
diff --git a/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/basic/LinkListTest.java b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/basic/LinkListTest.java
new file mode 100644
index 0000000000..b690c69c94
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/basic/LinkListTest.java
@@ -0,0 +1,81 @@
+package com.aaront.execrise.basic;
+
+import com.aaront.exercise.basic.Iterator;
+import com.aaront.exercise.basic.LinkedList;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author tonyhui
+ * @since 17/2/21
+ */
+public class LinkListTest {
+
+ private LinkedList linkedList = new LinkedList();
+
+ @Before
+ public void init() {
+ linkedList.add(1);
+ linkedList.add(2);
+ linkedList.add(3);
+ }
+
+ @Test
+ public void testAdd() {
+ Assert.assertArrayEquals(linkedList.toArray(), new Object[]{1, 2, 3});
+ }
+
+ @Test
+ public void testAddIndex() {
+ linkedList.add(1, 10);
+ linkedList.add(0, 8);
+ Assert.assertArrayEquals(linkedList.toArray(), new Object[]{8, 1, 10, 2, 3});
+ }
+
+ @Test
+ public void testAddFirst() {
+ linkedList.addFirst(-1);
+ Assert.assertArrayEquals(linkedList.toArray(), new Object[]{-1, 1, 2, 3});
+ }
+
+ @Test
+ public void testAddLast() {
+ linkedList.addLast(99);
+ Assert.assertArrayEquals(linkedList.toArray(), new Object[]{1, 2, 3, 99});
+ }
+
+ @Test
+ public void testRemove() {
+ testAddIndex();
+ linkedList.remove(1);
+ linkedList.remove(2);
+ linkedList.add(3, 3);
+ linkedList.add(1, 2);
+ Assert.assertArrayEquals(linkedList.toArray(), new Object[]{8, 2, 10, 3, 3});
+ }
+
+ @Test
+ public void testRemoveFirst() {
+ linkedList.removeFirst();
+ linkedList.removeFirst();
+ Assert.assertArrayEquals(linkedList.toArray(), new Object[]{3});
+ }
+
+ @Test
+ public void testRemoveLast() {
+ linkedList.removeLast();
+ linkedList.removeLast();
+ Assert.assertArrayEquals(linkedList.toArray(), new Object[]{1});
+ }
+
+ @Test
+ public void testIterator() {
+ Iterator iterator = linkedList.iterator();
+ while (iterator.hasNext()) {
+ iterator.next();
+ iterator.remove();
+ }
+ Assert.assertArrayEquals(linkedList.toArray(), new Object[]{});
+ }
+}
diff --git a/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/basic/QueueTest.java b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/basic/QueueTest.java
new file mode 100644
index 0000000000..0035a353ec
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/basic/QueueTest.java
@@ -0,0 +1,33 @@
+package com.aaront.execrise.basic;
+
+import com.aaront.exercise.basic.Queue;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author tonyhui
+ * @since 17/2/21
+ */
+public class QueueTest {
+ private Queue queue = new Queue();
+
+ @Before
+ public void init() {
+ queue.enQueue(1);
+ queue.enQueue(2);
+ queue.enQueue(3);
+ }
+
+ @Test
+ public void testEnqueue() {
+ Assert.assertArrayEquals(queue.toArray(), new Object[]{1, 2, 3});
+ }
+
+ @Test
+ public void testDequeue() {
+ queue.deQueue();
+ queue.deQueue();
+ Assert.assertArrayEquals(queue.toArray(), new Object[]{3});
+ }
+}
diff --git a/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/basic/StackTest.java b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/basic/StackTest.java
new file mode 100644
index 0000000000..3add6bcfdf
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/basic/StackTest.java
@@ -0,0 +1,46 @@
+package com.aaront.execrise.basic;
+
+import com.aaront.exercise.basic.Stack;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author tonyhui
+ * @since 17/2/21
+ */
+public class StackTest {
+
+ private Stack stack = new Stack();
+
+ @Before
+ public void init() {
+ stack.push(1);
+ stack.push(2);
+ stack.push(3);
+ }
+
+ @Test
+ public void testPush() {
+ Assert.assertArrayEquals(stack.toArray(), new Object[]{1, 2, 3});
+ }
+
+ @Test
+ public void testPop() {
+ Object element1 = stack.pop();
+ Assert.assertEquals(element1, 3);
+ Object element2 = stack.pop();
+ Assert.assertEquals(element2, 2);
+ Assert.assertArrayEquals(stack.toArray(), new Object[]{1});
+ }
+
+ @Test
+ public void testPeek() {
+ Object element1 = stack.peek();
+ Assert.assertEquals(element1, 3);
+ Object element2 = stack.peek();
+ Assert.assertEquals(element2, 3);
+ Assert.assertArrayEquals(stack.toArray(), new Object[]{1, 2, 3});
+ }
+
+}
diff --git a/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/generic/GenericAllTest.java b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/generic/GenericAllTest.java
new file mode 100644
index 0000000000..66c071cf5c
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/generic/GenericAllTest.java
@@ -0,0 +1,19 @@
+package com.aaront.execrise.generic;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * @author tonyhui
+ * @since 17/2/22
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ GenericArrayListTest.class,
+ GenericLinkedListTest.class,
+ GenericQueueTest.class,
+ GenericStackTest.class,
+ GenericBinaryTreeTest.class
+})
+public class GenericAllTest {
+}
diff --git a/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/generic/GenericArrayListTest.java b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/generic/GenericArrayListTest.java
new file mode 100644
index 0000000000..8f97cbd3ea
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/generic/GenericArrayListTest.java
@@ -0,0 +1,76 @@
+package com.aaront.execrise.generic;
+
+import com.aaront.exercise.generic.GenericArrayList;
+import com.aaront.exercise.generic.GenericIterator;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author tonyhui
+ * @since 17/2/22
+ */
+public class GenericArrayListTest {
+
+ private GenericArrayList arrayList = new GenericArrayList<>();
+
+ @Before
+ public void init() {
+ arrayList.add("1");
+ arrayList.add("2");
+ arrayList.add("3");
+ }
+
+
+ @Test
+ public void testAdd() {
+ Assert.assertEquals(arrayList.get(0), "1");
+ Assert.assertEquals(arrayList.get(1), "2");
+ Assert.assertEquals(arrayList.get(2), "3");
+ Assert.assertEquals(arrayList.size(), 3);
+ }
+
+ @Test
+ public void testAddIndex() {
+ arrayList.add(1, "4");
+ arrayList.add(2, "5");
+ Assert.assertArrayEquals(arrayList.toArray(), new String[]{"1", "4", "5", "2", "3"});
+ }
+
+ @Test
+ public void testToArray() {
+ Assert.assertArrayEquals(arrayList.toArray(), new String[]{"1", "2", "3"});
+ }
+
+ @Test
+ public void testToGenericArray() {
+ Assert.assertArrayEquals(arrayList.toArray(new String[0]), new String[]{"1", "2", "3"});
+ }
+
+ @Test
+ public void testGet() {
+ Assert.assertEquals(arrayList.get(2), "3");
+ Assert.assertEquals(arrayList.get(0), "1");
+ Assert.assertEquals(arrayList.get(1), "2");
+ }
+
+ @Test
+ public void testRemove() {
+ testAddIndex();
+ arrayList.remove(2);
+ arrayList.add(4, "10");
+ arrayList.add(3, "9");
+ Assert.assertArrayEquals(arrayList.toArray(), new String[]{"1", "4", "2", "9", "3", "10"});
+ }
+
+ @Test
+ public void testIterator() {
+ GenericIterator genericIterator = arrayList.iterator();
+ while (genericIterator.hasNext()) {
+ genericIterator.next();
+ genericIterator.remove();
+ }
+ Assert.assertArrayEquals(arrayList.toArray(), new String[]{});
+ }
+
+}
diff --git a/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/generic/GenericBinaryTreeTest.java b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/generic/GenericBinaryTreeTest.java
new file mode 100644
index 0000000000..41adbf6706
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/generic/GenericBinaryTreeTest.java
@@ -0,0 +1,75 @@
+package com.aaront.execrise.generic;
+
+import com.aaront.exercise.generic.GenericBinaryTree;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author tonyhui
+ * @since 17/2/20
+ */
+public class GenericBinaryTreeTest {
+
+ @Before
+ public void init() {
+ String[] datas = new String[]{"9", "4", "5", "7", "1", "2", "3", "10", "17", "9"};
+ GenericBinaryTree binaryTree = new GenericBinaryTree<>();
+ for (String data : datas) {
+ binaryTree.add(data);
+ }
+ }
+
+ @Test
+ public void testAdd() {
+ String[] datas = new String[]{"9", "4", "5", "7", "1", "2", "3", "10", "17", "9"};
+ GenericBinaryTree binaryTree = new GenericBinaryTree<>();
+ for (String data : datas) {
+ binaryTree.add(data);
+ }
+ String[] preorderDatas = binaryTree.traversal(GenericBinaryTree.PREORDER, new String[0]);
+ Assert.assertArrayEquals(preorderDatas, new String[]{"9", "4", "1", "2", "10", "17", "3", "5", "7", "9" });
+ String[] inorderDatas = binaryTree.traversal(GenericBinaryTree.INORDER, new String[0]);
+ Assert.assertArrayEquals(inorderDatas, new String[]{"1", "10", "17", "2", "3", "4", "5", "7", "9", "9" });
+ String[] postorderDatas = binaryTree.traversal(GenericBinaryTree.POSTORDER, new String[0]);
+ Assert.assertArrayEquals(postorderDatas, new String[]{"17", "10", "3", "2", "1", "7", "5", "4", "9", "9" });
+ String[] hierarchicalDatas = binaryTree.traversal(GenericBinaryTree.HIERARCHICAL, new String[0]);
+ Assert.assertArrayEquals(hierarchicalDatas, new String[]{"9", "4", "9", "1", "5", "2", "7", "10", "3", "17" });
+ }
+
+ @Test
+ public void testDelete() {
+ GenericBinaryTree binaryTree = buildTree(new int[]{50, 25, 12, 11, 40, 14, 35, 45, 44, 43, 42, 75, 55, 70, 60, 65, 63, 61, 90, 80, 85, 82, 88});
+ // 删除叶子节点
+ binaryTree.delete(11);
+ Object[] preOrderDatas = binaryTree.traversal();
+ Assert.assertArrayEquals(preOrderDatas, new Object[]{50, 25, 12, 14, 40, 35, 45, 44, 43, 42, 75, 55, 70, 60, 65, 63, 61, 90, 80, 85, 82, 88});
+ binaryTree.delete(88);
+ preOrderDatas = binaryTree.traversal();
+ Assert.assertArrayEquals(preOrderDatas, new Object[]{50, 25, 12, 14, 40, 35, 45, 44, 43, 42, 75, 55, 70, 60, 65, 63, 61, 90, 80, 85, 82});
+
+ // 删除一个子节点的节点
+ binaryTree.delete(70);
+ preOrderDatas = binaryTree.traversal();
+ Assert.assertArrayEquals(preOrderDatas, new Object[]{50, 25, 12, 14, 40, 35, 45, 44, 43, 42, 75, 55, 60, 65, 63, 61, 90, 80, 85, 82});
+ binaryTree.delete(80);
+ preOrderDatas = binaryTree.traversal();
+ Assert.assertArrayEquals(preOrderDatas, new Object[]{50, 25, 12, 14, 40, 35, 45, 44, 43, 42, 75, 55, 60, 65, 63, 61, 90, 85, 82});
+
+ // 删除两个子节点的节点
+ binaryTree.delete(40);
+ preOrderDatas = binaryTree.traversal();
+ Assert.assertArrayEquals(preOrderDatas, new Object[]{50, 25, 12, 14, 42, 35, 45, 44, 43, 75, 55, 60, 65, 63, 61, 90, 85, 82});
+ binaryTree.delete(50);
+ preOrderDatas = binaryTree.traversal();
+ Assert.assertArrayEquals(preOrderDatas, new Object[]{55, 25, 12, 14, 42, 35, 45, 44, 43, 75, 60, 65, 63, 61, 90, 85, 82});
+ }
+
+ private GenericBinaryTree buildTree(int[] datas) {
+ GenericBinaryTree binaryTree = new GenericBinaryTree<>();
+ for (int data : datas) {
+ binaryTree.add(data);
+ }
+ return binaryTree;
+ }
+}
\ No newline at end of file
diff --git a/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/generic/GenericLinkedListTest.java b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/generic/GenericLinkedListTest.java
new file mode 100644
index 0000000000..513119fa6e
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/generic/GenericLinkedListTest.java
@@ -0,0 +1,90 @@
+package com.aaront.execrise.generic;
+
+import com.aaront.exercise.generic.GenericLinkedList;
+import com.aaront.exercise.generic.GenericIterator;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author tonyhui
+ * @since 17/2/22
+ */
+public class GenericLinkedListTest {
+ private GenericLinkedList linkedList = new GenericLinkedList<>();
+
+ @Before
+ public void init() {
+ linkedList.add("1");
+ linkedList.add("2");
+ linkedList.add("3");
+ }
+
+ @Test
+ public void testAdd() {
+ Assert.assertArrayEquals(linkedList.toArray(), new String[]{"1", "2", "3"});
+ }
+
+ @Test
+ public void testAddIndex() {
+ linkedList.add(1, "10");
+ linkedList.add(0, "8");
+ Assert.assertArrayEquals(linkedList.toArray(), new String[]{"8", "1", "10", "2", "3"});
+ }
+
+ @Test
+ public void testAddFirst() {
+ linkedList.addFirst("-1");
+ Assert.assertArrayEquals(linkedList.toArray(), new String[]{"-1", "1", "2", "3"});
+ }
+
+ @Test
+ public void testAddLast() {
+ linkedList.addLast("99");
+ Assert.assertArrayEquals(linkedList.toArray(), new String[]{"1", "2", "3", "99"});
+ }
+
+ @Test
+ public void testRemove() {
+ testAddIndex();
+ linkedList.remove(1);
+ linkedList.remove(2);
+ linkedList.add(3, "3");
+ linkedList.add(1, "2");
+ Assert.assertArrayEquals(linkedList.toArray(), new String[]{"8", "2", "10", "3", "3"});
+ }
+
+ @Test
+ public void testRemoveFirst() {
+ linkedList.removeFirst();
+ linkedList.removeFirst();
+ Assert.assertArrayEquals(linkedList.toArray(), new String[]{"3"});
+ }
+
+ @Test
+ public void testRemoveLast() {
+ linkedList.removeLast();
+ linkedList.removeLast();
+ Assert.assertArrayEquals(linkedList.toArray(), new String[]{"1"});
+ }
+
+ @Test
+ public void testToArray() {
+ Assert.assertArrayEquals(linkedList.toArray(), new String[]{"1", "2", "3"});
+ }
+
+ @Test
+ public void testToGenericArray() {
+ Assert.assertArrayEquals(linkedList.toArray(new String[0]), new String[]{"1", "2", "3"});
+ }
+
+ @Test
+ public void testIterator() {
+ GenericIterator genericIterator = linkedList.iterator();
+ while (genericIterator.hasNext()) {
+ genericIterator.next();
+ genericIterator.remove();
+ }
+ Assert.assertArrayEquals(linkedList.toArray(), new String[]{});
+ }
+}
diff --git a/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/generic/GenericQueueTest.java b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/generic/GenericQueueTest.java
new file mode 100644
index 0000000000..6b33a4b3e0
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/generic/GenericQueueTest.java
@@ -0,0 +1,33 @@
+package com.aaront.execrise.generic;
+
+import com.aaront.exercise.generic.GenericQueue;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author tonyhui
+ * @since 17/2/21
+ */
+public class GenericQueueTest {
+ private GenericQueue queue = new GenericQueue<>();
+
+ @Before
+ public void init() {
+ queue.enQueue("1");
+ queue.enQueue("2");
+ queue.enQueue("3");
+ }
+
+ @Test
+ public void testEnqueue() {
+ Assert.assertArrayEquals(queue.toArray(), new String[]{"1", "2", "3"});
+ }
+
+ @Test
+ public void testDequeue() {
+ queue.deQueue();
+ queue.deQueue();
+ Assert.assertArrayEquals(queue.toArray(), new String[]{"3"});
+ }
+}
diff --git a/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/generic/GenericStackTest.java b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/generic/GenericStackTest.java
new file mode 100644
index 0000000000..0b4b587704
--- /dev/null
+++ b/group01/954958168/class01/BasicDataStructure/src/test/java/com/aaront/execrise/generic/GenericStackTest.java
@@ -0,0 +1,46 @@
+package com.aaront.execrise.generic;
+
+import com.aaront.exercise.generic.GenericStack;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author tonyhui
+ * @since 17/2/21
+ */
+public class GenericStackTest {
+
+ private GenericStack stack = new GenericStack<>();
+
+ @Before
+ public void init() {
+ stack.push("1");
+ stack.push("2");
+ stack.push("3");
+ }
+
+ @Test
+ public void testPush() {
+ Assert.assertArrayEquals(stack.toArray(), new String[]{"1", "2", "3"});
+ }
+
+ @Test
+ public void testPop() {
+ String element1 = stack.pop();
+ Assert.assertEquals(element1, "3");
+ String element2 = stack.pop();
+ Assert.assertEquals(element2, "2");
+ Assert.assertArrayEquals(stack.toArray(), new String[]{"1"});
+ }
+
+ @Test
+ public void testPeek() {
+ String element1 = stack.peek();
+ Assert.assertEquals(element1, "3");
+ String element2 = stack.peek();
+ Assert.assertEquals(element2, "3");
+ Assert.assertArrayEquals(stack.toArray(), new String[]{"1", "2", "3"});
+ }
+
+}
diff --git a/group01/group01.md b/group01/group01.md
index d3f5a12faa..8b13789179 100644
--- a/group01/group01.md
+++ b/group01/group01.md
@@ -1 +1 @@
-
+
diff --git a/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/array/ArrayUtil.java b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/array/ArrayUtil.java
new file mode 100644
index 0000000000..38c0889f32
--- /dev/null
+++ b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/array/ArrayUtil.java
@@ -0,0 +1,301 @@
+package com.github.Ven13.coding2017.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){
+
+ int originalLen = origin.length;
+
+ int len = originalLen;
+
+ int temp;
+
+ for(int i = 0; i < (originalLen/2); i++){
+
+ temp = origin[len - i - 1];
+
+ origin[len - i - 1] = origin[i];
+
+ origin[i] = 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 newLength = 0;
+ // 鳤ֵ
+ for (int i = 0; i < oldArray.length; i++) {
+
+ if(oldArray[i] != 0) {
+
+ newLength++;
+
+ }
+
+ }
+
+ //
+ int[] newArray = new int[newLength];
+ // ±
+ int n = 0;
+ // ת
+ for (int i = 0; i < oldArray.length; i++) {
+
+ if(oldArray[i] != 0) {
+
+ newArray[n] = oldArray[i];// ת
+ n++;// ±ƫ
+
+ }
+
+ }
+
+ //ɵ
+ return newArray;
+
+ }
+
+ /**
+ * Ѿõ飬 a1a2 , һµa3, ʹa3 a1a2 Ԫأ Ȼ
+ * 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){
+
+ int[] newArray = new int[array1.length + array2.length];
+
+ int k = 0;
+
+ String inNum = "";
+
+ for(int i = 0; i < array1.length; i++) {
+
+ for(int j = 0; j < array2.length; j++) {
+
+ if (array1[i] < array2[j]) {
+ if (inNum.indexOf(array1[i] + "|") < 0) {
+ newArray[k++] = array1[i];
+ inNum += array1[i] + "|";
+ }
+
+ } else if (array1[i] == array2[j]) {
+ if (inNum.indexOf(array1[i] + "|") < 0) {
+ newArray[k++] = array1[i];
+ inNum += array1[i] + "|";
+ }
+ } else {
+ if (i == array1.length - 1) {
+ if (inNum.indexOf(array1[i] + "|") < 0) {
+ newArray[k++] = array1[i];
+ inNum += array1[i] + "|";
+ }
+ } else {
+ if (inNum.indexOf(array2[j] + "|") < 0) {
+ newArray[k++] = array2[j];
+ inNum += array2[j] + "|";
+ }
+ }
+
+ }
+
+ }
+
+ }
+
+ return newArray;
+ }
+ /**
+ * һѾݵ 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){
+ int[] newArray = new int[oldArray.length + size];
+ return newArray;
+ }
+
+ /**
+ * 쳲Ϊ1123581321...... һֵ Сڸֵ
+ * 磬 max = 15 , صӦΪ [11235813]
+ * max = 1, ؿ []
+ * @param max
+ * @return
+ */
+ public int[] fibonacci(int max){
+ return null;
+ }
+
+ /**
+ * Сڸֵmax
+ * max = 23, صΪ[2,3,5,7,11,13,17,19]
+ * @param max
+ * @return
+ */
+ public int[] getPrimes(int max){
+
+ int[] newArray = new int[max];
+
+ int k = 0;
+
+ boolean isN = true;
+
+ if (max > 2) {
+
+ for (int i = 2; i < max; i++) {
+
+ isN = true;
+
+ for (int j = 2; j < max; j++) {
+
+ if (i % j == 0 && i != j) {
+
+ isN = false;
+
+ }
+ }
+
+ if (isN) {
+
+ newArray[k++] = i;
+
+ }
+
+ }
+
+ } else if (max == 2) {
+
+ newArray[0] = 2;
+ k++;
+ } else {
+
+ return null;
+
+ }
+
+ int[] newArray2 = new int[k];
+
+ for(int i = 0; i < k; i ++) {
+
+ newArray2[i] = newArray[i];
+
+ }
+
+ return newArray2;
+ }
+
+ /**
+ * ν ָǡõ֮ͣ6=1+2+3
+ * һֵmax һ飬 Сmax
+ * @param max
+ * @return
+ */
+ public int[] getPerfectNumbers(int max) {
+
+ int i, j, k;
+
+ int sum;
+
+ k = 0;
+
+ for(i = 1; i <= max; i++) {
+
+
+ sum = 0;
+
+ for(j = 1; j < i; j++) {
+
+ if(i % j == 0) {
+
+ sum += j;
+
+ }
+
+ }
+
+ if(i == sum)
+ k++;
+ }
+
+ int[] newArray = new int[k];
+
+ k = 0;
+
+ for(i = 1; i <= max; i++) {
+
+
+ sum = 0;
+
+ for(j = 1; j < i; j++) {
+
+ if(i % j == 0) {
+
+ sum += j;
+
+ }
+
+ }
+
+ if(i == sum) {
+
+ newArray[k] = i;
+
+ k++;
+
+ }
+
+ }
+
+
+ return newArray;
+ }
+
+ /**
+ * seperator array
+ * array= [3,8,9], seperator = "-"
+ * ֵΪ"3-8-9"
+ * @param array
+ * @param s
+ * @return
+ */
+ public String join(int[] array, String seperator){
+
+ String str = "";
+
+ for(int i = 0; i < array.length; i++) {
+
+ str += array[i] + seperator;
+
+ }
+
+ str = str.substring(0, str.length() - 1);
+
+ return str;
+ }
+
+
+
+}
diff --git a/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/array/test/ArrayUtilTest.java b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/array/test/ArrayUtilTest.java
new file mode 100644
index 0000000000..c9684fa326
--- /dev/null
+++ b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/array/test/ArrayUtilTest.java
@@ -0,0 +1,46 @@
+package com.github.Ven13.coding2017.array.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+import com.github.Ven13.coding2017.array.ArrayUtil;
+
+public class ArrayUtilTest {
+
+ @Test
+ public final void testMerge() {
+ ArrayUtil arrayUtil = new ArrayUtil();
+ int[] a1 = {3, 5, 7, 8};
+ int[] a2 = {4, 5, 6, 7};
+ int[] a3 = {};
+ a3 = arrayUtil.merge(a1, a2);
+ assertEquals(3, a3[0]);
+ assertEquals(4, a3[1]);
+ assertEquals(5, a3[2]);
+ assertEquals(6, a3[3]);
+ assertEquals(7, a3[4]);
+ assertEquals(8, a3[5]);
+
+ }
+
+ @Test
+ public final void testgetPrimes() {
+ ArrayUtil arrayUtil = new ArrayUtil();
+ int max = 23;
+ int[] a1 = {};
+ a1 = arrayUtil.getPrimes(max);
+ assertEquals(3, a1.length);
+ assertEquals(1, a1[0]);
+ assertEquals(2, a1[1]);
+ assertEquals(3, a1[2]);
+ }
+
+ @Test
+ public final void testgetPerfectNumbers() {
+ ArrayUtil arrayUtil = new ArrayUtil();
+ int max = 6;
+ int[] a1 = {};
+ a1 = arrayUtil.getPerfectNumbers(max);
+ }
+}
diff --git a/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/ArrayList.java b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/ArrayList.java
new file mode 100644
index 0000000000..59ca0d34ee
--- /dev/null
+++ b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/ArrayList.java
@@ -0,0 +1,97 @@
+package com.github.Ven13.coding2017.basic;
+
+public class ArrayList implements List {
+
+ //ؼϴС
+ private int size = 0;
+
+ //ȸһΪ10
+ Object[] elementData = new Object[100];
+
+ @Override
+ //̬Ԫ
+ public void add(Object o) {
+ //жǷ
+ if(size == elementData.length) {
+ Object[] newObjects = new Object[elementData.length * 2];
+ System.arraycopy(elementData, 0, newObjects, 0, elementData.length);
+ elementData = newObjects;
+ }
+
+ //ΪӵԪָ±
+ elementData[size] = o;
+ size++;
+ }
+
+ @Override
+ public void add(int index, Object o) {
+ //жǷ
+ if(size == elementData.length) {
+ Object[] newObjects = elementData;
+ this.elementData = new Object[elementData.length * 2];
+ for(int j = 0; j < newObjects.length; j++) {
+ this.elementData[j] = newObjects[j];
+ }
+ }
+
+ for(int i = size - 1; i >= index; i--) {
+ elementData[i+1] = elementData[i];
+ }
+
+ elementData[index] = o;
+ size++;
+ }
+
+ @Override
+ public Object get(int index) {
+ return elementData[index];
+ }
+
+ @Override
+ public Object remove(int index) {
+ if (index > size) {
+ return null;
+ };
+
+ int moveSize = size - index - 1;
+
+ if (moveSize > 0) {
+ System.arraycopy(elementData, index + 1, elementData, index, size - index - 1);
+ }
+ elementData[--size] = null;
+
+ //for(int i = index; i < elementData.length; i++) {
+ // elementData[i] = elementData[i+1];
+ //}
+
+ return elementData;
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ public Iterator iterator(){
+ return new ArrayListIterator();
+ }
+
+ private class ArrayListIterator implements Iterator {
+
+ private int currentIndex = 0;
+
+ @Override
+ public boolean hasNext() {
+ if(currentIndex >= size) return false;
+ else return true;
+ }
+
+ @Override
+ public Object next() {
+ Object o = elementData[currentIndex];
+ currentIndex ++;
+ return o;
+ }
+ }
+
+}
diff --git a/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/BinaryTreeNode.java b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/BinaryTreeNode.java
new file mode 100644
index 0000000000..354b2ba7a0
--- /dev/null
+++ b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/BinaryTreeNode.java
@@ -0,0 +1,32 @@
+package com.github.Ven13.coding2017.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/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/Iterator.java b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/Iterator.java
new file mode 100644
index 0000000000..3cf6540e5e
--- /dev/null
+++ b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/Iterator.java
@@ -0,0 +1,7 @@
+package com.github.Ven13.coding2017.basic;
+
+public interface Iterator {
+ public boolean hasNext();
+ public Object next();
+
+}
diff --git a/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/LinkedList.java b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/LinkedList.java
new file mode 100644
index 0000000000..adf30d89c2
--- /dev/null
+++ b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/LinkedList.java
@@ -0,0 +1,173 @@
+package com.github.Ven13.coding2017.basic;
+
+public class LinkedList implements List {
+
+ //ʾij
+ private int size;
+
+ //ͷԪ
+ private Node head;
+ //βԪ
+ private Node tail;
+
+ //ʹڲʵÿһڵ㣬ÿڵһָһԪصnextԼdata
+ private static class Node {
+ public Object data;
+ public Node next;
+
+ public Node(Object data) {
+ this.data = data;
+ }
+ }
+
+ //Ĺ췽
+ public LinkedList() {
+ }
+
+ @Override
+ public void add(Object o) {
+ add(size, o);
+ }
+
+ @Override
+ public void add(int index, Object o) {
+ if(index == 0) {
+ addFirst(o);
+ } else {
+ if(index >= size) {
+ addLast(o);
+ } else {
+ Node node = head;
+ for (int i = 1; i < index; i++) {
+ head = head.next;
+ }
+ Node nextNode = node.next;
+ Node temp = new Node(o);
+ node.next = temp;
+ temp.next = nextNode;
+ size++;
+ }
+ }
+ }
+
+ //ǰ
+ public void addFirst(Object o) {
+ Node newNode = new Node(o);
+ newNode.next = head;
+ head = newNode;
+ size++;
+ if(tail == null) {
+ tail = head;
+ }
+ }
+
+ //Ӻ
+ public void addLast(Object o) {
+ if(tail == null) {
+ tail = head = new Node(o);
+ } else {
+ Node newNode = new Node(o);
+ tail.next = newNode;
+ tail = tail.next;
+ }
+ size++;
+ }
+
+
+ @Override
+ public Object get(int index) {
+ Node node = head;
+ for(int i = 0; i < index; i++) {
+ node = node.next;
+ }
+ return node.data;
+ }
+
+ @Override
+ public Object remove(int index) {
+ if(size == 0) {
+ throw new java.util.NoSuchElementException();
+ }
+ if(index == 0) {
+ Node node = head;
+ Node temp = node.next;
+ head = temp;
+ size--;
+ return node.data;
+ } else {
+ if(index >= size) {
+ throw new java.util.NoSuchElementException();
+ } else {
+ Node node = head;
+ for(int i = 1; i < index; i++) {
+ node = node.next;
+ }
+ Node temp = node.next;
+ node.next = temp.next;
+ size--;
+ return node.data;
+ }
+ }
+
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ public Object removeFirst() {
+ //ͨͷָ봴ͷڵ
+ Node hNode = head;
+ if (hNode == null) {
+ throw new java.util.NoSuchElementException();
+ }
+ Node nNode = hNode.next;
+ Object element = hNode.data;
+
+ //Ƴ
+ hNode.data = null;
+ hNode.next = null;
+ head = nNode;
+ //жǷΪβڵ
+ if (nNode == null) {
+ tail = null;
+ }else {
+ nNode = null;
+ }
+ size --;
+ return element;
+ }
+
+ public Object removeLast() {
+ return remove(size - 1);
+ }
+
+ public Iterator iterator() {
+ return new LinkedListIterator();
+ }
+
+ private class LinkedListIterator implements Iterator {
+
+ private Node node = head.next;
+
+ @Override
+ public boolean hasNext() {
+ return node != tail;
+ }
+
+ @Override
+ public Object next() {
+
+ if(!hasNext()) {
+ throw new java.util.NoSuchElementException();
+ }
+ Object nextData = node.data;
+ node = node.next;
+ return nextData;
+ }
+
+ }
+
+
+}
diff --git a/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/List.java b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/List.java
new file mode 100644
index 0000000000..02e4297a33
--- /dev/null
+++ b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/List.java
@@ -0,0 +1,11 @@
+package com.github.Ven13.coding2017.basic;
+
+public interface List {
+ public void add(Object o);
+ public void add(int index, Object o);
+ public Object get(int index);
+ public Object remove(int index);
+ public int size();
+
+ public Iterator iterator();
+}
diff --git a/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/Queue.java b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/Queue.java
new file mode 100644
index 0000000000..112299b5e9
--- /dev/null
+++ b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/Queue.java
@@ -0,0 +1,30 @@
+package com.github.Ven13.coding2017.basic;
+
+public class Queue {
+
+ private LinkedList list = new LinkedList();
+ private int size = 0;
+
+ public void enQueue(Object o){
+ size++;
+ list.addLast(o);
+ }
+
+ public Object deQueue(){
+ size--;
+ return list.removeFirst();
+ }
+
+ public boolean isEmpty(){
+ if(size == 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public int size(){
+ return size;
+ }
+
+}
diff --git a/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/Stack.java b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/Stack.java
new file mode 100644
index 0000000000..c0a2658bb3
--- /dev/null
+++ b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/Stack.java
@@ -0,0 +1,30 @@
+package com.github.Ven13.coding2017.basic;
+
+public class Stack {
+ private ArrayList elementData = new ArrayList();
+
+ public void push(Object o){
+
+ elementData.add(o);
+ }
+
+ public Object pop(){
+ Object o = null;
+ if(elementData.size() > 0) {
+ o = elementData.get(elementData.size() - 1);
+ elementData.remove(elementData.size() - 1);
+ }
+ return o;
+ }
+
+ public Object peek(){
+ return elementData.get(0);
+ }
+ public boolean isEmpty(){
+ return elementData.size() == 0;
+ }
+ public int size(){
+ return elementData.size();
+ }
+
+}
diff --git a/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/test/ArrayListTest.java b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/test/ArrayListTest.java
new file mode 100644
index 0000000000..7f3f179f3b
--- /dev/null
+++ b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/test/ArrayListTest.java
@@ -0,0 +1,11 @@
+package com.github.Ven13.coding2017.basic.test;
+
+import org.junit.Before;
+
+import com.github.Ven13.coding2017.basic.*;
+
+public class ArrayListTest extends ListTest{
+
+
+
+}
diff --git a/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/test/LinkedListTest.java b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/test/LinkedListTest.java
new file mode 100644
index 0000000000..c6bc65698c
--- /dev/null
+++ b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/test/LinkedListTest.java
@@ -0,0 +1,100 @@
+package com.github.Ven13.coding2017.basic.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.github.Ven13.coding2017.basic.ArrayList;
+import com.github.Ven13.coding2017.basic.LinkedList;
+import com.github.Ven13.coding2017.basic.List;
+
+public class LinkedListTest extends ListTest {
+
+private LinkedList aLinkedList;
+
+ @Before
+ public void setUpLinkedList() {
+ List aList = new ArrayList();
+ aList = new LinkedList();
+ aLinkedList = new LinkedList();
+ }
+
+ @Test
+ public void testAddFirst() {
+ aLinkedList.addFirst(5);
+ assertEquals(5, aLinkedList.get(0));
+
+ aLinkedList.addFirst(6);
+ assertEquals(6, aLinkedList.get(0));
+ assertEquals(5, aLinkedList.get(1));
+ assertEquals(2, aLinkedList.size());
+ }
+
+ @Test
+ public void testAddLast() {
+ aLinkedList.addLast("hello");
+ assertEquals("hello", aLinkedList.get(0));
+
+ aLinkedList.addLast("world");
+ assertEquals("hello", aLinkedList.get(0));
+ assertEquals("world", aLinkedList.get(1));
+ assertEquals(2, aLinkedList.size());
+ }
+
+ @Test
+ public void testRemoveFirst() {
+ aLinkedList.addLast("hello");
+ aLinkedList.addLast("world");
+
+ aLinkedList.removeFirst();
+ assertEquals("world", aLinkedList.get(0));
+ assertEquals(1, aLinkedList.size());
+
+ aLinkedList.removeFirst();
+ assertEquals(0, aLinkedList.size());
+ }
+
+ @Test
+ public void testRemoveLast() {
+ aLinkedList.addFirst("world");
+ aLinkedList.addFirst("hello");
+
+ aLinkedList.removeLast();
+ //assertEquals("hello", aLinkedList.get(0));
+ assertEquals(1, aLinkedList.size());
+
+ aLinkedList.removeLast();
+ assertEquals(0, aLinkedList.size());
+ }
+
+ @Test
+ public void testLinkedListFunctional() {
+ for (int i = 1; i < 4; i++) {
+ aLinkedList.add(i); // [1,2,3]
+ }
+ aLinkedList.remove(1); // [1,3]
+
+ aLinkedList.add(1, 0); // [1,0,3]
+ for (int i=4; i<6; i++) {
+ aLinkedList.addFirst(i); // [5, 4, 1, 0, 3]
+ }
+ assertEquals(5, aLinkedList.size());
+ assertEquals(5, aLinkedList.get(0));
+ assertEquals(1, aLinkedList.get(2));
+ assertEquals(0, aLinkedList.get(3));
+
+
+ aLinkedList.remove(3); // [5, 4, 1, 3]
+ assertEquals(3, aLinkedList.get(aLinkedList.size()-1));
+ aLinkedList.removeLast(); // [5, 4, 1]
+ assertEquals(1, aLinkedList.get(aLinkedList.size()-1));
+ aLinkedList.removeFirst(); // [4,1]
+
+ assertEquals(4, aLinkedList.get(0));
+ assertEquals(1, aLinkedList.get(1));
+ assertEquals(2, aLinkedList.size());
+
+ }
+
+}
diff --git a/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/test/ListTest.java b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/test/ListTest.java
new file mode 100644
index 0000000000..6959da0421
--- /dev/null
+++ b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/test/ListTest.java
@@ -0,0 +1,129 @@
+package com.github.Ven13.coding2017.basic.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.*;
+
+import com.github.Ven13.coding2017.basic.ArrayList;
+import com.github.Ven13.coding2017.basic.Iterator;
+import com.github.Ven13.coding2017.basic.List;
+
+public class ListTest {
+
+ //protected static List aList;
+
+ @Test
+ public void testFunctional() {
+
+ List aList = new ArrayList();
+
+ aList.add(1);
+ aList.add(2);
+ assertEquals(1, aList.get(0));
+ assertEquals(2, aList.get(1));
+
+ aList.add(3);
+ aList.add(0, 5);
+ aList.add(2, 11);
+ assertEquals(5, aList.get(0));
+ assertEquals(11, aList.get(2));
+
+ aList.add("hi");
+ assertEquals("hi", aList.get(5));
+ assertEquals(6, aList.size());
+
+ aList.remove(1);
+ assertEquals(11, aList.get(1));
+ assertEquals(2, aList.get(2));
+
+ assertEquals(5, aList.size());
+ }
+
+ @Test
+ public void testAdd() {
+
+ List aList = new ArrayList();
+
+ for (int i = 0; i < 100; i++) {
+ aList.add(i);
+ }
+
+ assertEquals(0, aList.get(0));
+ assertEquals(99, aList.get(99));
+ assertEquals(44, aList.get(44));
+ }
+
+ @Test
+ public void testRemove() {
+
+ List aList = new ArrayList();
+
+ aList.add(1);
+ aList.add(2);
+ aList.add(3);
+ aList.remove(3);
+ assertEquals(2, aList.size());
+
+ }
+
+ @Test
+ public void testSize() {
+
+ List aList = new ArrayList();
+
+ for (int i = 0; i < 10; i++) {
+ aList.add(i * 2);
+ }
+
+ assertEquals(10, aList.size());
+ }
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
+ @Test
+ public void testException() {
+
+ List aList = new ArrayList();
+
+ expectedEx.expect(Exception.class);
+
+ aList.remove(1);
+ aList.add(3);
+ aList.add(2, 5);
+ }
+
+ @Test
+ public void testIterator() {
+
+ List aList = new ArrayList();
+
+ Iterator it = aList.iterator();
+
+ assertEquals(false, it.hasNext());
+
+ aList.add(1);
+ aList.add(2);
+ aList.add(3);
+
+ it = aList.iterator();
+ assertEquals(true, it.hasNext());
+ assertEquals(1, it.next());
+ assertEquals(2, it.next());
+ assertEquals(3, it.next());
+ assertEquals(false, it.hasNext());
+
+ aList.remove(1);
+ it = aList.iterator();
+ assertEquals(true, it.hasNext());
+ assertEquals(1, it.next());
+ assertEquals(3, it.next());
+ assertEquals(false, it.hasNext());
+
+ expectedEx.expect(Exception.class);
+ it.next();
+ }
+
+}
diff --git a/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/test/QueueTest.java b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/test/QueueTest.java
new file mode 100644
index 0000000000..965610cdce
--- /dev/null
+++ b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/test/QueueTest.java
@@ -0,0 +1,36 @@
+package com.github.Ven13.coding2017.basic.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.github.Ven13.coding2017.basic.Queue;
+
+public class QueueTest {
+
+private Queue queue;
+
+ @Before
+ public void setUpQueue() {
+ queue = new Queue();
+ }
+
+ @Test
+ public void testQueueFunctional() {
+ assertEquals(true, queue.isEmpty());
+ queue.enQueue(4);
+ queue.enQueue(2);
+ assertEquals(2, queue.size());
+ assertEquals(false, queue.isEmpty());
+
+ int i = (Integer)queue.deQueue();
+ assertEquals(4, i);
+ i = (Integer)queue.deQueue();
+ assertEquals(2, i);
+
+ assertEquals(0, queue.size());
+ assertEquals(true, queue.isEmpty());
+ }
+
+}
diff --git a/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/test/StackTest.java b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/test/StackTest.java
new file mode 100644
index 0000000000..9bbf41914f
--- /dev/null
+++ b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/basic/test/StackTest.java
@@ -0,0 +1,40 @@
+package com.github.Ven13.coding2017.basic.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.github.Ven13.coding2017.basic.Stack;
+
+public class StackTest {
+
+private Stack stack;
+
+ @Before
+ public void setUpStack() {
+ stack = new Stack();
+ }
+
+ @Test
+ public void testStackFunctional() {
+ assertEquals(true, stack.isEmpty());
+ stack.push(4);
+ stack.push(2);
+ assertEquals(2, stack.size());
+ assertEquals(false, stack.isEmpty());
+
+ int i = (Integer)stack.pop();
+ assertEquals(2, i);
+
+ i = (Integer)stack.peek();
+ assertEquals(4, i);
+
+ i = (Integer)stack.pop();
+ assertEquals(4, i);
+
+ assertEquals(0, stack.size());
+ assertEquals(true, stack.isEmpty());
+ }
+
+}
diff --git a/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/litestruts/LoginAction.java b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/litestruts/LoginAction.java
new file mode 100644
index 0000000000..d43bc2c452
--- /dev/null
+++ b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/litestruts/LoginAction.java
@@ -0,0 +1,42 @@
+package com.github.Ven13.coding2017.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 void setMessage(String message) {
+ this.message = message;
+ }
+ public String getMessage(){
+ return this.message;
+ }
+}
diff --git a/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/litestruts/Struts.java b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/litestruts/Struts.java
new file mode 100644
index 0000000000..a9040e257d
--- /dev/null
+++ b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/litestruts/Struts.java
@@ -0,0 +1,166 @@
+package com.github.Ven13.coding2017.litestruts;
+
+import java.beans.IntrospectionException;
+import java.beans.PropertyDescriptor;
+import java.io.File;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+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字段中。
+
+ */
+
+ View view = new View();
+
+ Map map = testParseXmlData(actionName, "/struts.xml");
+
+ String className = (String)map.get(actionName);
+
+ String resultName = "";
+ System.out.println(className);
+
+ try {
+ Class c = Class.forName(className);
+ Object obj = c.newInstance();
+ Method method = null;
+
+ for (Map.Entry entry : parameters.entrySet()) {
+ String key = entry.getKey();
+ String value = entry.getValue();
+ PropertyDescriptor pd = new PropertyDescriptor(key, c);
+ Method setMethod = pd.getWriteMethod();
+ setMethod.invoke(obj, value);
+ }
+
+ Method exec = c.getDeclaredMethod("execute");
+ Object res = exec.invoke(obj);
+ if(res != null) {
+ resultName = (String)map.get(actionName + '|' + res);
+ view.setJsp(resultName);
+ }
+ Field[] fields = c.getDeclaredFields();
+ for(Field f : fields){
+ PropertyDescriptor descriptor = new PropertyDescriptor(f.getName(), c);
+ Method getMethod = descriptor.getReadMethod();
+ Object value = getMethod.invoke(obj);
+ parameters.put(f.getName(), (String)value);
+ }
+ view.setParameters(parameters);
+
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ } catch (IntrospectionException e) {
+ System.out.println(e.toString());
+ e.printStackTrace();
+ }
+
+
+ return view;
+ }
+
+ public static Document parse2Document(String xmlFilePath){
+ SAXReader reader = new SAXReader();
+ Document doc = null;
+ try {
+ InputStream inputStream = Class.class.getResourceAsStream(xmlFilePath);
+ doc = reader.read(inputStream);
+ } catch (DocumentException e) {
+ e.printStackTrace();
+ }
+ return doc;
+ }
+
+ public static Map testParseXmlData(String actionName, String xmlFilePath){
+ //获取xml解析器对象
+ //SAXReader reader = new SAXReader();
+ //将xml解析为Document对象
+ Document doc = parse2Document(xmlFilePath);
+ //获取文档的根元素
+ Element root = doc.getRootElement();
+
+ //定义保存属性、值的map
+ Map map = new HashMap();
+
+
+ //遍历当前元素(在此是根元素)的子元素
+
+ for (Iterator i_pe = root.elementIterator(); i_pe.hasNext();) {
+
+ Element e_pe = (Element) i_pe.next();
+ //获取当前元素的名字
+ String act = e_pe.getName();
+ //获取当前元素的name和class属性的值并分别赋给attName,attClass变量
+ System.out.println(act);
+ String attName = e_pe.attributeValue("name");
+ String attClass = e_pe.attributeValue("class");
+ if (attName.equals(actionName)) {
+ map.put(attName, attClass);
+
+ //Element e_res = e_pe.element("result");
+ //System.out.println(e_res.getName());
+ for (Iterator i_res = e_pe.elementIterator(); i_res.hasNext();) {
+
+ Element e_re = (Element) i_res.next();
+ //获取当前元素的名字
+ String person_n = e_re.getName();
+ //获取当前元素的name和class属性的值并分别赋给attName,attClass变量
+ System.out.println(person_n);
+ String resName = e_re.attributeValue("name");
+ String resClass = e_re.getStringValue();
+ map.put(attName + '|' + resName, resClass);
+
+ }
+ }
+ }
+
+ return map;
+
+ }
+
+}
diff --git a/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/litestruts/StrutsTest.java b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/litestruts/StrutsTest.java
new file mode 100644
index 0000000000..a5a777be1c
--- /dev/null
+++ b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/litestruts/StrutsTest.java
@@ -0,0 +1,43 @@
+package com.github.Ven13.coding2017.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/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/litestruts/View.java b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/litestruts/View.java
new file mode 100644
index 0000000000..2b0997095c
--- /dev/null
+++ b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/litestruts/View.java
@@ -0,0 +1,23 @@
+package com.github.Ven13.coding2017.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/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/litestruts/struts.xml b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/litestruts/struts.xml
new file mode 100644
index 0000000000..59ec89bb69
--- /dev/null
+++ b/group02/106614649/106614649Learnin/src/com/github/Ven13/coding2017/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/group02/106614649/106614649Learnin/src/struts.xml b/group02/106614649/106614649Learnin/src/struts.xml
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/ArrayList.java b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/ArrayList.java
new file mode 100644
index 0000000000..133db97491
--- /dev/null
+++ b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/ArrayList.java
@@ -0,0 +1,105 @@
+package com.github.FelixCJF.coding2017.basic;
+
+
+public class ArrayList implements List {
+
+ private int size = 0;
+
+ private Object[] elementData = new Object[100];
+
+ public void add(Object o){
+ //容量增加
+ ensureCapacity(size + 1);
+ //添加
+ elementData[size ++] = o;
+ }
+
+ public void add(int index, Object o){
+
+ //检查是否越界
+ rangeCheck(index);
+ // 进行扩容检查
+ ensureCapacity(size + 1);
+ // 对数组进行复制处理,目的就是空出index的位置插入element,并将index后的元素位移一个位置
+ System. arraycopy(elementData, index, elementData, index + 1,
+ size - index);
+ // 将指定的index位置赋值为Object o
+ elementData[index] = o;
+ // 自增一位长度
+ size++;
+ }
+
+ public Object get(int index){
+ rangeCheck(index);
+ return elementData[index];
+ }
+
+ public Object remove(int index){
+ // 数组越界检查
+ rangeCheck(index);
+ // 取出要删除位置的元素,供返回使用
+ Object oldValue = elementData[index];
+ // 计算数组要复制的数量
+ int numMoved = size - index - 1;
+ // 数组复制,就是将index之后的元素往前移动一个位置
+ if (numMoved > 0)
+ System. arraycopy(elementData, index+1, elementData, index,
+ numMoved);
+ // 将数组最后一个元素置空(因为删除了一个元素,然后index后面的元素都向前移动了,所以最后一个就没用了),好让gc尽快回收
+ // 不要忘了size减一
+ elementData[--size] = null;
+ return oldValue;
+ }
+
+ public int size(){
+ return size;
+ }
+
+ public Iterator iterator(){
+ return new ArrayListIterator();
+ }
+
+ //内部类,实现Iterator
+ private class ArrayListIterator implements Iterator{
+
+ private int currentIndex = 0; //当前索引
+
+ public boolean hasNext() {
+ if (currentIndex >= size) {
+ return false;
+ }
+ return true;
+ }
+
+ public Object next() {
+ Object object = elementData[currentIndex];
+ currentIndex ++ ;
+ return object;
+ }
+ }
+ //扩容
+ public void ensureCapacity( int minCapacity) {
+ // 当前数组的长度
+ int oldCapacity = elementData .length;
+ // 最小需要的容量大于当前数组的长度则进行扩容
+ if (minCapacity > oldCapacity) {
+ // 扩容
+ int newCapacity = oldCapacity + (oldCapacity >> 1);
+ // 如果新扩容的数组长度还是比最小需要的容量小,则以最小需要的容量为长度进行扩容
+ if (newCapacity < minCapacity)
+ newCapacity = minCapacity;
+ //数组复制
+ Object[] elementData2 = new Object[newCapacity];
+ for (int i = 0; i < oldCapacity; i++) {
+ elementData2[i] = elementData[i];
+ }
+ elementData = elementData2;
+ }
+ }
+ //检查是否越界
+ private void rangeCheck(int index){
+ if (index < 0 || index >= this.size) {
+ throw new IndexOutOfBoundsException("index :" + index + "size :" + size);
+ }
+ }
+}
diff --git a/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/BinaryTreeNode.java b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/BinaryTreeNode.java
new file mode 100644
index 0000000000..6dccc25dcb
--- /dev/null
+++ b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/BinaryTreeNode.java
@@ -0,0 +1,32 @@
+package com.github.FelixCJF.coding2017.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;
+ }
+
+}
\ No newline at end of file
diff --git a/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/Iterator.java b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/Iterator.java
new file mode 100644
index 0000000000..3a1b9abf8c
--- /dev/null
+++ b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/Iterator.java
@@ -0,0 +1,8 @@
+package com.github.FelixCJF.coding2017.basic;
+
+public interface Iterator {
+
+ public boolean hasNext();
+ public Object next();
+
+}
diff --git a/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/LinkedList.java b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/LinkedList.java
new file mode 100644
index 0000000000..d86e970b8a
--- /dev/null
+++ b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/LinkedList.java
@@ -0,0 +1,214 @@
+package com.github.FelixCJF.coding2017.basic;
+
+import java.util.NoSuchElementException;
+
+public class LinkedList implements List {
+
+ private Node head;//头指针
+ private Node last;//尾指针
+ private int size = 0;
+
+ public void add(Object o){
+ addLast(o);
+ }
+
+ public void add(int index , Object o){
+ //检查是否越界
+ checkIndex(index);
+
+ Node indexNode = node(index);
+
+ if (index == size) {
+ addLast(o);
+ } else {
+ final Node pred = indexNode.prv;
+
+ final Node newNode = new Node();
+ newNode.data = o;
+ newNode.next = indexNode;
+ newNode.prv = pred;
+
+ indexNode.prv = newNode;
+
+ if (pred == null) {
+ head = newNode;
+ } else {
+ pred.next = newNode;
+ }
+ }
+ size ++;
+ }
+ public Object get(int index){
+ //检查是否越界
+ checkIndex(index);
+
+ Node indexNode = node(index);
+
+ return indexNode.data;
+ }
+ public Object remove(int index){
+ //检查是否越界
+ checkIndex(index);
+
+ Node indexNode = node(index);
+ Object element = indexNode.data;
+ Node pre = indexNode.prv;
+ Node next = indexNode.next;
+
+ if (pre == null) {
+ head = next;
+ } else {
+ pre.next = next;
+ indexNode.prv = null;
+ }
+
+ if (next == null) {
+ last = pre;
+ } else {
+ next.prv = pre;
+ indexNode.next = null;
+ }
+
+ indexNode.data = null;
+
+ size --;
+
+ return element;
+ }
+
+ public int size(){
+ return size;
+ }
+
+ public void addFirst(Object o){
+ //节点变量存放原来的头指针
+ final Node oldHead = head;
+ //创建新的节点对象
+ final Node newNode = new Node();
+ newNode.data = o;
+ newNode.next = head;
+ newNode.prv = null;
+ //判断oldhead是否为null
+ if (oldHead == null) {
+ last = newNode;
+ }else {
+ //头指针指向新创建的节点对象
+ oldHead.prv = newNode;
+ }
+ //将newNode变为头指针
+ head = newNode;
+ size ++;
+ }
+ public void addLast(Object o){
+ //节点新变量放原先的尾指针
+ final Node oldLast = last;
+ //创建新节点,加入要添加的对象
+ final Node newNode = new Node();
+ newNode.data = o;
+ newNode.next = null;
+ newNode.prv = oldLast;
+ if (oldLast == null) {
+ head = newNode;
+ } else {
+ //尾指针指向新创建的节点
+ oldLast.next = newNode;
+ }
+ //newNode变为尾指针
+ last = newNode;
+ size++;
+ }
+ public Object removeFirst(){
+ //通过头指针创建头节点
+ final Node hNode = head;
+ if (hNode == null) {
+ throw new NoSuchElementException();
+ }
+ final Node next = hNode.next;
+ final Object element = hNode.data;
+
+ //移除
+ hNode.data = null;
+ hNode.next = null;
+ head = next;
+ //判断是否为尾节点
+ if (next == null) {
+ last = null;
+ }else {
+ next.prv = null;
+ }
+ size --;
+ return element;
+ }
+ public Object removeLast(){
+ //通过尾指针创建节点
+ final Node lastNode = last;
+ if (lastNode == null) {
+ throw new NoSuchElementException();
+ }
+ final Object element = lastNode.data;
+ final Node prve = lastNode.prv;
+
+ //移除
+ lastNode.data = null;
+ lastNode.prv = null;
+ last = prve;
+
+ if (prve == null) {
+ head = null;
+ } else {
+ prve.next = null;
+ }
+ size --;
+ return element;
+ }
+ public Iterator iterator(){
+ return new LinkedListIterator();
+ }
+
+ private class LinkedListIterator implements Iterator{
+
+ private Node currentNode = head;//当前节点
+
+ public boolean hasNext() {
+ if (currentNode == null) {
+ return false;
+ }
+ return true;
+ }
+
+ public Object next() {
+ Object element = currentNode.data;
+ currentNode = currentNode.next;
+ return element;
+ }
+
+ }
+
+ //查找index节点,并返回该节点
+ Node node(int index) {
+ // assert isElementIndex(index);
+
+ if (index < (size >> 1)) {
+ Node x = head;
+ for (int i = 0; i < index; i++)
+ x = x.next;
+ return x;
+ } else {
+ Node x = last;
+ for (int i = size - 1; i > index; i--)
+ x = x.prv;
+ return x;
+ }
+ }
+ //检查索引
+ private void checkIndex(int index){
+ if (index < 0 || index > size) {
+ throw new IndexOutOfBoundsException();
+ }
+ }
+ private static class Node{
+ Object data;
+ Node next;
+ Node prv;
+ }
+}
\ No newline at end of file
diff --git a/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/List.java b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/List.java
new file mode 100644
index 0000000000..ecbb657597
--- /dev/null
+++ b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/List.java
@@ -0,0 +1,11 @@
+package com.github.FelixCJF.coding2017.basic;
+
+
+public interface List {
+ public void add(Object o);
+ public void add(int index, Object o);
+ public Object get(int index);
+ public Object remove(int index);
+ public int size();
+ public Iterator iterator();
+}
\ No newline at end of file
diff --git a/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/Queue.java b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/Queue.java
new file mode 100644
index 0000000000..c2661ce35f
--- /dev/null
+++ b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/Queue.java
@@ -0,0 +1,53 @@
+package com.github.FelixCJF.coding2017.basic;
+
+
+public class Queue {
+
+ private Node head;//头节点
+ private Node last;//尾节点
+ private int size;//记录节点
+
+ public void enQueue(Object o){
+ //设置一个节点变量存放原先的尾节点
+ final Node oldLast = last;
+ //创建一个新的节点
+ Node newNode = new Node();
+ newNode.data = o;
+ newNode.next = null;
+ //添加到队列
+ if (isEmpty()) {
+ head = newNode;
+ } else {
+ oldLast.next = newNode;
+ }
+ //新节点变为尾节点
+ last = newNode;
+ size ++;
+ }
+
+ public Object deQueue(){
+
+ Object object = head.data;
+
+ head = head.next;
+
+ if (isEmpty()) {
+ last = null;
+ }
+ size --;
+ return object;
+ }
+
+ public boolean isEmpty(){
+ return head == null;
+ }
+
+ public int size(){
+ return size;
+ }
+
+ private static class Node{
+ Object data;
+ Node next;
+ }
+}
\ No newline at end of file
diff --git a/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/Stack.java b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/Stack.java
new file mode 100644
index 0000000000..16684f7d92
--- /dev/null
+++ b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/Stack.java
@@ -0,0 +1,34 @@
+package com.github.FelixCJF.coding2017.basic;
+
+import java.util.EmptyStackException;
+
+public class Stack {
+
+ //存放栈内元素的容器
+ private ArrayList elementData = new ArrayList();
+ //记录栈内元素个数
+
+ public void push(Object o){
+ elementData.add(o);
+ }
+
+ public Object pop(){
+ if (isEmpty()) {
+ throw new EmptyStackException();
+ }
+ return elementData.remove(elementData.size() - 1);
+ }
+
+ public Object peek(){
+ if (isEmpty()) {
+ throw new EmptyStackException();
+ }
+ return elementData.get(elementData.size() - 1);
+ }
+ public boolean isEmpty(){
+ return elementData.size() == 0;
+ }
+ public int size(){
+ return elementData.size();
+ }
+}
diff --git a/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/test/ArrayListTest.java b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/test/ArrayListTest.java
new file mode 100644
index 0000000000..9484ce1527
--- /dev/null
+++ b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/test/ArrayListTest.java
@@ -0,0 +1,14 @@
+package com.github.FelixCJF.coding2017.basic.test;
+
+import org.junit.Before;
+
+import com.github.FelixCJF.coding2017.basic.ArrayList;
+
+public class ArrayListTest extends ListTest {
+
+/* @Before
+ public void setUpArrayList() {
+ aList = new ArrayList();
+ }*/
+
+}
diff --git a/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/test/LinkedListTest.java b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/test/LinkedListTest.java
new file mode 100644
index 0000000000..ce0c0d1c0d
--- /dev/null
+++ b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/test/LinkedListTest.java
@@ -0,0 +1,100 @@
+package com.github.FelixCJF.coding2017.basic.test;
+
+
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.github.FelixCJF.coding2017.basic.ArrayList;
+import com.github.FelixCJF.coding2017.basic.LinkedList;
+import com.github.FelixCJF.coding2017.basic.List;
+
+public class LinkedListTest extends ListTest{
+
+ private LinkedList aLinkedList;
+
+ @Before
+ public void setUpLinkedList() {
+ List aList = new ArrayList();
+ aList = new LinkedList();
+ aLinkedList = new LinkedList();
+ }
+
+ @Test
+ public void testAddFirst() {
+ aLinkedList.addFirst(5);
+ assertEquals(5, aLinkedList.get(0));
+
+ aLinkedList.addFirst(6);
+ assertEquals(6, aLinkedList.get(0));
+ assertEquals(5, aLinkedList.get(1));
+ assertEquals(2, aLinkedList.size());
+ }
+
+ @Test
+ public void testAddLast() {
+ aLinkedList.addLast("hello");
+ assertEquals("hello", aLinkedList.get(0));
+
+ aLinkedList.addLast("world");
+ assertEquals("hello", aLinkedList.get(0));
+ assertEquals("world", aLinkedList.get(1));
+ assertEquals(2, aLinkedList.size());
+ }
+
+ @Test
+ public void testRemoveFirst() {
+ aLinkedList.addLast("hello");
+ aLinkedList.addLast("world");
+
+ aLinkedList.removeFirst();
+ assertEquals("world", aLinkedList.get(0));
+ assertEquals(1, aLinkedList.size());
+
+ aLinkedList.removeFirst();
+ assertEquals(0, aLinkedList.size());
+ }
+
+ @Test
+ public void testRemoveLast() {
+ aLinkedList.addFirst("world");
+ aLinkedList.addFirst("hello");
+
+ aLinkedList.removeLast();
+ assertEquals("hello", aLinkedList.get(0));
+ assertEquals(1, aLinkedList.size());
+
+ aLinkedList.removeLast();
+ assertEquals(0, aLinkedList.size());
+ }
+
+ @Test
+ public void testLinkedListFunctional() {
+ for (int i=1; i<4; i++) {
+ aLinkedList.add(i); // [1,2,3]
+ }
+ aLinkedList.remove(1); // [1,3]
+
+ aLinkedList.add(1, 0); // [1,0,3]
+ for (int i=4; i<6; i++) {
+ aLinkedList.addFirst(i); // [5, 4, 1, 0, 3]
+ }
+ assertEquals(5, aLinkedList.size());
+ assertEquals(5, aLinkedList.get(0));
+ assertEquals(1, aLinkedList.get(2));
+ assertEquals(0, aLinkedList.get(3));
+
+ aLinkedList.remove(3); // [5, 4, 1, 3]
+ assertEquals(3, aLinkedList.get(aLinkedList.size()-1));
+ aLinkedList.removeLast(); // [5, 4, 1]
+ assertEquals(1, aLinkedList.get(aLinkedList.size()-1));
+ aLinkedList.removeFirst(); // [4,1]
+
+ assertEquals(4, aLinkedList.get(0));
+ assertEquals(1, aLinkedList.get(1));
+ assertEquals(2, aLinkedList.size());
+ }
+
+}
diff --git a/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/test/ListTest.java b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/test/ListTest.java
new file mode 100644
index 0000000000..b970372bbe
--- /dev/null
+++ b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/test/ListTest.java
@@ -0,0 +1,124 @@
+package com.github.FelixCJF.coding2017.basic.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import com.github.FelixCJF.coding2017.basic.ArrayList;
+import com.github.FelixCJF.coding2017.basic.Iterator;
+import com.github.FelixCJF.coding2017.basic.List;
+
+public class ListTest {
+
+
+ //protected static List aList = new ArrayList();
+
+ @Test
+ public void testFunctional() {
+ List aList = new ArrayList();
+ aList.add(1);
+ aList.add(2);
+ assertEquals(1, aList.get(0));
+ assertEquals(2, aList.get(1));
+
+ aList.add(3);
+ aList.add(0, 5);
+ aList.add(2, 11);
+ assertEquals(5, aList.get(0));
+ assertEquals(11, aList.get(2));
+
+ aList.add("hi");
+ assertEquals("hi", aList.get(5));
+ assertEquals(6, aList.size());
+
+ aList.remove(1);
+ assertEquals(11, aList.get(1));
+ assertEquals(2, aList.get(2));
+
+ assertEquals(5, aList.size());
+ }
+
+ @Test
+ public void testAdd() {
+ List aList = new ArrayList();
+ for (int i=0; i<100; i++)
+ aList.add(i);
+ assertEquals(0, aList.get(0));
+ assertEquals(99, aList.get(99));
+ assertEquals(44, aList.get(44));
+ }
+
+ @Test
+ public void testRemove() {
+ List aList = new ArrayList();
+ aList.add(1);
+ aList.add(2);
+ aList.add(3);
+ int u = (Integer)aList.remove(2);
+ assertEquals(3, u);
+ assertEquals(2, aList.size());
+
+ aList.add(1, 5);
+ u = (Integer)aList.remove(0);
+ assertEquals(1, u);
+ assertEquals(5, aList.get(0));
+ assertEquals(2, aList.get(1));
+ assertEquals(2, aList.size());
+
+ aList.remove(0);
+ aList.remove(0);
+ assertEquals(0, aList.size());
+
+
+ }
+
+ @Test
+ public void testSize() {
+ List aList = new ArrayList();
+ for (int i=0; i<10; i++)
+ aList.add(i*2);
+ assertEquals(10, aList.size());
+ }
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
+ @Test
+ public void testException() {
+ List aList = new ArrayList();
+ expectedEx.expect(Exception.class);
+
+ aList.remove(1);
+ aList.add(3);
+ aList.add(2, 5);
+ expectedEx.expect(Exception.class);
+ }
+
+ @Test
+ public void testIterator() {
+ List aList = new ArrayList();
+ Iterator it = aList.iterator();
+ assertEquals(false, it.hasNext());
+
+ aList.add(1);
+ aList.add(2);
+ aList.add(3);
+
+ it = aList.iterator();
+ assertEquals(true, it.hasNext());
+ assertEquals(1, it.next());
+ assertEquals(2, it.next());
+ assertEquals(3, it.next());
+ assertEquals(false, it.hasNext());
+
+ aList.remove(1);
+ it = aList.iterator();
+ assertEquals(true, it.hasNext());
+ assertEquals(1, it.next());
+ assertEquals(3, it.next());
+ assertEquals(false, it.hasNext());
+ }
+
+}
diff --git a/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/test/QueueTest.java b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/test/QueueTest.java
new file mode 100644
index 0000000000..49506c2b35
--- /dev/null
+++ b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/test/QueueTest.java
@@ -0,0 +1,34 @@
+package com.github.FelixCJF.coding2017.basic.test;
+
+import static org.junit.Assert.*;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.github.FelixCJF.coding2017.basic.Queue;
+
+public class QueueTest {
+ private Queue queue;
+
+ @Before
+ public void setUpQueue() {
+ queue = new Queue();
+ }
+
+ @Test
+ public void testQueueFunctional() {
+ assertEquals(true, queue.isEmpty());
+ queue.enQueue(4);
+ queue.enQueue(2);
+ assertEquals(2, queue.size());
+ assertEquals(false, queue.isEmpty());
+
+ int i = (Integer)queue.deQueue();
+ assertEquals(4, i);
+ i = (Integer)queue.deQueue();
+ assertEquals(2, i);
+
+ assertEquals(0, queue.size());
+ assertEquals(true, queue.isEmpty());
+ }
+
+}
diff --git a/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/test/StackTest.java b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/test/StackTest.java
new file mode 100644
index 0000000000..6bb53571a5
--- /dev/null
+++ b/group02/1554421063/src/com/github/FelixCJF/coding2017/basic/test/StackTest.java
@@ -0,0 +1,41 @@
+package com.github.FelixCJF.coding2017.basic.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.github.FelixCJF.coding2017.basic.Stack;
+
+
+public class StackTest {
+
+ private Stack stack;
+
+ @Before
+ public void setUpStack() {
+ stack = new Stack();
+ }
+
+ @Test
+ public void testStackFunctional() {
+ assertEquals(true, stack.isEmpty());
+ stack.push(4);
+ stack.push(2);
+ assertEquals(2, stack.size());
+ assertEquals(false, stack.isEmpty());
+
+ int i = (Integer)stack.pop();
+ assertEquals(2, i);
+
+ i = (Integer)stack.peek();
+ assertEquals(4, i);
+
+ i = (Integer)stack.pop();
+ assertEquals(4, i);
+
+ assertEquals(0, stack.size());
+ assertEquals(true, stack.isEmpty());
+ }
+
+}
diff --git a/group02/1554421063/src/com/github/FelixCJF/coding2017/coderising/array/ArrayUtil.java b/group02/1554421063/src/com/github/FelixCJF/coding2017/coderising/array/ArrayUtil.java
new file mode 100644
index 0000000000..f60be05977
--- /dev/null
+++ b/group02/1554421063/src/com/github/FelixCJF/coding2017/coderising/array/ArrayUtil.java
@@ -0,0 +1,228 @@
+package com.github.FelixCJF.coding2017.coderising.array;
+
+import java.util.ArrayList;
+
+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 array[] = new int[origin.length];
+ for (int i = 0; i newArr[i+1]) {
+ int temp = newArr[i];
+ newArr[i] = newArr[i+1];
+ newArr[i + 1] = temp;
+ }
+ }
+ return newArr;
+ }
+ /**
+ * 把一个已经存满数据的数组 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){
+ int newArr[] = new int[oldArray.length + size];
+ System.arraycopy(oldArray, 0, newArr, 0, oldArray.length);
+ return newArr;
+ }
+
+ /**
+ * 斐波那契数列为: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[] newArr;
+ int f1 = 0;
+ int f2 = 1;
+ int f = 0;
+ if (max < 2) {
+ return newArr = new int[0];
+ }
+ ArrayList list = new ArrayList();
+ for (int i = 2; f < max; i++) {
+ list.add(f2);
+ f = f1 + f2;
+ f1 = f2;
+ f2 = f;
+ }
+ newArr = new int[list.size()];
+ for (int i = 0; i < newArr.length; i++) {
+ newArr[i] = (int) list.get(i);
+ }
+ return newArr;
+ }
+
+ /**
+ * 返回小于给定最大值max的所有素数数组
+ * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ * @param max
+ * @return
+ */
+ public int[] getPrimes(int max){
+
+ ArrayList list = new ArrayList();
+
+ for (int i = 1; i < max; i++) {
+ if (isPrime(i)) {
+ list.add(i);
+ }
+ }
+ int[] newArr = new int[list.size()];
+ for (int i = 0; i < newArr.length; i++) {
+ newArr[i] = (int) list.get(i);
+ }
+ return newArr;
+ }
+ //判断是否为素数
+ private boolean isPrime(int a) {
+
+ boolean flag = true;
+
+ if (a < 2) {// 素数不小于2
+ return false;
+ } else {
+
+ for (int i = 2; i <= Math.sqrt(a); i++) {
+
+ if (a % i == 0) {// 若能被整除,则说明不是素数,返回false
+
+ flag = false;
+ break;// 跳出循环
+ }
+ }
+ }
+ return flag;
+ }
+
+ /**
+ * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
+ * 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
+ * @param max
+ * @return
+ */
+ public int[] getPerfectNumbers(int max){
+ int[] newArr;
+ if (max == 0) {
+ return newArr = new int[0];
+ }
+ ArrayList list = new ArrayList();
+ for (int i = 1; i < max; i++) {
+ if (isWanshu(i)) {
+ list.add(i);
+ }
+ }
+ newArr = new int[list.size()];
+ for (int i = 0; i < newArr.length; i++) {
+ newArr[i] = (int) list.get(i);
+ }
+ return newArr;
+ }
+ //判断一个数是不是完数
+ private boolean isWanshu(int n)
+ {
+ boolean flag=false;
+ int i,sum=0;
+ for(i=1;i<=n/2;i++)
+ {
+ if(n%i==0)
+ {
+ sum+=i;
+ }
+ }
+ if(sum==n)
+ {
+ flag=true;
+ }
+ return flag;
+ }
+ /**
+ * 用seperator 把数组 array给连接起来
+ * 例如array= [3,8,9], seperator = "-"
+ * 则返回值为"3-8-9"
+ * @param array
+ * @param s
+ * @return
+ */
+ public String join(int[] array, String seperator){
+ String string = "";
+ for (int i = 0; i < array.length; i++) {
+ if (i == array.length - 1) {
+ string += array[i];
+ } else {
+ string += array[i] + seperator;
+ }
+ }
+ return string;
+ }
+
+
+}
diff --git a/group02/1554421063/src/com/github/FelixCJF/coding2017/coderising/array/test/ArrayUtilTest.java b/group02/1554421063/src/com/github/FelixCJF/coding2017/coderising/array/test/ArrayUtilTest.java
new file mode 100644
index 0000000000..378e052164
--- /dev/null
+++ b/group02/1554421063/src/com/github/FelixCJF/coding2017/coderising/array/test/ArrayUtilTest.java
@@ -0,0 +1,148 @@
+package com.github.FelixCJF.coding2017.coderising.array.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import com.github.FelixCJF.coding2017.coderising.array.ArrayUtil;
+
+
+public class ArrayUtilTest
+{
+ private ArrayUtil myArray;
+ @Before
+ public void setUp() throws Exception
+ {
+ myArray = new ArrayUtil();
+ }
+
+ @Test
+ public void testReverseArray()
+ {
+ int[] a = {1, 2, 1, 3, 5, 6};
+ int[] b = {6, 5, 3, 1, 2, 1};
+ int[] c = new int[0];
+
+ myArray.reverseArray(a);
+ assertArrayEquals(a, b);
+
+ //对空数组进行反转
+ myArray.reverseArray(c);
+ assertArrayEquals(c, new int[0]);
+ }
+
+ @Test
+ public void testRemoveZero()
+ {
+ int[] oldArr= {1, 3, 4, 5, 0, 0, 6, 6, 0, 5, 4, 7, 6, 7, 1, 2, 0, 5};
+ int b[] = {1, 3, 4, 5, 6, 6, 5, 4, 7, 6, 7, 1, 2, 5};
+ int[] c = myArray.removeZero(oldArr);
+ assertArrayEquals(b, c);
+
+ int[] d = new int[0];
+ assertArrayEquals(d, new int[0]);
+ }
+
+ @Test
+ public void testMerge()
+ {
+ int a1[] = {1, 2, 3, 4, 5};
+ int b1[] = {3, 4, 5, 6, 7, 8};
+ int c1[] = {1, 2, 3, 4, 5, 6, 7, 8};
+ int[] newArray1 = myArray.merge(a1, b1);
+ assertArrayEquals(c1, newArray1);
+
+ int a2[] = new int[0];
+ int b2[] = {0, 2, 3, 6, 7, 8};
+ int c2[] = {0, 2, 3, 6, 7, 8};
+ int[] newArray2 = myArray.merge(a2, b2);
+ assertArrayEquals(c2, newArray2);
+
+ int a3[] = {0, 2, 3, 6, 7, 8};
+ int b3[] = new int[0];
+ int c3[] = {0, 2, 3, 6, 7, 8};
+ int[] newArray3 = myArray.merge(a3, b3);
+ assertArrayEquals(c3, newArray3);
+
+ int[] a4 = new int[0];
+ int[] b4 = new int[0];
+ int[] newArray4 = myArray.merge(a4, b4);
+ assertArrayEquals(new int[0], newArray4);
+ }
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+ @Test
+ public void testGrow()
+ {
+ int[] a = {3, 5, 7, 8, 9};
+ int[] b = {3, 5, 7, 8, 9, 0, 0, 0};
+ int[] newArray = myArray.grow(a, 3);
+ assertArrayEquals(b, newArray);
+
+ // size < 0 抛出异常
+ expectedEx.expect(Exception.class);
+ int[] newArray1 = myArray.grow(a, -3);
+ assertArrayEquals(b, newArray1);
+
+ }
+
+ @Test
+ public void testFibonacci()
+ {
+ //max == 1时返回空数组
+ int[] array1 = myArray.fibonacci(1);
+ int[] b = new int[0];
+ assertArrayEquals(array1, b);
+
+
+ int[] array2= myArray.fibonacci(35);
+ int[] c = {1, 1, 2, 3, 5, 8, 13, 21, 34 };
+ assertArrayEquals(c, array2);
+ }
+
+ @Test
+ public void testGetPrimes()
+ {
+ int[] a = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };
+ int[] array1 = myArray.getPrimes(35);
+ assertArrayEquals(a, array1);
+
+ //max <= 2的时候没有素数,数组为空数组 new int[0]
+ int[] array2 = myArray.getPrimes(1);
+ int[] b = new int[0];
+ assertArrayEquals(array2, b);
+ }
+
+ @Test
+ public void testGetPerfectNumbers()
+ {
+ int[] array = myArray.getPerfectNumbers(10000);
+ int[] a = {6, 28, 496, 8128 };
+ assertArrayEquals(a, array);
+ }
+
+ @Test
+ public void testJoin()
+ {
+ int[] Array0 = {3, 5, 7, 8, 9};
+ String s0 = myArray.join(Array0, "-");
+ String s1 = "3-5-7-8-9";
+ assertEquals(s1, s0);
+
+ int[] Array1 = {3};
+ String s2 = myArray.join(Array1, "-");
+ String s3 = "3";
+ assertEquals(s2, s3);
+
+ //传递空数组时,返回空数组
+ int[] Array2 = new int[0];
+ String s4 = myArray.join(Array2, "-");
+ String s5 = "";
+ assertEquals(s4, s5);
+ }
+
+}
diff --git a/group02/1554421063/src/com/github/FelixCJF/coding2017/coderising/litestruts/LoginAction.java b/group02/1554421063/src/com/github/FelixCJF/coding2017/coderising/litestruts/LoginAction.java
new file mode 100644
index 0000000000..dcdbe226ed
--- /dev/null
+++ b/group02/1554421063/src/com/github/FelixCJF/coding2017/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/group02/1554421063/src/com/github/FelixCJF/coding2017/coderising/litestruts/Struts.java b/group02/1554421063/src/com/github/FelixCJF/coding2017/coderising/litestruts/Struts.java
new file mode 100644
index 0000000000..85e2e22de3
--- /dev/null
+++ b/group02/1554421063/src/com/github/FelixCJF/coding2017/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/group02/1554421063/src/com/github/FelixCJF/coding2017/coderising/litestruts/StrutsTest.java b/group02/1554421063/src/com/github/FelixCJF/coding2017/coderising/litestruts/StrutsTest.java
new file mode 100644
index 0000000000..b8c81faf3c
--- /dev/null
+++ b/group02/1554421063/src/com/github/FelixCJF/coding2017/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/group02/1554421063/src/com/github/FelixCJF/coding2017/coderising/litestruts/View.java b/group02/1554421063/src/com/github/FelixCJF/coding2017/coderising/litestruts/View.java
new file mode 100644
index 0000000000..07df2a5dab
--- /dev/null
+++ b/group02/1554421063/src/com/github/FelixCJF/coding2017/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/group02/1554421063/src/com/github/FelixCJF/coding2017/coderising/litestruts/struts.xml b/group02/1554421063/src/com/github/FelixCJF/coding2017/coderising/litestruts/struts.xml
new file mode 100644
index 0000000000..a6cfe43e6c
--- /dev/null
+++ b/group02/1554421063/src/com/github/FelixCJF/coding2017/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/group02/435994736/src/main/java/com/github/lhpmatlab/coding2017/basic/MyArrayList.java b/group02/435994736/src/main/java/com/github/lhpmatlab/coding2017/basic/MyArrayList.java
new file mode 100644
index 0000000000..03f6710788
--- /dev/null
+++ b/group02/435994736/src/main/java/com/github/lhpmatlab/coding2017/basic/MyArrayList.java
@@ -0,0 +1,83 @@
+package com.github.lhpmatlab.coding2017.basic;
+
+/**
+ * Created by andy on 2017/2/18.
+ */
+public class MyArrayList {
+
+ private Object[] initialArray = {};
+ private Object[] dataArray;
+ private int initSize = 10;
+ private int arraySize;
+ public MyArrayList() {
+ dataArray = initialArray;
+ }
+
+ public MyArrayList(int init) {
+ dataArray = new Object[init];
+ }
+
+ public void ensureCapacity(int newCapacity) {
+ if (newCapacity < arraySize)
+ return;
+
+ Object[] old = dataArray;
+ dataArray = new Object[newCapacity];
+ for (int i = 0; i < size(); i++) {
+ dataArray[i] = old[i];
+ }
+ }
+
+ public void add(T element) {
+ add(size(), element);
+ }
+
+ public void add(int index, T element) {
+ if (size() == dataArray.length) {
+ ensureCapacity(size()*2 + 1);
+ }
+ for(int i=arraySize;i>index;i--) {
+ dataArray[i] = dataArray[i - 1];
+ }
+ dataArray[index] = element;
+ arraySize++;
+ }
+
+ public T delete(int index) {
+ if (index < 0 || index > arraySize) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ T removeElement = (T)dataArray[index];
+ for (int i = index; i < size() -1; i++) {
+ dataArray[i] = dataArray[i + 1];
+ }
+ arraySize--;
+ return removeElement;
+ }
+
+ public T get(int index) {
+ if (index < 0 || index > arraySize) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ return (T)dataArray[index];
+ }
+
+ public T set(int index, T newElement) {
+ if (index < 0 || index > arraySize) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ T oldElement = (T) dataArray[index];
+ dataArray[index] = newElement;
+
+ return oldElement;
+ }
+
+ public int size() {
+ return arraySize;
+ }
+
+ public boolean isEmpty() {
+ return size() == 0;
+ }
+
+}
diff --git a/group02/435994736/src/main/java/com/github/lhpmatlab/coding2017/basic/MyLinkedList.java b/group02/435994736/src/main/java/com/github/lhpmatlab/coding2017/basic/MyLinkedList.java
new file mode 100644
index 0000000000..9e7eab3401
--- /dev/null
+++ b/group02/435994736/src/main/java/com/github/lhpmatlab/coding2017/basic/MyLinkedList.java
@@ -0,0 +1,119 @@
+package com.github.lhpmatlab.coding2017.basic;
+
+/**
+ * Created by andy on 2017/2/18.
+ */
+public class MyLinkedList {
+ private class Node {
+ public Node pre;
+ public Node next;
+ public T data;
+
+ public Node(Node pre,Node next,T data) {
+ this.pre = pre;
+ this.next = next;
+ this.data = data;
+ }
+ }
+
+ private int dataSize;
+
+ private Node head;
+ private Node tail;
+
+ public MyLinkedList() {
+ head = new Node(null,null,null);
+ tail = new Node(head, null, null);
+ head.next = tail;
+ dataSize = 0;
+ }
+
+ public void add(T t) {
+// add(size(), t);
+ Node newNode = new Node<>(null, tail, t);
+ newNode.pre = tail.pre;
+ tail.pre.next = newNode;
+ tail.pre = newNode;
+ dataSize++;
+
+ }
+
+ /**
+ * 根据索引添加没有实现
+ * @param index
+ * @param element
+ */
+ public void add(int index,T element) {
+ //TODO 根据索引添加元素
+// addBefore(getNode(index,0,size()-1),element);
+// if (index == dataSize) {
+// add(element);
+// } else {
+ //
+// }
+ }
+
+ public T get(int index) {
+ return getNode(index).data;
+ }
+
+ public T set(int index, T newValue) {
+ Node node = getNode(index);
+ T oldData = node.data;
+ node.data = newValue;
+ return oldData;
+ }
+
+ public T remove(int index) {
+ Node node = getNode(index);
+ node.next.pre = node.pre;
+ node.pre.next = node.next;
+ dataSize--;
+
+ return node.data;
+
+ }
+
+ private void addBefore(Node node, T element) {
+// newNode.pre.next = newNode;
+// node.pre = newNode;
+ Node pre = node.pre;
+ Node newNode = new Node<>(node.pre, node, element);
+ node.pre = newNode;
+ pre.next = newNode;
+
+ dataSize++;
+ }
+
+ private Node getNode(int index) {
+ return getNode(index, 0, size());
+ }
+
+ private Node getNode(int index, int lower, int upper) {
+ Node p;
+ if (index < lower || index > upper) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (index < size() / 2) {
+ p = head.next;
+ for (int i = 0; i < index; i++) {
+ p = p.next;
+ }
+ } else {
+ p = tail.pre;
+ for (int i = size()-1; i > index; i--) {
+ p = p.pre;
+ }
+ }
+ return p;
+ }
+
+ public int size() {
+ return dataSize;
+ }
+
+ public boolean isEmpty() {
+ return size() == 0;
+ }
+}
diff --git a/group02/435994736/src/main/java/com/github/lhpmatlab/coding2017/basic/MyQueue.java b/group02/435994736/src/main/java/com/github/lhpmatlab/coding2017/basic/MyQueue.java
new file mode 100644
index 0000000000..6d0c970b65
--- /dev/null
+++ b/group02/435994736/src/main/java/com/github/lhpmatlab/coding2017/basic/MyQueue.java
@@ -0,0 +1,29 @@
+package com.github.lhpmatlab.coding2017.basic;
+
+/**
+ * Created by andy on 2017/2/22.
+ */
+public class MyQueue {
+ private MyLinkedList link = new MyLinkedList<>();
+
+ public void enQueue(T t) {
+ link.add(t);
+ }
+
+ public T deQueue() {
+ if (size() <= 0) {
+ return null;
+ }
+ T t = link.get(0);
+ link.remove(0);
+ return t;
+ }
+
+ public boolean isEmpty() {
+ return size() == 0;
+ }
+
+ public int size() {
+ return link.size();
+ }
+}
diff --git a/group02/435994736/src/main/java/com/github/lhpmatlab/coding2017/basic/MyStack.java b/group02/435994736/src/main/java/com/github/lhpmatlab/coding2017/basic/MyStack.java
new file mode 100644
index 0000000000..3fd9d2f5c2
--- /dev/null
+++ b/group02/435994736/src/main/java/com/github/lhpmatlab/coding2017/basic/MyStack.java
@@ -0,0 +1,30 @@
+package com.github.lhpmatlab.coding2017.basic;
+
+/**
+ * Created by andy on 2017/2/22.
+ */
+public class MyStack {
+ private MyArrayList list = new MyArrayList<>();
+
+ public void push(T t) {
+ list.add(t);
+ }
+
+ public T pop() {
+ if (size() <= 0) {
+ throw new IndexOutOfBoundsException();
+ }
+ return list.delete(size() - 1);
+ }
+
+ public T peek() {
+ return list.get(size() - 1);
+ }
+
+ public boolean isEmpty() {
+ return list.size() == 0;
+ }
+ public int size() {
+ return list.size();
+ }
+}
diff --git a/group02/435994736/src/test/java/com/github/lhpmatlab/coding2017/basic/MyArrayListTest.java b/group02/435994736/src/test/java/com/github/lhpmatlab/coding2017/basic/MyArrayListTest.java
new file mode 100644
index 0000000000..e29d41feac
--- /dev/null
+++ b/group02/435994736/src/test/java/com/github/lhpmatlab/coding2017/basic/MyArrayListTest.java
@@ -0,0 +1,113 @@
+package com.github.lhpmatlab.coding2017.basic;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class MyArrayListTest {
+ private MyArrayList list;
+
+ @Before
+ public void init(){
+ list = new MyArrayList<>();
+ }
+
+ @Test
+ public void testEnsureCapacity() {
+ assertEquals("init list size is 0 ", list.size(), 0);
+ list.add("1");
+ list.ensureCapacity(10);
+ assertEquals("ensureCapacity size is 10 ", list.size(),1);
+ }
+
+ /**
+ * 在列表的末尾添加元素
+ */
+ @Test
+ public void testAddT() {
+ assertEquals("init list size is 0 ", list.size(), 0);
+ list.add("1");
+ list.add("2");
+ assertEquals("add list size ", list.size(), 2);
+ for (int i=0; i
+* @since ���� 26, 2017
+* @version 1.0
+*/
+public class MyLinkedListTest {
+ private MyLinkedList linkedList;
+
+ @Before
+ public void before() throws Exception {
+ linkedList = new MyLinkedList<>();
+ }
+
+ @After
+ public void after() throws Exception {
+ }
+
+ /**
+ *
+ * Method: add(T t)
+ *
+ */
+ @Test
+ public void testAddT() throws Exception {
+ assertEquals("init list size is 0 ", linkedList.size(), 0);
+ linkedList.add("1");
+ linkedList.add("2");
+ assertEquals("add list size ", linkedList.size(), 2);
+ for (int i=0; i
+* @since ���� 26, 2017
+* @version 1.0
+*/
+public class MyQueueTest {
+ private MyQueue queue;
+
+ @Before
+ public void init() throws Exception {
+ queue = new MyQueue<>();
+ }
+
+ /**
+ *
+ * Method: enQueue(T t)
+ *
+ */
+ @Test
+ public void testEnQueue() throws Exception {
+ queue.enQueue("1");
+ assertEquals("size ", queue.size(), 1);
+ }
+
+ /**
+ *
+ * Method: deQueue()
+ *
+ */
+ @Test
+ public void testDeQueue() throws Exception {
+ queue.enQueue("1");
+ queue.enQueue("2");
+// queue.deQueue();
+ assertEquals("dequeue element ",queue.deQueue(),"1");
+ assertEquals("size ", queue.size(), 1);
+
+ }
+
+ /**
+ *
+ * Method: isEmpty()
+ *
+ */
+ @Test
+ public void testIsEmpty() throws Exception {
+ assertEquals("isEmpty method",queue.isEmpty(),true);
+ }
+
+ /**
+ *
+ * Method: size()
+ *
+ */
+ @Test
+ public void testSize() throws Exception {
+ queue.enQueue("1");
+ queue.enQueue("2");
+ assertEquals("size method", queue.size(),2);
+ }
+
+
+}
diff --git a/group02/435994736/src/test/java/com/github/lhpmatlab/coding2017/basic/MyStackTest.java b/group02/435994736/src/test/java/com/github/lhpmatlab/coding2017/basic/MyStackTest.java
new file mode 100644
index 0000000000..a90af5d720
--- /dev/null
+++ b/group02/435994736/src/test/java/com/github/lhpmatlab/coding2017/basic/MyStackTest.java
@@ -0,0 +1,104 @@
+package com.github.lhpmatlab.coding2017.basic;
+
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+
+import static org.junit.Assert.*;
+
+/**
+* MyStack Tester.
+*
+* @author
+* @since ���� 26, 2017
+* @version 1.0
+*/
+public class MyStackTest {
+
+ MyStack stack;
+
+
+ @Before
+ public void init() throws Exception {
+ stack = new MyStack<>();
+ }
+
+ @After
+ public void after() throws Exception {
+ }
+
+ /**
+ *
+ * Method: push(T t)
+ *
+ */
+ @Test
+ public void testPush() throws Exception {
+ assertEquals("init stack ", stack.size(), 0);
+ stack.push("1");
+ assertEquals("pust stack ", stack.size(),1);
+ }
+
+ /**
+ *
+ * Method: pop()
+ *
+ */
+ @Test
+ public void testPop() throws Exception {
+ assertEquals("init stack ", stack.size(), 0);
+ stack.push("1");
+ stack.push("2");
+ stack.pop();
+ assertEquals("after pop ",stack.size(),1);
+ }
+
+ /**
+ *
+ * Method: peek()
+ *
+ */
+ @Test
+ public void testPeek() throws Exception {
+ assertEquals("init stack ", stack.size(), 0);
+ stack.push("1");
+ stack.push("2");
+ assertEquals("peek ", stack.peek(),"2");
+ }
+
+ /**
+ *测试判空方法
+ * Method: isEmpty()
+ *
+ */
+ @Test
+ public void testIsEmpty() throws Exception {
+ assertEquals("stack is empty ", stack.isEmpty(), true);
+ }
+
+ /**
+ *测试判空方法,不为空的情况
+ * Method: isEmpty()
+ *
+ */
+ @Test
+ public void testIsNotEmpty() throws Exception {
+ stack.push("1");
+ assertEquals("stack is empty ", stack.isEmpty(), false);
+ }
+
+ /**
+ *
+ * Method: size()
+ *
+ */
+ @Test
+ public void testSize() throws Exception {
+ assertEquals("init stack ", stack.size(), 0);
+ stack.push("1");
+ stack.push("2");
+ assertEquals("size is 2", stack.size(), 2);
+ }
+
+
+}
diff --git a/group02/527705641/.gitignore b/group02/527705641/.gitignore
new file mode 100644
index 0000000000..ae3c172604
--- /dev/null
+++ b/group02/527705641/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/group02/527705641/src/com/github/fei9009/coderising0226/array/ArrayUtil.java b/group02/527705641/src/com/github/fei9009/coderising0226/array/ArrayUtil.java
new file mode 100644
index 0000000000..d4e62075d9
--- /dev/null
+++ b/group02/527705641/src/com/github/fei9009/coderising0226/array/ArrayUtil.java
@@ -0,0 +1,218 @@
+package com.github.fei9009.coderising0226.array;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import com.sun.org.apache.bcel.internal.generic.ISTORE;
+
+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 i = 0, j = origin.length-1;
+ while(i < j){
+ int tmp = origin[i];
+ origin[i] = origin[j];
+ origin[j] = tmp;
+ i++;
+ j--;
+ }
+ }
+
+ /**
+ * 现在有如下的一个数组: 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){
+ if (oldArray == null || oldArray.length == 0){
+ return oldArray;
+ }
+ int count = 0;
+ for (int i = 0; i < oldArray.length; i++) {
+ if (oldArray[i] != 0) {
+ count++;
+ }
+ }
+ int[] newArray = new int[count];
+ int j = 0;
+ for (int i = 0; i <= oldArray.length - 1; i++) {
+ if (oldArray[i] == 0) {
+ continue;
+ }
+ newArray[j++] = oldArray[i];
+ }
+ 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 && array2 == null) {
+ return null;
+ }
+ if (array1 == null) {
+ return array2;
+ }
+ if (array2 == null) {
+ return array1;
+ }
+ int i=0, j=0, k=0;
+ int len1 = array1.length;
+ int len2 = array2.length;
+ int[] mergeArr = new int[len1+len2];
+ while(true){
+ if(i == len1 || j == len2)
+ break;
+ if(array1[i]array2[j]){
+ mergeArr[k++] = array2[j++];
+ }else{
+ mergeArr[k++] = array1[i++];
+ j++;
+ }
+ }
+
+ for(;i list = new ArrayList<>();
+ int f1 = 1, f2 = 1, f3;
+ list.add(f1);
+ list.add(f2);
+ while (f1 +f2 < max) {
+ f3 = f1 + f2;
+ list.add(f3);
+ f1 = f2;
+ f2 = f3;
+ }
+ int[] result = new int[list.size()];
+ int j = 0;
+ for(Integer i : list) {
+ result[j++] = i;
+ }
+ return result;
+ }
+
+ /**
+ * 返回小于给定最大值max的所有素数数组
+ * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ * @param max
+ * @return
+ */
+ public int[] getPrimes(int max){
+ int[] a = new int[max];
+ int k=0;
+ for (int z = 1; ztype){
+ try {
+ Method met = obj.getClass().getMethod("set" + initStr(att), type);
+ met.invoke(obj, value);
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+
+ private static String getter(Object obj, String att){
+ try {
+ Method met = obj.getClass().getMethod("get" + initStr(att));
+ return (String)met.invoke(obj);
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ return null;
+ }
+ private static String initStr(String name) {
+ name = name.substring(0, 1).toUpperCase() + name.substring(1);
+ return name;
+ }
+
+ private static String toLowerString(String name) {
+ name = name.substring(0, 1).toLowerCase() + name.substring(1);
+ return name;
+ }
+
+
+ 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字段中。
+
+ */
+ SAXReader saxReader = new SAXReader();
+ try {
+ Document document = saxReader.read(new File("struts.xml"));
+ Element root = document.getRootElement();
+
+
+ boolean flag = false;
+ String className = "";
+ Element action = null;
+ for (Iterator iter = root.elementIterator(); iter.hasNext();)
+ {
+ Element e = (Element) iter.next();
+ if(e.attributeValue("name").equals(actionName)){
+ flag = true;
+ className = e.attributeValue("class");
+ action = e;
+ break;
+ }
+ }
+ if(!flag)
+ throw new Exception(actionName+"未定义");
+
+ Class> clz = Class.forName(className);
+ Constructor> c = clz.getConstructor();
+ Object obj = c.newInstance();
+
+ for (String in : parameters.keySet()) {
+ setter(obj,in,parameters.get(in), String.class);
+ }
+ Method exc = clz.getDeclaredMethod("execute");
+ String res = (String)exc.invoke(obj);
+
+ //获取所有getter方法
+ //Get the methods
+ Method[] methods = clz.getDeclaredMethods();
+ //Loop through the methods and print out their names
+ Map params = new HashMap();
+
+ for (Method method : methods) {
+ String name = method.getName();
+ if(name.substring(0,3).equals("get")){
+ params.put(toLowerString(name.substring(3)),getter(obj,toLowerString(name.substring(3))));
+ }
+ }
+ View view = new View();
+ view.setParameters(params);
+ //step 4
+ flag = false;
+ Element result = null;
+ List actionChildList = action.elements("result");
+ for (Iterator iter = action.elementIterator(); iter.hasNext();){
+ Element e = (Element) iter.next();
+ if(e.attributeValue("name").equals(res)){
+ flag = true;
+ result = e;
+ break;
+ }
+ }
+ if(!flag)
+ throw new Exception(res+"undefined");
+ view.setJsp(result.getText());
+ return view;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+}
diff --git a/group02/527705641/src/com/github/fei9009/coderising0226/litestruts/StrutsTest.java b/group02/527705641/src/com/github/fei9009/coderising0226/litestruts/StrutsTest.java
new file mode 100644
index 0000000000..c5ee5f10a9
--- /dev/null
+++ b/group02/527705641/src/com/github/fei9009/coderising0226/litestruts/StrutsTest.java
@@ -0,0 +1,43 @@
+package com.github.fei9009.coderising0226.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/group02/527705641/src/com/github/fei9009/coderising0226/litestruts/View.java b/group02/527705641/src/com/github/fei9009/coderising0226/litestruts/View.java
new file mode 100644
index 0000000000..9332493c42
--- /dev/null
+++ b/group02/527705641/src/com/github/fei9009/coderising0226/litestruts/View.java
@@ -0,0 +1,23 @@
+package com.github.fei9009.coderising0226.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/group02/527705641/src/com/github/fei9009/coderising0226/litestruts/struts.xml b/group02/527705641/src/com/github/fei9009/coderising0226/litestruts/struts.xml
new file mode 100644
index 0000000000..68098b57e3
--- /dev/null
+++ b/group02/527705641/src/com/github/fei9009/coderising0226/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/group02/527705641/src/com/github/fei9009/coding2017/basic/ArrayList.java b/group02/527705641/src/com/github/fei9009/coding2017/basic/ArrayList.java
new file mode 100644
index 0000000000..855e25b257
--- /dev/null
+++ b/group02/527705641/src/com/github/fei9009/coding2017/basic/ArrayList.java
@@ -0,0 +1,71 @@
+package com.github.fei9009.coding2017.basic;
+
+public class ArrayList implements List {
+
+ private int size = 0;
+ private int capacity;
+
+ private Object[] elementData = new Object[100];
+
+ public ArrayList() {
+ this.capacity = 20;
+ }
+
+ private void extend() {
+ Object[] updatedElementData = new Object[this.elementData.length + this.capacity];
+ System.arraycopy(this.elementData, 0, updatedElementData, 0, this.elementData.length);
+ this.elementData = updatedElementData;
+ }
+
+ public void add(Object o){
+ if (this.size == elementData.length) {
+ extend();
+ }
+ elementData[size] = o;
+ this.size++;
+ }
+
+ public void add(int index, Object o){
+ if (this.size == elementData.length) {
+ extend();
+ }
+ int i;
+ for (i = this.size - 1; i >= index; i--) {
+ this.elementData[i + 1] = this.elementData[i];
+ }
+ this.elementData[i + 1] = o;
+ this.size++;
+ }
+
+ public Object get(int index){
+ if (index >= 0 && index < this.size) {
+ return this.elementData[index];
+ }else {
+ return null;
+ }
+ }
+
+ public Object remove(int index){
+ if (index >= 0 && index < this.size) {
+ int i = 0;
+ Object deletedElement = this.elementData[index];
+ for (i = index + 1; i < this.size; i++) {
+ this.elementData[i - 1] = this.elementData[i];
+ }
+ this.elementData[i] = null;
+ this.size--;
+ return deletedElement;
+ }else {
+ return null;
+ }
+ }
+
+ public int size(){
+ return this.size;
+ }
+
+ public Iterator iterator(){
+ return null;
+ }
+
+}
diff --git a/group02/527705641/src/com/github/fei9009/coding2017/basic/ArrayListTest.java b/group02/527705641/src/com/github/fei9009/coding2017/basic/ArrayListTest.java
new file mode 100644
index 0000000000..d623dd05e0
--- /dev/null
+++ b/group02/527705641/src/com/github/fei9009/coding2017/basic/ArrayListTest.java
@@ -0,0 +1,55 @@
+package com.github.fei9009.coding2017.basic;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class ArrayListTest {
+
+ private static ArrayList testArray = new ArrayList();
+ @Before
+ public void setUp() throws Exception {
+ //testArray.clear();
+ }
+
+ @Test
+ public void testArrayList() {
+ //fail("Not yet implemented");
+ }
+
+ @Test
+ public void testAddObject() {
+ testArray.add(10);
+ assertEquals(10, testArray.get(0));
+ //fail("Not yet implemented");
+ }
+
+ @Test
+ public void testAddIntObject() {
+ testArray.add(10);
+ testArray.add(0, 3);
+ testArray.add(0, 2);
+ assertEquals(3, testArray.get(1));
+ assertEquals(2, testArray.get(0));
+ //fail("Not yet implemented");
+ }
+
+ @Test
+ public void testGet() {
+ testArray.add(10);
+ assertEquals(10, testArray.get(0));
+ //fail("Not yet implemented");
+ }
+
+ @Test
+ public void testRemove() {
+ fail("Not yet implemented");
+ }
+
+ @Test
+ public void testSize() {
+ fail("Not yet implemented");
+ }
+
+}
diff --git a/group02/527705641/src/com/github/fei9009/coding2017/basic/BinaryTreeNode.java b/group02/527705641/src/com/github/fei9009/coding2017/basic/BinaryTreeNode.java
new file mode 100644
index 0000000000..6dbc7ee012
--- /dev/null
+++ b/group02/527705641/src/com/github/fei9009/coding2017/basic/BinaryTreeNode.java
@@ -0,0 +1,57 @@
+package com.github.fei9009.coding2017.basic;
+
+public class BinaryTreeNode