From 4656c624a3b1b1ba1404617d9548f1e54f45b2c8 Mon Sep 17 00:00:00 2001
From: James <1310368322@qq.com>
Date: Mon, 6 Mar 2017 11:37:43 +0800
Subject: [PATCH 001/155] second homework
---
.../ArrayList.java | 0
.../ArrayUtil.java | 83 +++++++++++++++++++
2 files changed, 83 insertions(+)
rename group11/1310368322/GitHub/src/{ => Day_2017_2_26_FirstHomework}/ArrayList.java (100%)
create mode 100644 group11/1310368322/GitHub/src/day_2017_2_26_SecondHomework/ArrayUtil.java
diff --git a/group11/1310368322/GitHub/src/ArrayList.java b/group11/1310368322/GitHub/src/Day_2017_2_26_FirstHomework/ArrayList.java
similarity index 100%
rename from group11/1310368322/GitHub/src/ArrayList.java
rename to group11/1310368322/GitHub/src/Day_2017_2_26_FirstHomework/ArrayList.java
diff --git a/group11/1310368322/GitHub/src/day_2017_2_26_SecondHomework/ArrayUtil.java b/group11/1310368322/GitHub/src/day_2017_2_26_SecondHomework/ArrayUtil.java
new file mode 100644
index 0000000000..81bc431679
--- /dev/null
+++ b/group11/1310368322/GitHub/src/day_2017_2_26_SecondHomework/ArrayUtil.java
@@ -0,0 +1,83 @@
+package day_2017_2_26_SecondHomework;
+
+import java.util.Arrays;
+
+import javax.management.RuntimeErrorException;
+
+public class ArrayUtil {
+
+ /* *
+ * 给定一个整形数组 a ,对该数组的值进行置换
+ * 例如: a = [7, 9, 30, 3], 置换后为 [3, 30, 9, 7]
+ * */
+
+ /*public ArrayUtil(int[] a2) {
+ this.a = a2;
+ }*/
+ public void reverseArray(int [] a){
+ if(null == a){
+ System.out.println("空指针----");
+ return;
+ }
+ int temp;
+ int last = a.length-1;
+ for (int i = 0; i < a.length/2; i++) {
+ temp = a[i];
+ a[i] = a[last];
+ a[last--] = temp;
+ }
+ }
+ public void print(int [] a){
+ if(null == a){
+ System.out.println("空指针----");
+ return;
+ }
+ for (int i = 0; i < a.length; i++) {
+ System.out.print(a[i] + " ");
+ }
+ System.out.println();
+ }
+
+ /* *
+ * 现在有如下的一个数组, 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(null == oldArray){
+ return null;
+ }
+ int count = 0;
+ int oldArrayLength = oldArray.length;
+ for(int i = 0; i < oldArrayLength;){
+ if(oldArray[i]==0){
+ for(int j = i; j < oldArrayLength -1; j++){
+ oldArray[j] = oldArray[j+1];
+ }
+ oldArrayLength--;
+ count++;
+ }else{
+ i++;
+ }
+ }
+ int [] target = new int[oldArray.length-count];
+ System.arraycopy(oldArray, 0, target, 0, oldArray.length-count);
+ return target;
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+}
From 7af7f85a0b7244b65342eab9a6fb38d6766fbbb4 Mon Sep 17 00:00:00 2001
From: James <1310368322@qq.com>
Date: Mon, 6 Mar 2017 11:55:22 +0800
Subject: [PATCH 002/155] new
---
group11/1310368322/src/ArrayList.java | 98 ++++++++++++++++++
group11/1310368322/src/LinkedList.java | 113 +++++++++++++++++++++
group11/1310368322/test/ArrayUtilTest.java | 101 ++++++++++++++++++
3 files changed, 312 insertions(+)
create mode 100644 group11/1310368322/src/ArrayList.java
create mode 100644 group11/1310368322/src/LinkedList.java
create mode 100644 group11/1310368322/test/ArrayUtilTest.java
diff --git a/group11/1310368322/src/ArrayList.java b/group11/1310368322/src/ArrayList.java
new file mode 100644
index 0000000000..b5024f1dfb
--- /dev/null
+++ b/group11/1310368322/src/ArrayList.java
@@ -0,0 +1,98 @@
+package Day_2017_2_26_FirstHomework;
+
+public class ArrayList {
+
+ private static final int DEFAULT_SIZE = 10;
+ private static final int MAX_VALUE = 2147483647;
+ private Object[] elementData = new Object[DEFAULT_SIZE];
+ private Exception Exception;
+ private int size = 0;
+
+ public ArrayList(){
+ this(DEFAULT_SIZE);
+ }
+ public ArrayList(int defaultSize) {
+ rangCheckForConstructor(defaultSize);
+ elementData = new Object[defaultSize];
+ }
+
+
+ private void rangCheckForConstructor(int defaultSize) {
+ if(defaultSize<0 || defaultSize>MAX_VALUE){
+ throw new IndexOutOfBoundsException("数值不合理");
+ }
+
+ }
+
+ public void add(Object o){
+ ensureCapacity();
+ for(int i = 0; i < elementData.length; i++){
+ if(null == elementData[i]){
+ elementData[i] = o;
+ break;
+ }
+ }
+ size++;
+ }
+ private void ensureCapacity() {
+ if(size>elementData.length){
+ elementData = ArrayList.grow(elementData, 10);
+ }
+ }
+ public void add(int index, Object o){
+ rangeCheckForAdd(index);
+ ensureCapacity();
+ int k = -1;
+ for(int i = index; i < elementData.length; i++){
+ if(null==elementData[i]){
+ k = i-1;
+ break;
+ }
+ }
+ for(int i = k; i >= index;i--){
+ elementData[i+1] = elementData[i];
+ }
+ elementData[index] = o;
+ size++;
+ }
+ private void rangeCheckForAdd(int index) {
+ if(index < 0 || index > this.size){// add 的元素只能在 [0,size](可以给size位置插元素,但不可以给size后插元素)
+ throw new IndexOutOfBoundsException("下标越界");
+ }
+
+ }
+ public Object get(int index){
+ return elementData[index];
+ }
+
+ public Object remove(int index){
+ while(true){
+ elementData[index] = elementData[index+++1];
+ if(elementData[index]==null){
+ break;
+ }
+ }
+ size--;
+ return null;
+ }
+ public int size(){
+ return -1;
+ }
+ public void getElementData(){
+ for(int i = 0; i < elementData.length; i++){
+ System.out.println(elementData[i]);
+
+ }
+ }
+ public static Object[] grow(Object[] elementData2, int size){
+ Object []target = new Object[elementData2.length+size];
+ System.arraycopy(elementData2, 0, target, 0, elementData2.length);
+ return target;
+ }
+
+ public static void main(String[] args) {
+ ArrayList a = new ArrayList();
+ a.getElementData();
+ System.out.println(a.size);
+ }
+}
diff --git a/group11/1310368322/src/LinkedList.java b/group11/1310368322/src/LinkedList.java
new file mode 100644
index 0000000000..488f2a22a6
--- /dev/null
+++ b/group11/1310368322/src/LinkedList.java
@@ -0,0 +1,113 @@
+package Day_2017_2_26_FirstHomework;
+
+public class LinkedList{
+ private Node head;
+ static int size = 0;
+ public void add(Object o){
+ if(null == head){
+ head = new Node();
+ head.data = o;
+ head.next = null;
+ }else{
+ Node p = head;
+ while(null != p.next){
+ p = p.next;
+ }
+ Node newNode = new Node();
+ newNode.data = o;
+ p.next = newNode;
+ newNode.next =null;
+ }
+ size++;
+ }
+ public int size(){
+ return size;
+ }
+ public void add(int index,Object o){
+ if(index < 0){
+ throw new RuntimeException("下标不能为负数");
+ }
+ if(index == 0){
+ addFirst(o);
+ size++;
+ return;
+ }
+ if(index > size){
+ throw new RuntimeException("");
+ }
+ int i = 0;
+ Node p = head;
+ Node q = null;
+
+ while(i!=index){
+ q = p;
+ p = p.next;
+ i++;
+ }
+ Node r = new Node();
+ r.data = o;
+ r.next =null;
+ q.next = r;
+ r.next = p;
+ size++;
+ return;
+ }
+
+ public Object get(int index){
+ int i = 0;
+ Node p = head;
+ while(i != index){
+ p = p.next;
+ i++;
+ }
+ return p.data;
+ }
+ public Object remove(int index){
+ if(index < 0){
+ throw new RuntimeException("下标不能为负数");
+ }
+ if(index == 1){
+ size--;
+ return head.data;
+ }
+ int i = 0;
+ Node p = head;
+ Node q = null;
+ while(i != index){
+ q = p;
+ p = p.next;
+ i++;
+ }
+ q.next = p.next;
+ size--;
+ return p.data;
+ }
+ public void addFirst(Object o){
+ Node p = new Node();
+ p.next = head;
+ p.data = o;
+ head = p;
+ size++;
+ }
+ public Object removeFirst(){
+ head = head.next;
+ size--;
+ return null;
+ }
+ public static class Node{
+ Object data;
+ Node next;
+ }
+
+ public static void main(String[] args) {
+ LinkedList linkedList = new LinkedList();
+ linkedList.add("a");
+ linkedList.add("b");
+ linkedList.add("c");
+ linkedList.add("d");
+ linkedList.add(5, "f");
+ System.out.println(linkedList.get(5));
+ System.out.println(linkedList.size());
+ }
+
+}
\ No newline at end of file
diff --git a/group11/1310368322/test/ArrayUtilTest.java b/group11/1310368322/test/ArrayUtilTest.java
new file mode 100644
index 0000000000..aaf3a80e7e
--- /dev/null
+++ b/group11/1310368322/test/ArrayUtilTest.java
@@ -0,0 +1,101 @@
+package day_2017_2_26_SecondHomework;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ArrayUtilTest {
+ ArrayUtil arrayUtil;
+
+ @Before
+ public void setUp() throws Exception {
+ arrayUtil = new ArrayUtil();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testReverseArray_a() {
+ int [] actuals = {};
+ int [] expected = {};
+ arrayUtil.reverseArray(actuals);
+ Assert.assertArrayEquals(expected, actuals);
+ }
+ @Test
+ public void testReverseArray_b() {
+ int [] actuals = null;
+ int [] expected = null;
+ arrayUtil.reverseArray(actuals);
+ Assert.assertArrayEquals(expected, actuals);
+ }
+ @Test
+ public void testReverseArray_c() {
+ int [] actuals = {1,2,3,4};
+ int [] expected = {4,3,2,1};
+ arrayUtil.reverseArray(actuals);
+ Assert.assertArrayEquals(expected, actuals);
+ }
+
+
+ @Test
+ public void testRemoveZero_1(){
+ int [] actuals = null;
+ int [] expected = null;
+ int [] actual = arrayUtil.removeZero(actuals);
+ Assert.assertArrayEquals(expected, actual);
+ }
+ @Test
+ public void testRemoveZero_2(){
+ int [] actuals = {};
+ int [] expected = {};
+ int [] actual = arrayUtil.removeZero(actuals);
+ Assert.assertArrayEquals(expected, actual);
+ }
+ @Test
+ public void testRemoveZero_3(){
+ int [] actuals = {0,0,0,0,0,0};
+ int [] expected = {};
+ int [] actual = arrayUtil.removeZero(actuals);
+ Assert.assertArrayEquals(expected, actual);
+ }
+ @Test
+ public void testRemoveZero_4(){
+ int [] actuals = {1,2,3,4,5,6};
+ int [] expected = {1,2,3,4,5,6};
+ int [] actual = arrayUtil.removeZero(actuals);
+ Assert.assertArrayEquals(expected, actual);
+ }
+ @Test
+ public void testRemoveZero_5(){
+ int [] actuals = {1,2,0,0,5,6};
+ int [] expected = {1,2,5,6};
+ int [] actual = arrayUtil.removeZero(actuals);
+ Assert.assertArrayEquals(expected, actual);
+ }
+ @Test
+ public void testRemoveZero_6(){
+ int [] actuals = {0,0,4,2};
+ int [] expected = {4,2};
+ int [] actual = arrayUtil.removeZero(actuals);
+ Assert.assertArrayEquals(expected, actual);
+ }@Test
+ public void testRemoveZero_7(){
+ int [] actuals = {4,2,0,0,0};
+ int [] expected = {4,2};
+ int [] actual = arrayUtil.removeZero(actuals);
+ Assert.assertArrayEquals(expected, actual);
+ }
+ public void testRemoveZero_8(){
+ int [] actuals = {0,0,4,0,0,2,0,0,0};
+ int [] expected = {4,2};
+ int [] actual = arrayUtil.removeZero(actuals);
+ Assert.assertArrayEquals(expected, actual);
+ }
+
+
+}
From c7f3d11a592e37a418ffcf5d1934b686c4d09a29 Mon Sep 17 00:00:00 2001
From: James <1310368322@qq.com>
Date: Mon, 6 Mar 2017 12:11:32 +0800
Subject: [PATCH 003/155] second
---
group11/1310368322/src/ArrayUtil.java | 83 +++++++++++++++++++++++++++
1 file changed, 83 insertions(+)
create mode 100644 group11/1310368322/src/ArrayUtil.java
diff --git a/group11/1310368322/src/ArrayUtil.java b/group11/1310368322/src/ArrayUtil.java
new file mode 100644
index 0000000000..81bc431679
--- /dev/null
+++ b/group11/1310368322/src/ArrayUtil.java
@@ -0,0 +1,83 @@
+package day_2017_2_26_SecondHomework;
+
+import java.util.Arrays;
+
+import javax.management.RuntimeErrorException;
+
+public class ArrayUtil {
+
+ /* *
+ * 给定一个整形数组 a ,对该数组的值进行置换
+ * 例如: a = [7, 9, 30, 3], 置换后为 [3, 30, 9, 7]
+ * */
+
+ /*public ArrayUtil(int[] a2) {
+ this.a = a2;
+ }*/
+ public void reverseArray(int [] a){
+ if(null == a){
+ System.out.println("空指针----");
+ return;
+ }
+ int temp;
+ int last = a.length-1;
+ for (int i = 0; i < a.length/2; i++) {
+ temp = a[i];
+ a[i] = a[last];
+ a[last--] = temp;
+ }
+ }
+ public void print(int [] a){
+ if(null == a){
+ System.out.println("空指针----");
+ return;
+ }
+ for (int i = 0; i < a.length; i++) {
+ System.out.print(a[i] + " ");
+ }
+ System.out.println();
+ }
+
+ /* *
+ * 现在有如下的一个数组, 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(null == oldArray){
+ return null;
+ }
+ int count = 0;
+ int oldArrayLength = oldArray.length;
+ for(int i = 0; i < oldArrayLength;){
+ if(oldArray[i]==0){
+ for(int j = i; j < oldArrayLength -1; j++){
+ oldArray[j] = oldArray[j+1];
+ }
+ oldArrayLength--;
+ count++;
+ }else{
+ i++;
+ }
+ }
+ int [] target = new int[oldArray.length-count];
+ System.arraycopy(oldArray, 0, target, 0, oldArray.length-count);
+ return target;
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+}
From 87d2cfef839eeca434ef57bcf7207bbfd36d6aa9 Mon Sep 17 00:00:00 2001
From: James <1310368322@qq.com>
Date: Mon, 6 Mar 2017 14:33:56 +0800
Subject: [PATCH 004/155] remove GitHub
---
group11/1310368322/GitHub/.gitignore | 1 -
.../ArrayList.java | 79 ------------------
.../ArrayUtil.java | 83 -------------------
group11/1310368322/GitHub/src/testGitHub.java | 7 --
4 files changed, 170 deletions(-)
delete mode 100644 group11/1310368322/GitHub/.gitignore
delete mode 100644 group11/1310368322/GitHub/src/Day_2017_2_26_FirstHomework/ArrayList.java
delete mode 100644 group11/1310368322/GitHub/src/day_2017_2_26_SecondHomework/ArrayUtil.java
delete mode 100644 group11/1310368322/GitHub/src/testGitHub.java
diff --git a/group11/1310368322/GitHub/.gitignore b/group11/1310368322/GitHub/.gitignore
deleted file mode 100644
index 5e56e040ec..0000000000
--- a/group11/1310368322/GitHub/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/bin
diff --git a/group11/1310368322/GitHub/src/Day_2017_2_26_FirstHomework/ArrayList.java b/group11/1310368322/GitHub/src/Day_2017_2_26_FirstHomework/ArrayList.java
deleted file mode 100644
index 68b42b1c03..0000000000
--- a/group11/1310368322/GitHub/src/Day_2017_2_26_FirstHomework/ArrayList.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package Day_2017_2_20_DateStructure;
-
-public class ArrayList {
-
-
- private int size = 0;
-
- private Object[] elementData = new Object[10];
-
- private Exception Exception;
-
- public void add(Object o){
- if(size>elementData.length){
- elementData = ArrayList.grow(elementData, 10);
- }
- for(int i = 0; i < elementData.length; i++){
- if(null == elementData[i]){
- elementData[i] = o;
- break;
- }
- }
- size++;
- }
- public void add(int index, Object o){
- if(size>elementData.length){
- elementData = ArrayList.grow(elementData, 10);
- }
- if(index<0){
- System.out.println("您插入的位置有误");
- }
- int k = -1;
- for(int i = index; i < elementData.length; i++){
- if(null==elementData[i]){
- k = i-1;
- break;
- }
- }
- for(int i = k; i >= index;i--){
- elementData[i+1] = elementData[i];
- }
- elementData[index] = o;
- size++;
- }
- public Object get(int index){
- return elementData[index];
- }
-
- public Object remove(int index){
- while(true){
- elementData[index] = elementData[index+++1];
- if(elementData[index]==null){
- break;
- }
- }
- size--;
- return null;
- }
- public int size(){
- return -1;
- }
- public void getElementData(){
- for(int i = 0; i < elementData.length; i++){
- System.out.println(elementData[i]);
-
- }
- }
- public static Object[] grow(Object[] elementData2, int size){
- Object []target = new Object[elementData2.length+size];
- System.arraycopy(elementData2, 0, target, 0, elementData2.length);
- return target;
- }
-
- public static void main(String[] args) {
- ArrayList a = new ArrayList();
- a.add("a");
- a.getElementData();
- System.out.println(a.size);
- }
-}
diff --git a/group11/1310368322/GitHub/src/day_2017_2_26_SecondHomework/ArrayUtil.java b/group11/1310368322/GitHub/src/day_2017_2_26_SecondHomework/ArrayUtil.java
deleted file mode 100644
index 81bc431679..0000000000
--- a/group11/1310368322/GitHub/src/day_2017_2_26_SecondHomework/ArrayUtil.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package day_2017_2_26_SecondHomework;
-
-import java.util.Arrays;
-
-import javax.management.RuntimeErrorException;
-
-public class ArrayUtil {
-
- /* *
- * 给定一个整形数组 a ,对该数组的值进行置换
- * 例如: a = [7, 9, 30, 3], 置换后为 [3, 30, 9, 7]
- * */
-
- /*public ArrayUtil(int[] a2) {
- this.a = a2;
- }*/
- public void reverseArray(int [] a){
- if(null == a){
- System.out.println("空指针----");
- return;
- }
- int temp;
- int last = a.length-1;
- for (int i = 0; i < a.length/2; i++) {
- temp = a[i];
- a[i] = a[last];
- a[last--] = temp;
- }
- }
- public void print(int [] a){
- if(null == a){
- System.out.println("空指针----");
- return;
- }
- for (int i = 0; i < a.length; i++) {
- System.out.print(a[i] + " ");
- }
- System.out.println();
- }
-
- /* *
- * 现在有如下的一个数组, 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(null == oldArray){
- return null;
- }
- int count = 0;
- int oldArrayLength = oldArray.length;
- for(int i = 0; i < oldArrayLength;){
- if(oldArray[i]==0){
- for(int j = i; j < oldArrayLength -1; j++){
- oldArray[j] = oldArray[j+1];
- }
- oldArrayLength--;
- count++;
- }else{
- i++;
- }
- }
- int [] target = new int[oldArray.length-count];
- System.arraycopy(oldArray, 0, target, 0, oldArray.length-count);
- return target;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-}
diff --git a/group11/1310368322/GitHub/src/testGitHub.java b/group11/1310368322/GitHub/src/testGitHub.java
deleted file mode 100644
index af74e99b53..0000000000
--- a/group11/1310368322/GitHub/src/testGitHub.java
+++ /dev/null
@@ -1,7 +0,0 @@
-
-public class testGitHub {
- private void mian() {
- System.out.print("Hello GitHub");
- }
-
-}
From ecafb62bacf99c75b0c7af64ec957dedd356a20d Mon Sep 17 00:00:00 2001
From: Dev_yang <501294009@qq.com>
Date: Mon, 6 Mar 2017 23:31:39 +0800
Subject: [PATCH 005/155] commit first
---
.../JavaProject/.idea/uiDesigner.xml | 124 ++++++++++++++++++
.../501294009/JavaProject/module1/README.md | 1 +
group11/501294009/JavaProject/module1/pom.xml | 25 ++++
.../501294009/JavaProject/module2/README.md | 15 +++
group11/501294009/JavaProject/module2/pom.xml | 47 +++++++
.../src/main/java/com/yang/LoginAction.java | 39 ++++++
.../src/main/java/com/yang/Struts.java | 124 ++++++++++++++++++
.../src/main/java/com/yang/StrutsTest.java | 43 ++++++
.../module2/src/main/java/com/yang/View.java | 27 ++++
.../src/main/java/com/yang/bean/Action.java | 58 ++++++++
.../src/main/java/com/yang/bean/Result.java | 40 ++++++
.../src/main/java/com/yang/bean/Struts.java | 34 +++++
.../module2/src/main/resources/struts.xml | 11 ++
13 files changed, 588 insertions(+)
create mode 100644 group11/501294009/JavaProject/.idea/uiDesigner.xml
create mode 100644 group11/501294009/JavaProject/module1/README.md
create mode 100644 group11/501294009/JavaProject/module1/pom.xml
create mode 100644 group11/501294009/JavaProject/module2/README.md
create mode 100644 group11/501294009/JavaProject/module2/pom.xml
create mode 100644 group11/501294009/JavaProject/module2/src/main/java/com/yang/LoginAction.java
create mode 100644 group11/501294009/JavaProject/module2/src/main/java/com/yang/Struts.java
create mode 100644 group11/501294009/JavaProject/module2/src/main/java/com/yang/StrutsTest.java
create mode 100644 group11/501294009/JavaProject/module2/src/main/java/com/yang/View.java
create mode 100644 group11/501294009/JavaProject/module2/src/main/java/com/yang/bean/Action.java
create mode 100644 group11/501294009/JavaProject/module2/src/main/java/com/yang/bean/Result.java
create mode 100644 group11/501294009/JavaProject/module2/src/main/java/com/yang/bean/Struts.java
create mode 100644 group11/501294009/JavaProject/module2/src/main/resources/struts.xml
diff --git a/group11/501294009/JavaProject/.idea/uiDesigner.xml b/group11/501294009/JavaProject/.idea/uiDesigner.xml
new file mode 100644
index 0000000000..e96534fb27
--- /dev/null
+++ b/group11/501294009/JavaProject/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/group11/501294009/JavaProject/module1/README.md b/group11/501294009/JavaProject/module1/README.md
new file mode 100644
index 0000000000..933a3ef67e
--- /dev/null
+++ b/group11/501294009/JavaProject/module1/README.md
@@ -0,0 +1 @@
+module1 is achieve ArrayList, LinkedList, Queue, Stack BinaryTree 鍜孖terator
\ No newline at end of file
diff --git a/group11/501294009/JavaProject/module1/pom.xml b/group11/501294009/JavaProject/module1/pom.xml
new file mode 100644
index 0000000000..98bfd43a2c
--- /dev/null
+++ b/group11/501294009/JavaProject/module1/pom.xml
@@ -0,0 +1,25 @@
+
+ 4.0.0
+
+ com.yang
+ module1
+ 1.0-SNAPSHOT
+ jar
+
+ module1
+ http://maven.apache.org
+
+
+ UTF-8
+
+
+
+
+ junit
+ junit
+ 3.8.1
+ test
+
+
+
diff --git a/group11/501294009/JavaProject/module2/README.md b/group11/501294009/JavaProject/module2/README.md
new file mode 100644
index 0000000000..9bf528719a
--- /dev/null
+++ b/group11/501294009/JavaProject/module2/README.md
@@ -0,0 +1,15 @@
+0. 璇诲彇閰嶇疆鏂囦欢struts.xml
+
+1. 鏍规嵁actionName鎵惧埌鐩稿搴旂殑class 锛 渚嬪LoginAction, 閫氳繃鍙嶅皠瀹炰緥鍖栵紙鍒涘缓瀵硅薄锛
+鎹畃arameters涓殑鏁版嵁锛岃皟鐢ㄥ璞$殑setter鏂规硶锛 渚嬪parameters涓殑鏁版嵁鏄
+("name"="test" , "password"="1234") ,
+閭e氨搴旇璋冪敤 setName鍜宻etPassword鏂规硶
+
+2. 閫氳繃鍙嶅皠璋冪敤瀵硅薄鐨別xectue 鏂规硶锛 骞惰幏寰楄繑鍥炲硷紝渚嬪"success"
+
+3. 閫氳繃鍙嶅皠鎵惧埌瀵硅薄鐨勬墍鏈塯etter鏂规硶锛堜緥濡 getMessage锛,
+閫氳繃鍙嶅皠鏉ヨ皟鐢紝 鎶婂煎拰灞炴у舰鎴愪竴涓狧ashMap , 渚嬪 {"message": "鐧诲綍鎴愬姛"} ,
+鏀惧埌View瀵硅薄鐨刾arameters
+
+4. 鏍规嵁struts.xml涓殑 閰嶇疆,浠ュ強execute鐨勮繑鍥炲硷紝 纭畾鍝竴涓猨sp锛
+鏀惧埌View瀵硅薄鐨刯sp瀛楁涓
diff --git a/group11/501294009/JavaProject/module2/pom.xml b/group11/501294009/JavaProject/module2/pom.xml
new file mode 100644
index 0000000000..aee6c06186
--- /dev/null
+++ b/group11/501294009/JavaProject/module2/pom.xml
@@ -0,0 +1,47 @@
+
+ 4.0.0
+
+ com.yang
+ module2
+ 1.0-SNAPSHOT
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 1.8
+ 1.8
+
+
+
+
+ jar
+
+ module2
+ http://maven.apache.org
+
+
+ UTF-8
+
+
+
+
+ junit
+ junit
+ 3.8.1
+ test
+
+
+ junit
+ junit
+ RELEASE
+
+
+ junit
+ junit
+ RELEASE
+
+
+
diff --git a/group11/501294009/JavaProject/module2/src/main/java/com/yang/LoginAction.java b/group11/501294009/JavaProject/module2/src/main/java/com/yang/LoginAction.java
new file mode 100644
index 0000000000..377ae9c629
--- /dev/null
+++ b/group11/501294009/JavaProject/module2/src/main/java/com/yang/LoginAction.java
@@ -0,0 +1,39 @@
+package com.yang;
+
+/**
+ * 杩欐槸涓涓敤鏉ュ睍绀虹櫥褰曠殑涓氬姟绫伙紝 鍏朵腑鐨勭敤鎴峰悕鍜屽瘑鐮侀兘鏄‖缂栫爜鐨勩
+ * @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;
+ }
+}
\ No newline at end of file
diff --git a/group11/501294009/JavaProject/module2/src/main/java/com/yang/Struts.java b/group11/501294009/JavaProject/module2/src/main/java/com/yang/Struts.java
new file mode 100644
index 0000000000..c28148d584
--- /dev/null
+++ b/group11/501294009/JavaProject/module2/src/main/java/com/yang/Struts.java
@@ -0,0 +1,124 @@
+package com.yang;
+
+import com.yang.bean.Action;
+import com.yang.bean.Result;
+import org.junit.Test;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import java.io.*;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/*
+
+0. 璇诲彇閰嶇疆鏂囦欢struts.xml
+
+ 1. 鏍规嵁actionName鎵惧埌鐩稿搴旂殑class 锛 渚嬪LoginAction, 閫氳繃鍙嶅皠瀹炰緥鍖栵紙鍒涘缓瀵硅薄锛
+鎹畃arameters涓殑鏁版嵁锛岃皟鐢ㄥ璞$殑setter鏂规硶锛 渚嬪parameters涓殑鏁版嵁鏄
+("name"="test" , "password"="1234") ,
+閭e氨搴旇璋冪敤 setName鍜宻etPassword鏂规硶
+
+2. 閫氳繃鍙嶅皠璋冪敤瀵硅薄鐨別xectue 鏂规硶锛 骞惰幏寰楄繑鍥炲硷紝渚嬪"success"
+
+3. 閫氳繃鍙嶅皠鎵惧埌瀵硅薄鐨勬墍鏈塯etter鏂规硶锛堜緥濡 getMessage锛,
+閫氳繃鍙嶅皠鏉ヨ皟鐢紝 鎶婂煎拰灞炴у舰鎴愪竴涓狧ashMap , 渚嬪 {"message": "鐧诲綍鎴愬姛"} ,
+鏀惧埌View瀵硅薄鐨刾arameters
+
+4. 鏍规嵁struts.xml涓殑 閰嶇疆,浠ュ強execute鐨勮繑鍥炲硷紝 纭畾鍝竴涓猨sp锛
+鏀惧埌View瀵硅薄鐨刯sp瀛楁涓
+
+*/
+public class Struts {
+
+ private static View view;
+
+ public static View runAction(String actionName, Map parameters) {
+ view = null;
+
+ try {
+ com.yang.bean.Struts struts = (com.yang.bean.Struts) getBean(com.yang.bean.Struts.class, "struts.xml");
+
+ List actions = struts.getActions();
+ actions.forEach((Action action) -> {
+ try {
+ renderView(actionName, parameters, action);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+
+ });
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return view;
+ }
+
+ private static void renderView(String actionName, Map parameters, Action action) throws Exception {
+ if (!action.getName().equalsIgnoreCase(actionName)) {
+ return;//same as continue
+ }
+ String packageName = action.getPackageName();
+ Class> aClass;
+ aClass = Class.forName(packageName);
+ Object instance = aClass.newInstance();
+
+ Method[] methods = aClass.getDeclaredMethods();
+ Map methodMap = new HashMap();
+ for (Method method : methods) {
+ method.setAccessible(true);
+ methodMap.put(method.getName(), method);
+ }
+
+ invokeMethod("setName", parameters.get("name"), instance, methodMap);
+ invokeMethod("setPassword", parameters.get("password"), instance, methodMap);
+ String jsp = invokeMethod("execute", null, instance, methodMap);
+
+ String message = invokeMethod("getMessage", null, instance, methodMap);
+
+ Map params = new HashMap();
+ params.put("message", message);
+ view = new View();
+ view.setParameters(params);
+ List results = action.getResults();
+ results.forEach(temp -> {
+ if (temp.getName().equalsIgnoreCase(jsp)) {
+ view.setJsp(temp.getValue());
+ }
+
+ });
+ }
+
+
+
+ private static Object getBean(Class clz, String fileName) throws JAXBException {
+ JAXBContext context = JAXBContext.newInstance(clz);
+ Unmarshaller unmarshaller = context.createUnmarshaller();
+ InputStream inputStream = Struts.class.getClassLoader().getResourceAsStream(fileName);
+ return unmarshaller.unmarshal(inputStream);
+ }
+
+
+ private static String invokeMethod(String methodName, String param, Object instance, Map map) throws IllegalAccessException, InvocationTargetException {
+ Method setNameMethod = map.get(methodName);
+ String invoke = null;
+ if (setNameMethod != null) {
+ if (param == null) {
+ invoke = (String) setNameMethod.invoke(instance);
+ return invoke;
+ }
+ invoke = (String) setNameMethod.invoke(instance, param);
+ }
+
+
+ return invoke;
+ }
+
+}
\ No newline at end of file
diff --git a/group11/501294009/JavaProject/module2/src/main/java/com/yang/StrutsTest.java b/group11/501294009/JavaProject/module2/src/main/java/com/yang/StrutsTest.java
new file mode 100644
index 0000000000..68f204e252
--- /dev/null
+++ b/group11/501294009/JavaProject/module2/src/main/java/com/yang/StrutsTest.java
@@ -0,0 +1,43 @@
+package com.yang;
+
+import junit.framework.Assert;
+import org.junit.Test;
+import java.util.HashMap;
+import java.util.Map;
+
+
+
+
+
+
+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"));
+ }
+}
\ No newline at end of file
diff --git a/group11/501294009/JavaProject/module2/src/main/java/com/yang/View.java b/group11/501294009/JavaProject/module2/src/main/java/com/yang/View.java
new file mode 100644
index 0000000000..e443b9c759
--- /dev/null
+++ b/group11/501294009/JavaProject/module2/src/main/java/com/yang/View.java
@@ -0,0 +1,27 @@
+package com.yang;
+
+import java.util.Map;
+
+/**
+ * Created by Dev_yang on 2017/3/5.
+ */
+public class View {
+ private String jsp;
+ private Map parameters;
+
+ public String getJsp() {
+ return jsp;
+ }
+
+ public void setJsp(String jsp) {
+ this.jsp = jsp;
+ }
+
+ public Map getParameters() {
+ return parameters;
+ }
+
+ public void setParameters(Map parameters) {
+ this.parameters = parameters;
+ }
+}
diff --git a/group11/501294009/JavaProject/module2/src/main/java/com/yang/bean/Action.java b/group11/501294009/JavaProject/module2/src/main/java/com/yang/bean/Action.java
new file mode 100644
index 0000000000..f79864106a
--- /dev/null
+++ b/group11/501294009/JavaProject/module2/src/main/java/com/yang/bean/Action.java
@@ -0,0 +1,58 @@
+package com.yang.bean;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * Created by Dev_yang on 2017/3/5.
+ */
+public class Action implements Serializable{
+
+ private List results;
+
+ private String name;
+
+ private String packageName;
+
+
+ @XmlElement(name = "result")
+ public List getResults() {
+ return results;
+ }
+
+ public void setResults(List results) {
+ this.results = results;
+ }
+
+
+ @XmlAttribute(name="name")
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+
+ @XmlAttribute(name = "class")
+ public String getPackageName() {
+ return packageName;
+ }
+
+ public void setPackageName(String packageName) {
+ this.packageName = packageName;
+ }
+
+
+ @Override
+ public String toString() {
+ return "Action{" +
+ "results=" + results +
+ ", name='" + name + '\'' +
+ ", packageName='" + packageName + '\'' +
+ '}';
+ }
+}
diff --git a/group11/501294009/JavaProject/module2/src/main/java/com/yang/bean/Result.java b/group11/501294009/JavaProject/module2/src/main/java/com/yang/bean/Result.java
new file mode 100644
index 0000000000..9dd66cac04
--- /dev/null
+++ b/group11/501294009/JavaProject/module2/src/main/java/com/yang/bean/Result.java
@@ -0,0 +1,40 @@
+package com.yang.bean;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlValue;
+import java.io.Serializable;
+
+/**
+ * Created by Dev_yang on 2017/3/5.
+ */
+public class Result implements Serializable{
+
+ private String name;
+ private String value;
+
+ @XmlAttribute(name = "name")
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @XmlValue
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return "Result{" +
+ "name='" + name + '\'' +
+ ", value='" + value + '\'' +
+ '}';
+ }
+}
diff --git a/group11/501294009/JavaProject/module2/src/main/java/com/yang/bean/Struts.java b/group11/501294009/JavaProject/module2/src/main/java/com/yang/bean/Struts.java
new file mode 100644
index 0000000000..ad16ccc057
--- /dev/null
+++ b/group11/501294009/JavaProject/module2/src/main/java/com/yang/bean/Struts.java
@@ -0,0 +1,34 @@
+
+package com.yang.bean;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.io.Serializable;
+import java.util.List;
+
+
+
+@XmlRootElement(name = "struts")
+public class Struts implements Serializable{
+
+ private List actions;
+
+
+ @XmlElement(name = "action")
+ public List getActions() {
+ return actions;
+ }
+
+
+ public void setActions(List actions) {
+ this.actions = actions;
+ }
+
+
+ @Override
+ public String toString() {
+ return "Struts{" +
+ "actions=" + actions +
+ '}';
+ }
+}
diff --git a/group11/501294009/JavaProject/module2/src/main/resources/struts.xml b/group11/501294009/JavaProject/module2/src/main/resources/struts.xml
new file mode 100644
index 0000000000..9c989a77e3
--- /dev/null
+++ b/group11/501294009/JavaProject/module2/src/main/resources/struts.xml
@@ -0,0 +1,11 @@
+
+
+
+ /jsp/homepage.jsp
+ /jsp/showLogin.jsp
+
+
+ /jsp/welcome.jsp
+ /jsp/error.jsp
+
+
\ No newline at end of file
From ec4aa08fe5b4a3878c722fb9193d1d42d15d44a3 Mon Sep 17 00:00:00 2001
From: Dev_yang <501294009@qq.com>
Date: Mon, 6 Mar 2017 23:46:49 +0800
Subject: [PATCH 006/155] delete .idea folder
---
.../JavaProject/.idea/uiDesigner.xml | 124 ------------------
1 file changed, 124 deletions(-)
delete mode 100644 group11/501294009/JavaProject/.idea/uiDesigner.xml
diff --git a/group11/501294009/JavaProject/.idea/uiDesigner.xml b/group11/501294009/JavaProject/.idea/uiDesigner.xml
deleted file mode 100644
index e96534fb27..0000000000
--- a/group11/501294009/JavaProject/.idea/uiDesigner.xml
+++ /dev/null
@@ -1,124 +0,0 @@
-
-
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
- -
-
-
- -
-
-
-
-
-
\ No newline at end of file
From c232163a721bd174a4213cbcc82feef4942092d2 Mon Sep 17 00:00:00 2001
From: xiongrui
Date: Tue, 7 Mar 2017 13:28:47 +0800
Subject: [PATCH 007/155] Basic framework
---
group22/627559964/.classpath | 6 +
group22/627559964/.gitignore | 1 +
group22/627559964/.project | 17 +++
.../src/com/coding/basic/ArrayList.java | 33 +++++
.../src/com/coding/basic/BinaryTreeNode.java | 37 ++++++
.../src/com/coding/basic/Iterator.java | 9 ++
.../src/com/coding/basic/LinkedList.java | 125 ++++++++++++++++++
.../627559964/src/com/coding/basic/List.java | 13 ++
.../627559964/src/com/coding/basic/Queue.java | 19 +++
.../627559964/src/com/coding/basic/Stack.java | 24 ++++
10 files changed, 284 insertions(+)
create mode 100644 group22/627559964/.classpath
create mode 100644 group22/627559964/.gitignore
create mode 100644 group22/627559964/.project
create mode 100644 group22/627559964/src/com/coding/basic/ArrayList.java
create mode 100644 group22/627559964/src/com/coding/basic/BinaryTreeNode.java
create mode 100644 group22/627559964/src/com/coding/basic/Iterator.java
create mode 100644 group22/627559964/src/com/coding/basic/LinkedList.java
create mode 100644 group22/627559964/src/com/coding/basic/List.java
create mode 100644 group22/627559964/src/com/coding/basic/Queue.java
create mode 100644 group22/627559964/src/com/coding/basic/Stack.java
diff --git a/group22/627559964/.classpath b/group22/627559964/.classpath
new file mode 100644
index 0000000000..fb5011632c
--- /dev/null
+++ b/group22/627559964/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/group22/627559964/.gitignore b/group22/627559964/.gitignore
new file mode 100644
index 0000000000..ae3c172604
--- /dev/null
+++ b/group22/627559964/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/group22/627559964/.project b/group22/627559964/.project
new file mode 100644
index 0000000000..870f65f4a0
--- /dev/null
+++ b/group22/627559964/.project
@@ -0,0 +1,17 @@
+
+
+ 627559964
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group22/627559964/src/com/coding/basic/ArrayList.java b/group22/627559964/src/com/coding/basic/ArrayList.java
new file mode 100644
index 0000000000..0ba3cb15a8
--- /dev/null
+++ b/group22/627559964/src/com/coding/basic/ArrayList.java
@@ -0,0 +1,33 @@
+package com.coding.basic;
+
+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;
+ }
+
+}
\ No newline at end of file
diff --git a/group22/627559964/src/com/coding/basic/BinaryTreeNode.java b/group22/627559964/src/com/coding/basic/BinaryTreeNode.java
new file mode 100644
index 0000000000..981812cf59
--- /dev/null
+++ b/group22/627559964/src/com/coding/basic/BinaryTreeNode.java
@@ -0,0 +1,37 @@
+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;
+ }
+
+}
\ No newline at end of file
diff --git a/group22/627559964/src/com/coding/basic/Iterator.java b/group22/627559964/src/com/coding/basic/Iterator.java
new file mode 100644
index 0000000000..c4c1725d21
--- /dev/null
+++ b/group22/627559964/src/com/coding/basic/Iterator.java
@@ -0,0 +1,9 @@
+package com.coding.basic;
+
+public interface Iterator {
+
+ public boolean hasNext();
+
+ public Object next();
+
+}
\ No newline at end of file
diff --git a/group22/627559964/src/com/coding/basic/LinkedList.java b/group22/627559964/src/com/coding/basic/LinkedList.java
new file mode 100644
index 0000000000..8aa70d53bd
--- /dev/null
+++ b/group22/627559964/src/com/coding/basic/LinkedList.java
@@ -0,0 +1,125 @@
+package com.coding.basic;
+
+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;
+
+ }
+
+ /**
+ * 把该链表逆置 例如链表为 3->7->10 , 逆置后变为 10->7->3
+ */
+ public void reverse() {
+
+ }
+
+ /**
+ * 删除一个单链表的前半部分 例如:list = 2->5->7->8 , 删除以后的值为 7->8 如果list = 2->5->7->8->10
+ * ,删除以后的值为7,8,10
+ */
+ public void removeFirstHalf() {
+
+ }
+
+ /**
+ * 从第i个元素开始, 删除length 个元素 , 注意i从0开始
+ *
+ * @param i
+ * @param length
+ */
+ public void remove(int i, int length) {
+
+ }
+
+ /**
+ * 假定当前链表和list均包含已升序排列的整数 从当前链表中取出那些list所指定的元素 例如当前链表 =
+ * 11->101->201->301->401->501->601->701 listB = 1->3->4->6
+ * 返回的结果应该是[101,301,401,601]
+ *
+ * @param list
+ */
+ public static int[] getElements(LinkedList list) {
+ return null;
+ }
+
+ /**
+ * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 从当前链表中中删除在list中出现的元素
+ *
+ * @param list
+ */
+
+ public void subtract(LinkedList list) {
+
+ }
+
+ /**
+ * 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同)
+ */
+ public void removeDuplicateValues() {
+
+ }
+
+ /**
+ * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素)
+ *
+ * @param min
+ * @param max
+ */
+ public void removeRange(int min, int max) {
+
+ }
+
+ /**
+ * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同)
+ * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列
+ *
+ * @param list
+ */
+ public LinkedList intersection(LinkedList list) {
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/group22/627559964/src/com/coding/basic/List.java b/group22/627559964/src/com/coding/basic/List.java
new file mode 100644
index 0000000000..8815065b99
--- /dev/null
+++ b/group22/627559964/src/com/coding/basic/List.java
@@ -0,0 +1,13 @@
+package com.coding.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();
+}
\ No newline at end of file
diff --git a/group22/627559964/src/com/coding/basic/Queue.java b/group22/627559964/src/com/coding/basic/Queue.java
new file mode 100644
index 0000000000..a487336ffe
--- /dev/null
+++ b/group22/627559964/src/com/coding/basic/Queue.java
@@ -0,0 +1,19 @@
+package com.coding.basic;
+
+public class Queue {
+
+ public void enQueue(Object o) {
+ }
+
+ public Object deQueue() {
+ return null;
+ }
+
+ public boolean isEmpty() {
+ return false;
+ }
+
+ public int size() {
+ return -1;
+ }
+}
\ No newline at end of file
diff --git a/group22/627559964/src/com/coding/basic/Stack.java b/group22/627559964/src/com/coding/basic/Stack.java
new file mode 100644
index 0000000000..b68067ee75
--- /dev/null
+++ b/group22/627559964/src/com/coding/basic/Stack.java
@@ -0,0 +1,24 @@
+package com.coding.basic;
+
+public class Stack {
+ private ArrayList elementData = new ArrayList();
+
+ public void push(Object o) {
+ }
+
+ public Object pop() {
+ return null;
+ }
+
+ public Object peek() {
+ return null;
+ }
+
+ public boolean isEmpty() {
+ return false;
+ }
+
+ public int size() {
+ return -1;
+ }
+}
\ No newline at end of file
From 618193789ccb9eaafbc97e59ca56aa8e65fc798d Mon Sep 17 00:00:00 2001
From: xiongrui
Date: Wed, 8 Mar 2017 08:41:57 +0800
Subject: [PATCH 008/155] Complete Arraylist
---
group22/627559964/.classpath | 1 +
group22/627559964/.gitignore | 1 +
.../src/com/coding/basic/ArrayList.java | 153 +++++++++++++++++-
.../627559964/src/com/coding/basic/List.java | 3 +
group22/627559964/src/demo/Demo.java | 24 +++
5 files changed, 175 insertions(+), 7 deletions(-)
create mode 100644 group22/627559964/src/demo/Demo.java
diff --git a/group22/627559964/.classpath b/group22/627559964/.classpath
index fb5011632c..83b76b7922 100644
--- a/group22/627559964/.classpath
+++ b/group22/627559964/.classpath
@@ -1,6 +1,7 @@
+
diff --git a/group22/627559964/.gitignore b/group22/627559964/.gitignore
index ae3c172604..3727029200 100644
--- a/group22/627559964/.gitignore
+++ b/group22/627559964/.gitignore
@@ -1 +1,2 @@
/bin/
+.metadata
\ No newline at end of file
diff --git a/group22/627559964/src/com/coding/basic/ArrayList.java b/group22/627559964/src/com/coding/basic/ArrayList.java
index 0ba3cb15a8..8a1eded430 100644
--- a/group22/627559964/src/com/coding/basic/ArrayList.java
+++ b/group22/627559964/src/com/coding/basic/ArrayList.java
@@ -1,33 +1,172 @@
package com.coding.basic;
+import java.util.Arrays;
+
+/**
+ * 自定义ArrayList
+ *
+ * @author xiongrui233
+ *
+ */
public class ArrayList implements List {
+ //list长度
private int size = 0;
- private Object[] elementData = new Object[100];
+ //list的元素集合
+ private Object[] elementData = new Object[10];
- public void add(Object o) {
+ /**
+ * 合并数组
+ *
+ * @param arrays1
+ * @param arrays2
+ * @return Object[]
+ */
+ private Object[] concat(Object[] arrays1, Object[] arrays2) {
+ Object[] newArrays = new Object[arrays1.length + arrays2.length];
+ System.arraycopy(arrays1, 0, newArrays, 0, arrays1.length);
+ System.arraycopy(arrays2, 0, newArrays, arrays1.length, arrays2.length);
+ return newArrays;
+ }
+
+ /**
+ * 分割数组
+ *
+ * @param arrays
+ * @param index
+ * @return Object[]
+ */
+ private Object[] subArrays(Object[] arrays, int from, int index) {
+ Object[] tempArrays = new Object[index - from];
+ for (int i = from, j = 0; i < index; i++, j++) {
+ tempArrays[j] = arrays[i];
+ }
+ return tempArrays;
+ }
+
+ /**
+ * 动态增长list长度 策略为:newSize = oldSize * 1.5
+ *
+ * @param oldSize
+ */
+ private void grow(int oldSize) {
+ elementData = Arrays.copyOf(elementData, oldSize + oldSize / 2);
+ }
+ /**
+ * 检查在插入新元素时,list长度是否足够
+ *
+ * @param newSize
+ */
+ private void checkSize(int newSize) {
+ int oldSize = elementData.length;
+ if (newSize > oldSize) {
+ grow(oldSize);
+ }
}
+ /**
+ * 新增元素
+ *
+ * @param Object
+ */
+ public void add(Object o) {
+ checkSize(size + 1);
+ elementData[size++] = o;
+ }
+
+ /**
+ * 新增元素
+ *
+ * @param index,
+ * @param Object
+ */
public void add(int index, Object o) {
+ checkSize(size + 1);
+ Object[] arrays1 = subArrays(elementData, 0, index);
+ Object[] arrays2 = subArrays(elementData, index, elementData.length);
+ arrays1 = Arrays.copyOf(arrays1, arrays1.length + 1);
+ arrays1[index] = o;
+ size++;
+ elementData = concat(arrays1, arrays2);
}
+ /**
+ * 获得编号为index的元素
+ *
+ * @param int
+ * @return Object
+ */
public Object get(int index) {
- return null;
+ return elementData[index];
}
+ /**
+ * 删除编号为index的元素
+ *
+ * @param int
+ * @return Object
+ */
public Object remove(int index) {
- return null;
+ Object[] arrays1 = subArrays(elementData, 0, index);
+ Object[] arrays2 = subArrays(elementData, index + 1, elementData.length);
+ Object obj = elementData[index];
+
+ size --;
+ elementData = concat(arrays1, arrays2);
+ return obj;
}
-
+
+ /**
+ * 返回list长度
+ *
+ * @return int
+ */
public int size() {
- return -1;
+ return size;
}
+ /**
+ * 重写迭代器
+ *
+ * @return IteratorImpl
+ */
public Iterator iterator() {
- return null;
+
+ class IteratorImpl implements Iterator {
+
+ private int point = 0;
+
+ @Override
+ public boolean hasNext() {
+ if (elementData[point] != null) {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public Object next() {
+ return elementData[point++];
+ }
+
+ }
+ return new IteratorImpl();
}
+ @Override
+ public String toString() {
+ StringBuffer list = new StringBuffer();
+ list.append("[");
+ for (int i = 0; i < elementData.length; i++) {
+ list.append(elementData);
+ if (i != elementData.length - 1) {
+ list.append(",");
+ }
+ }
+ list.append("]");
+ return list.toString();
+ }
}
\ No newline at end of file
diff --git a/group22/627559964/src/com/coding/basic/List.java b/group22/627559964/src/com/coding/basic/List.java
index 8815065b99..d04fcb7df6 100644
--- a/group22/627559964/src/com/coding/basic/List.java
+++ b/group22/627559964/src/com/coding/basic/List.java
@@ -1,6 +1,7 @@
package com.coding.basic;
public interface List {
+
public void add(Object o);
public void add(int index, Object o);
@@ -10,4 +11,6 @@ public interface List {
public Object remove(int index);
public int size();
+
+ public Iterator iterator();
}
\ No newline at end of file
diff --git a/group22/627559964/src/demo/Demo.java b/group22/627559964/src/demo/Demo.java
new file mode 100644
index 0000000000..de5ec1a19c
--- /dev/null
+++ b/group22/627559964/src/demo/Demo.java
@@ -0,0 +1,24 @@
+package demo;
+
+import com.coding.basic.ArrayList;
+import com.coding.basic.Iterator;
+import com.coding.basic.List;
+
+public class Demo {
+ public static void main(String[] args) {
+
+ List list = new ArrayList();
+ for (int i = 0; i < 12; i++) {
+ list.add(new Integer(123));
+ }
+ list.add(3, new Integer(233));
+ list.add(3, new Double(233.33));
+ list.remove(6);
+ Double kk = (Double) list.get(3);
+ Iterator it = list.iterator();
+ while (it.hasNext()) {
+ System.out.println(it.next());
+ }
+ System.out.println("End");
+ }
+}
From ce7562ce7fc216a5ea25518fc9fcd74004173ed7 Mon Sep 17 00:00:00 2001
From: cjl1407 <1158477486@qq.com>
Date: Wed, 8 Mar 2017 09:58:12 +0800
Subject: [PATCH 009/155] this is text
---
group22/1158477486/src/my.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 group22/1158477486/src/my.txt
diff --git a/group22/1158477486/src/my.txt b/group22/1158477486/src/my.txt
new file mode 100644
index 0000000000..605f61fe72
--- /dev/null
+++ b/group22/1158477486/src/my.txt
@@ -0,0 +1 @@
+这是我的一个Git
\ No newline at end of file
From 0cdb2b2e8f08cf7f0fa81772aafdc5575d4e9aee Mon Sep 17 00:00:00 2001
From: Administrator
Date: Wed, 8 Mar 2017 09:59:06 +0800
Subject: [PATCH 010/155] java se
---
group22/1158477486/src/myFist.java | 6 ++++++
1 file changed, 6 insertions(+)
create mode 100644 group22/1158477486/src/myFist.java
diff --git a/group22/1158477486/src/myFist.java b/group22/1158477486/src/myFist.java
new file mode 100644
index 0000000000..136079fbac
--- /dev/null
+++ b/group22/1158477486/src/myFist.java
@@ -0,0 +1,6 @@
+
+public class myFist {
+public static void main(String[] args) {
+ System.out.println("hello my love");
+}
+}
From 222e80b065e3b2555ace12ef5806b67e9f860488 Mon Sep 17 00:00:00 2001
From: cjl1407 <1158477486@qq.com>
Date: Wed, 8 Mar 2017 12:59:34 +0800
Subject: [PATCH 011/155] this a java demo
---
group22/1158477486/src/Test.java | 9 +++++++++
1 file changed, 9 insertions(+)
create mode 100644 group22/1158477486/src/Test.java
diff --git a/group22/1158477486/src/Test.java b/group22/1158477486/src/Test.java
new file mode 100644
index 0000000000..f106f0d3df
--- /dev/null
+++ b/group22/1158477486/src/Test.java
@@ -0,0 +1,9 @@
+
+public class Test {
+
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+System.out.println("测试中------------");
+ }
+
+}
From eee5017c54c8b4d7010110760321a2f0233c7920 Mon Sep 17 00:00:00 2001
From: xxp17457741 <17457741@qq.com>
Date: Wed, 8 Mar 2017 17:13:38 +0800
Subject: [PATCH 012/155] 17457741
---
group22/17457741/src/ArrayList.java | 110 +++++++++++++++++
group22/17457741/src/BinaryTreeNode.java | 53 ++++++++
group22/17457741/src/LinkedList.java | 149 +++++++++++++++++++++++
group22/17457741/src/Queue.java | 29 +++++
group22/17457741/src/Stack.java | 33 +++++
5 files changed, 374 insertions(+)
create mode 100644 group22/17457741/src/ArrayList.java
create mode 100644 group22/17457741/src/BinaryTreeNode.java
create mode 100644 group22/17457741/src/LinkedList.java
create mode 100644 group22/17457741/src/Queue.java
create mode 100644 group22/17457741/src/Stack.java
diff --git a/group22/17457741/src/ArrayList.java b/group22/17457741/src/ArrayList.java
new file mode 100644
index 0000000000..345538755c
--- /dev/null
+++ b/group22/17457741/src/ArrayList.java
@@ -0,0 +1,110 @@
+import java.util.Iterator锛
+import java.util.NoSuchElementException;
+
+public class ArrayList implements Iterable{
+ private static final int CAPACITY = 5;
+
+ private int size;
+
+ private T [] items;
+
+ public ArrayList(){doClear();}
+
+ public void clear(){
+ doClear();
+ }
+
+ private void doClear(){
+ this.size=0;ensureCapacity(CAPACITY);
+ }
+
+ public int size(){
+ return size;
+ }
+
+ public boolean isEmpty(){
+ return size==0;
+ }
+
+ public void trimToSize(){
+ ensureCapacity(size());
+ }
+
+ public T get( int a){
+ return items[a];
+ }
+
+ public T set(int a,T b){
+ T old = items[a];
+ items[a]=b;
+ return old;
+ }
+
+ public void ensureCapacity(int newCapacity){
+ if(newCapacitya;i--){
+ items[i]=items[i-1];
+ }
+ items[a]=b;
+ size++;
+ }
+
+ public T remove(int a){
+ T removedItem=items[a];
+ for(int i=a;i iterator() {
+ // TODO Auto-generated method stub
+ return new ArrayListIterator();
+ }
+
+ private class ArrayListIterator implements Iterator{
+
+ private int current =0;
+
+ @Override
+ public boolean hasNext() {
+ // TODO Auto-generated method stub
+ return current implements Iterable{
+ private Nodebegin;
+ private Nodeend;
+ private int size;
+ private int modCount=0;
+
+ public LinkedList(){
+ doClear();
+ }
+ public void clear(){
+ doClear();
+ }
+ private void doClear(){
+ begin=new Node(null,null,null);
+ end=new Node(null,begin,null);
+ begin.next=end;
+ }
+
+ public int size(){
+ return size;
+ }
+ public boolean isEmpty(){
+ return size==0;
+ }
+
+ public boolean add( T x){
+ add(size(),x);
+ return true;
+ }
+ public void add(int a,T x){
+ addBefore(getNode(a,0,size()),x);
+ }
+
+ public T get(int a){
+ return getNode(a).data;
+ }
+ public T set(int a,T newVal){
+ Nodep=getNode(a);
+ T old=p.data;
+ p.data=newVal;
+ return old;
+ }
+
+ public T remove(int a){
+ return remove(getNode(a));
+ }
+
+ private void addBefore(Nodep,T x){
+ Node newNode=new Node<>(x,p.prev,p);
+ newNode.prev.next=newNode;
+ p.prev=newNode;
+ size++;
+ modCount--;
+ }
+
+ private T remove(Nodep){
+ p.next.prev=p.prev;
+ p.prev.next=p.next;
+ size--;
+ modCount++;
+
+ return p.data;
+ }
+
+ private NodegetNode(int a){
+ return getNode(a,0,size()-1);
+ }
+
+ private NodegetNode(int a,int lower,int upper){
+ Nodep;
+
+ if(aupper)
+ throw new IndexOutOfBoundsException();
+ if(aa;i--)
+ p=p.prev;
+ }
+ return p;
+ }
+ @Override
+ public Iterator iterator() {
+ // TODO Auto-generated method stub
+ return new LinkedListIterator();
+ }
+ private class LinkedListIterator implements Iterator{
+ private Node current=begin.next;
+ private int expectedModCount=modCount;
+ private boolean toRemove=false;
+
+ @Override
+ public boolean hasNext() {
+ // TODO Auto-generated method stub
+ return current!=end;
+ }
+ @Override
+ public T next() {
+ // TODO Auto-generated method stub
+ if(modCount!=expectedModCount)
+ throw new java.util.ConcurrentModificationException();
+ if(!toRemove)
+ throw new IllegalStateException();
+
+ T nextItem=current.data;
+ current=current.next;
+ toRemove=true;
+ return nextItem;
+ }
+
+ public void remove(){
+ if(modCount!=expectedModCount)
+ throw new java.util.ConcurrentModificationException();
+ if(!toRemove)
+ throw new IllegalStateException();
+
+ LinkedList.this.remove(current.prev);
+ expectedModCount++;
+ toRemove=false;
+ }
+ }
+
+ private static class Node{
+
+ public T data;
+ public Node prev;
+ public Node next;
+
+ public Node(T d, Node p,Node n) {
+ // TODO Auto-generated constructor stub
+ data=d;prev=p;next=n;
+ }
+
+ }
+
+}
+
diff --git a/group22/17457741/src/Queue.java b/group22/17457741/src/Queue.java
new file mode 100644
index 0000000000..b98d8e2043
--- /dev/null
+++ b/group22/17457741/src/Queue.java
@@ -0,0 +1,29 @@
+
+
+public class Queue {
+
+ private ArrayList list = new ArrayList();
+
+ public void enQueue(Object o) {
+ list.add(o);
+ }
+
+ public Object deQueue() {
+ final int size = list.size();
+ if (0 == size)
+ return null;
+ Object o = list.remove(size);
+ return o;
+ }
+
+ public boolean isEmpty() {
+ return list.isEmpty();
+ }
+
+ public int size() {
+ return list.size();
+ }
+
+}
+
+
diff --git a/group22/17457741/src/Stack.java b/group22/17457741/src/Stack.java
new file mode 100644
index 0000000000..12f870566f
--- /dev/null
+++ b/group22/17457741/src/Stack.java
@@ -0,0 +1,33 @@
+
+
+public class Stack {
+ private ArrayList elementData = new ArrayList();
+
+ public void push(Object o){
+
+ elementData.add(o);
+ }
+
+ public Object peek(){
+ return elementData.get(0);
+ }
+
+ public Object pop(){
+ Object a = null;
+ if(elementData.size() > 0) {
+
+ a = elementData.get(elementData.size() - 1);
+ elementData.remove(elementData.size() - 1);
+ }
+ return a;
+ }
+
+ public boolean isEmpty(){
+ return elementData.size() == 0;
+ }
+
+ public int size(){
+ return elementData.size();
+ }
+
+}
From 1cd0c34be6d711ad95386830796611e94d2915ee Mon Sep 17 00:00:00 2001
From: xxp17457741 <17457741@qq.com>
Date: Wed, 8 Mar 2017 17:14:54 +0800
Subject: [PATCH 013/155] 17457741
---
group22/17457741/src/ArrayList.java | 2 +-
group22/17457741/src/LinkedList.java | 3 +--
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/group22/17457741/src/ArrayList.java b/group22/17457741/src/ArrayList.java
index 345538755c..45b583d13c 100644
--- a/group22/17457741/src/ArrayList.java
+++ b/group22/17457741/src/ArrayList.java
@@ -1,4 +1,4 @@
-import java.util.Iterator锛
+import java.util.Iterator;
import java.util.NoSuchElementException;
public class ArrayList implements Iterable{
diff --git a/group22/17457741/src/LinkedList.java b/group22/17457741/src/LinkedList.java
index d7c4fe3415..c098978572 100644
--- a/group22/17457741/src/LinkedList.java
+++ b/group22/17457741/src/LinkedList.java
@@ -1,7 +1,6 @@
import java.util.Iterator;
-import LinkedList.LinkedListIterator;
-import LinkedList.Node;
+
From 009358e1f49f5057ea678ebb9774c0bc00cfd873 Mon Sep 17 00:00:00 2001
From: Administrator
Date: Wed, 8 Mar 2017 17:15:07 +0800
Subject: [PATCH 014/155] =?UTF-8?q?list=20=E9=9B=86=E5=90=88?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
group22/1158477486/src/TestCollection/List.java | 9 +++++++++
1 file changed, 9 insertions(+)
create mode 100644 group22/1158477486/src/TestCollection/List.java
diff --git a/group22/1158477486/src/TestCollection/List.java b/group22/1158477486/src/TestCollection/List.java
new file mode 100644
index 0000000000..1b14c3ebe6
--- /dev/null
+++ b/group22/1158477486/src/TestCollection/List.java
@@ -0,0 +1,9 @@
+package TestCollection;
+
+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();
+}
From ffc07a4ae94ca5232e51a91821bd76ce0a06fa58 Mon Sep 17 00:00:00 2001
From: laoheihei
Date: Thu, 9 Mar 2017 10:52:45 +0800
Subject: [PATCH 015/155] template
---
group22/2622819383/Task1/ArrayList.java | 30 +++++
group22/2622819383/Task1/BinaryTreeNode.java | 30 +++++
group22/2622819383/Task1/Iterator.java | 5 +
group22/2622819383/Task1/LinkedList.java | 120 +++++++++++++++++++
group22/2622819383/Task1/List.java | 7 ++
group22/2622819383/Task1/Queue.java | 17 +++
group22/2622819383/Task1/Stack.java | 20 ++++
7 files changed, 229 insertions(+)
create mode 100644 group22/2622819383/Task1/ArrayList.java
create mode 100644 group22/2622819383/Task1/BinaryTreeNode.java
create mode 100644 group22/2622819383/Task1/Iterator.java
create mode 100644 group22/2622819383/Task1/LinkedList.java
create mode 100644 group22/2622819383/Task1/List.java
create mode 100644 group22/2622819383/Task1/Queue.java
create mode 100644 group22/2622819383/Task1/Stack.java
diff --git a/group22/2622819383/Task1/ArrayList.java b/group22/2622819383/Task1/ArrayList.java
new file mode 100644
index 0000000000..ca9faa3291
--- /dev/null
+++ b/group22/2622819383/Task1/ArrayList.java
@@ -0,0 +1,30 @@
+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/group22/2622819383/Task1/BinaryTreeNode.java b/group22/2622819383/Task1/BinaryTreeNode.java
new file mode 100644
index 0000000000..1f07869939
--- /dev/null
+++ b/group22/2622819383/Task1/BinaryTreeNode.java
@@ -0,0 +1,30 @@
+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/group22/2622819383/Task1/Iterator.java b/group22/2622819383/Task1/Iterator.java
new file mode 100644
index 0000000000..96a43dbe0a
--- /dev/null
+++ b/group22/2622819383/Task1/Iterator.java
@@ -0,0 +1,5 @@
+public interface Iterator {
+ public boolean hasNext();
+ public Object next();
+
+}
diff --git a/group22/2622819383/Task1/LinkedList.java b/group22/2622819383/Task1/LinkedList.java
new file mode 100644
index 0000000000..d431e25fdb
--- /dev/null
+++ b/group22/2622819383/Task1/LinkedList.java
@@ -0,0 +1,120 @@
+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;
+
+ }
+
+ /**
+ * 鎶婅閾捐〃閫嗙疆
+ * 渚嬪閾捐〃涓 3->7->10 , 閫嗙疆鍚庡彉涓 10->7->3
+ */
+ public void reverse(){
+
+ }
+
+ /**
+ * 鍒犻櫎涓涓崟閾捐〃鐨勫墠鍗婇儴鍒
+ * 渚嬪锛歭ist = 2->5->7->8 , 鍒犻櫎浠ュ悗鐨勫间负 7->8
+ * 濡傛灉list = 2->5->7->8->10 ,鍒犻櫎浠ュ悗鐨勫间负7,8,10
+
+ */
+ public void removeFirstHalf(){
+
+ }
+
+ /**
+ * 浠庣i涓厓绱犲紑濮嬶紝 鍒犻櫎length 涓厓绱 锛 娉ㄦ剰i浠0寮濮
+ * @param i
+ * @param length
+ */
+ public void remove(int i, int length){
+
+ }
+ /**
+ * 鍋囧畾褰撳墠閾捐〃鍜宭ist鍧囧寘鍚凡鍗囧簭鎺掑垪鐨勬暣鏁
+ * 浠庡綋鍓嶉摼琛ㄤ腑鍙栧嚭閭d簺list鎵鎸囧畾鐨勫厓绱
+ * 渚嬪褰撳墠閾捐〃 = 11->101->201->301->401->501->601->701
+ * listB = 1->3->4->6
+ * 杩斿洖鐨勭粨鏋滃簲璇ユ槸[101,301,401,601]
+ * @param list
+ */
+ public static int[] getElements(LinkedList list){
+ return null;
+ }
+
+ /**
+ * 宸茬煡閾捐〃涓殑鍏冪礌浠ュ奸掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩
+ * 浠庡綋鍓嶉摼琛ㄤ腑涓垹闄ゅ湪list涓嚭鐜扮殑鍏冪礌
+
+ * @param list
+ */
+
+ public void subtract(LinkedList list){
+
+ }
+
+ /**
+ * 宸茬煡褰撳墠閾捐〃涓殑鍏冪礌浠ュ奸掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩
+ * 鍒犻櫎琛ㄤ腑鎵鏈夊肩浉鍚岀殑澶氫綑鍏冪礌锛堜娇寰楁搷浣滃悗鐨勭嚎鎬ц〃涓墍鏈夊厓绱犵殑鍊煎潎涓嶇浉鍚岋級
+ */
+ public void removeDuplicateValues(){
+
+ }
+
+ /**
+ * 宸茬煡閾捐〃涓殑鍏冪礌浠ュ奸掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩
+ * 璇曞啓涓楂樻晥鐨勭畻娉曪紝鍒犻櫎琛ㄤ腑鎵鏈夊煎ぇ浜巑in涓斿皬浜巑ax鐨勫厓绱狅紙鑻ヨ〃涓瓨鍦ㄨ繖鏍风殑鍏冪礌锛
+ * @param min
+ * @param max
+ */
+ public void removeRange(int min, int max){
+
+ }
+
+ /**
+ * 鍋囪褰撳墠閾捐〃鍜屽弬鏁發ist鎸囧畾鐨勯摼琛ㄥ潎浠ュ厓绱犱緷鍊奸掑鏈夊簭鎺掑垪锛堝悓涓琛ㄤ腑鐨勫厓绱犲煎悇涓嶇浉鍚岋級
+ * 鐜拌姹傜敓鎴愭柊閾捐〃C锛屽叾鍏冪礌涓哄綋鍓嶉摼琛ㄥ拰list涓厓绱犵殑浜ら泦锛屼笖琛–涓殑鍏冪礌鏈変緷鍊奸掑鏈夊簭鎺掑垪
+ * @param list
+ */
+ public LinkedList intersection( LinkedList list){
+ return null;
+ }
+}
diff --git a/group22/2622819383/Task1/List.java b/group22/2622819383/Task1/List.java
new file mode 100644
index 0000000000..4f7bcc71a8
--- /dev/null
+++ b/group22/2622819383/Task1/List.java
@@ -0,0 +1,7 @@
+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/group22/2622819383/Task1/Queue.java b/group22/2622819383/Task1/Queue.java
new file mode 100644
index 0000000000..08f1e8ba29
--- /dev/null
+++ b/group22/2622819383/Task1/Queue.java
@@ -0,0 +1,17 @@
+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/group22/2622819383/Task1/Stack.java b/group22/2622819383/Task1/Stack.java
new file mode 100644
index 0000000000..6c8c49bb10
--- /dev/null
+++ b/group22/2622819383/Task1/Stack.java
@@ -0,0 +1,20 @@
+public class Stack {
+ private ArrayList elementData = new ArrayList();
+
+ public void push(Object o){
+ }
+
+ public Object pop(){
+ return null;
+ }
+
+ public Object peek(){
+ return null;
+ }
+ public boolean isEmpty(){
+ return false;
+ }
+ public int size(){
+ return -1;
+ }
+}
From aa9a515649cce4260ed37acdb85cf1fe330104e7 Mon Sep 17 00:00:00 2001
From: laoheihei
Date: Thu, 9 Mar 2017 12:26:19 +0800
Subject: [PATCH 016/155] done with ArrayList.java
---
group22/2622819383/Task1/ArrayList.java | 136 ++++++++++++++++++++++--
1 file changed, 125 insertions(+), 11 deletions(-)
diff --git a/group22/2622819383/Task1/ArrayList.java b/group22/2622819383/Task1/ArrayList.java
index ca9faa3291..1c060ffe3a 100644
--- a/group22/2622819383/Task1/ArrayList.java
+++ b/group22/2622819383/Task1/ArrayList.java
@@ -1,30 +1,144 @@
public class ArrayList implements List {
- private int size = 0;
+ private int size;
+
+ private int capacity;
+
+ private static final int DEFAULT_CAPACITY = 10;
- private Object[] elementData = new Object[100];
+ private Object[] elementData;
+
+ //add()时用于扩容
+ private void expand() {
+ if (size < capacity) return;//尚未满员,不必扩容
+
+ if (capacity < DEFAULT_CAPACITY) capacity = DEFAULT_CAPACITY;//不低于最小容量
+
+ Object[] oldElem = elementData;
+ elementData = new Object[capacity <<= 1];
+ for (int i = 0; i < size; i++)
+ elementData[i] = oldElem[i];
+ }
+
+ //remove()时用于缩容
+ private void shrink() {
+ if (capacity < DEFAULT_CAPACITY << 1) return;//不致收缩至DEFAULT_CAPACITY以下
+
+ if (capacity >> 2 < size) return; //以25%为界
+
+ Object[] oldElem = elementData; elementData = new Object[capacity >>= 1];
+ for (int i = 0; i < size; i++)
+ elementData[i] = oldElem[i];
+
+ }
+
+ public ArrayList() {
+ clear();
+ }
+
+ public ArrayList(Object ...args) {
+ this();
+ for (Object o : args)
+ add(o);
+ }
+
+ public void clear() {
+ size = 0;
+ elementData = new Object[capacity = DEFAULT_CAPACITY];
+ }
+ public int size() { return size; }
+
+ public int capacity() { return capacity; }//用于测试shrink()&expand()
+
+ public boolean isEmpty() { return size == 0; }
+
public void add(Object o){
-
+ add(size(), o);
}
public void add(int index, Object o){
-
+ if (index < 0 || size < index) throw new IndexOutOfBoundsException();
+ expand();
+
+ for (int i = size; i > index; i--)
+ elementData[i] = elementData[i - 1];
+ elementData[index] = o;
+
+ size++;
}
+ public void add(Object ...args) {
+ for (Object o : args)
+ add(o);
+ }
public Object get(int index){
- return null;
+ if (index < 0 || size <= index) throw new IndexOutOfBoundsException();
+ return elementData[index];
}
public Object remove(int index){
- return null;
- }
-
- public int size(){
- return -1;
+ if (index < 0 || size <= index) throw new IndexOutOfBoundsException();
+
+ Object removed = elementData[index];
+
+ for (int i = index; i < size - 1; i++)
+ elementData[i] = elementData[i + 1];
+ size--;
+ shrink();
+ return removed;
}
+
+ public void removeElems(int ...args) {
+ for (int i : args)
+ remove(i);
+ }
public Iterator iterator(){
- return null;
+ return new ArrayListIterator();
}
+ private class ArrayListIterator implements Iterator {
+ private int current;
+ public boolean hasNext() { return current != size; }
+ public Object next() {
+ if (!hasNext()) throw new java.util.NoSuchElementException();
+
+ return elementData[current++];
+ }
+ }
+ public static void showElements(ArrayList list) {
+ System.out.print("当前list中元素:");
+ Iterator iter = list.iterator();
+ while (iter.hasNext())
+ System.out.print(iter.next() + " ");
+ System.out.println();
+ }
+
+ public static void test(ArrayList list) {
+ System.out.println("--------基本方法测试---------");
+ System.out.println("当前list.isEmpty(): " + list.isEmpty());
+ System.out.println("当前list.size(): " + list.size());
+ System.out.println("当前list.capacity(): " + list.capacity());
+ showElements(list);
+
+ }
+
+ public static void main(String[] args) {
+ ArrayList list = new ArrayList(1, 2, 3, 4, 5);
+ test(list);
+ list.add(6, 7, 8, 9, 10);
+ test(list);
+ list.add(3, 11);
+ list.get(3);
+ test(list);
+ list.remove(3);
+ test(list);
+ list.add(11,12,13,14,15,16,17,18,19,20,21,22,23,24);
+ test(list);
+
+ list.removeElems(1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
+ test(list);
+
+
+ }
}
From f1691151953a645e9e602ed2111434a611b981df Mon Sep 17 00:00:00 2001
From: laoheihei
Date: Thu, 9 Mar 2017 12:32:42 +0800
Subject: [PATCH 017/155] add ignore file
---
group22/2622819383/Task1/.gitignore | 1 +
1 file changed, 1 insertion(+)
create mode 100644 group22/2622819383/Task1/.gitignore
diff --git a/group22/2622819383/Task1/.gitignore b/group22/2622819383/Task1/.gitignore
new file mode 100644
index 0000000000..5241a7220a
--- /dev/null
+++ b/group22/2622819383/Task1/.gitignore
@@ -0,0 +1 @@
+*.class
\ No newline at end of file
From e2d14dc6809168c62a49e5c14750feeeba76f6d7 Mon Sep 17 00:00:00 2001
From: xiongrui
Date: Thu, 9 Mar 2017 17:16:21 +0800
Subject: [PATCH 018/155] simple complete Stack
---
.../src/com/coding/basic/ArrayList.java | 24 ++++++++++---------
.../627559964/src/com/coding/basic/Stack.java | 15 ++++++++----
2 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/group22/627559964/src/com/coding/basic/ArrayList.java b/group22/627559964/src/com/coding/basic/ArrayList.java
index 8a1eded430..e20bd4ca45 100644
--- a/group22/627559964/src/com/coding/basic/ArrayList.java
+++ b/group22/627559964/src/com/coding/basic/ArrayList.java
@@ -10,10 +10,10 @@
*/
public class ArrayList implements List {
- //list长度
+ // list长度
private int size = 0;
- //list的元素集合
+ // list的元素集合
private Object[] elementData = new Object[10];
/**
@@ -34,6 +34,7 @@ private Object[] concat(Object[] arrays1, Object[] arrays2) {
* 分割数组
*
* @param arrays
+ * @param from
* @param index
* @return Object[]
*/
@@ -46,7 +47,8 @@ private Object[] subArrays(Object[] arrays, int from, int index) {
}
/**
- * 动态增长list长度 策略为:newSize = oldSize * 1.5
+ * 动态增长list长度
+ * 策略为:newSize = oldSize * 1.5
*
* @param oldSize
*/
@@ -79,7 +81,7 @@ public void add(Object o) {
/**
* 新增元素
*
- * @param index,
+ * @param index
* @param Object
*/
public void add(int index, Object o) {
@@ -113,12 +115,12 @@ public Object remove(int index) {
Object[] arrays1 = subArrays(elementData, 0, index);
Object[] arrays2 = subArrays(elementData, index + 1, elementData.length);
Object obj = elementData[index];
-
- size --;
+
+ size--;
elementData = concat(arrays1, arrays2);
return obj;
}
-
+
/**
* 返回list长度
*
@@ -129,16 +131,16 @@ public int size() {
}
/**
- * 重写迭代器
+ * 重写迭代器
*
* @return IteratorImpl
*/
public Iterator iterator() {
-
+
class IteratorImpl implements Iterator {
private int point = 0;
-
+
@Override
public boolean hasNext() {
if (elementData[point] != null) {
@@ -151,7 +153,7 @@ public boolean hasNext() {
public Object next() {
return elementData[point++];
}
-
+
}
return new IteratorImpl();
}
diff --git a/group22/627559964/src/com/coding/basic/Stack.java b/group22/627559964/src/com/coding/basic/Stack.java
index b68067ee75..0d93aabb47 100644
--- a/group22/627559964/src/com/coding/basic/Stack.java
+++ b/group22/627559964/src/com/coding/basic/Stack.java
@@ -1,24 +1,31 @@
package com.coding.basic;
public class Stack {
+
private ArrayList elementData = new ArrayList();
public void push(Object o) {
+ elementData.add(o);
}
public Object pop() {
- return null;
+ Object obj = elementData.get(0);
+ elementData.remove(0);
+ return obj;
}
public Object peek() {
- return null;
+ return elementData.get(0);
}
public boolean isEmpty() {
- return false;
+ if (elementData.size() != 0) {
+ return false;
+ }
+ return true;
}
public int size() {
- return -1;
+ return elementData.size();
}
}
\ No newline at end of file
From bee5ae231502b9acd178949b0d3c31e23f3ab6c1 Mon Sep 17 00:00:00 2001
From: Fred Qin
Date: Thu, 9 Mar 2017 01:34:34 -0800
Subject: [PATCH 019/155] complete linkedlist exercise
---
.../coderising/download/DownloadThread.java | 20 +
.../coderising/download/FileDownloader.java | 73 ++++
.../download/FileDownloaderTest.java | 59 +++
.../coderising/download/api/Connection.java | 23 ++
.../download/api/ConnectionException.java | 5 +
.../download/api/ConnectionManager.java | 10 +
.../download/api/DownloadListener.java | 5 +
.../download/impl/ConnectionImpl.java | 27 ++
.../download/impl/ConnectionManagerImpl.java | 15 +
.../src/com/coding/basic/LinkedList.java | 343 ++++++++++++++++--
.../src/com/coding/basic/LinkedListTest.java | 184 +++++++++-
11 files changed, 728 insertions(+), 36 deletions(-)
create mode 100644 group11/395443277/src/com/coderising/download/DownloadThread.java
create mode 100644 group11/395443277/src/com/coderising/download/FileDownloader.java
create mode 100644 group11/395443277/src/com/coderising/download/FileDownloaderTest.java
create mode 100644 group11/395443277/src/com/coderising/download/api/Connection.java
create mode 100644 group11/395443277/src/com/coderising/download/api/ConnectionException.java
create mode 100644 group11/395443277/src/com/coderising/download/api/ConnectionManager.java
create mode 100644 group11/395443277/src/com/coderising/download/api/DownloadListener.java
create mode 100644 group11/395443277/src/com/coderising/download/impl/ConnectionImpl.java
create mode 100644 group11/395443277/src/com/coderising/download/impl/ConnectionManagerImpl.java
diff --git a/group11/395443277/src/com/coderising/download/DownloadThread.java b/group11/395443277/src/com/coderising/download/DownloadThread.java
new file mode 100644
index 0000000000..900a3ad358
--- /dev/null
+++ b/group11/395443277/src/com/coderising/download/DownloadThread.java
@@ -0,0 +1,20 @@
+package com.coderising.download;
+
+import com.coderising.download.api.Connection;
+
+public class DownloadThread extends Thread{
+
+ Connection conn;
+ int startPos;
+ int endPos;
+
+ public DownloadThread( Connection conn, int startPos, int endPos){
+
+ this.conn = conn;
+ this.startPos = startPos;
+ this.endPos = endPos;
+ }
+ public void run(){
+
+ }
+}
diff --git a/group11/395443277/src/com/coderising/download/FileDownloader.java b/group11/395443277/src/com/coderising/download/FileDownloader.java
new file mode 100644
index 0000000000..c3c8a3f27d
--- /dev/null
+++ b/group11/395443277/src/com/coderising/download/FileDownloader.java
@@ -0,0 +1,73 @@
+package com.coderising.download;
+
+import com.coderising.download.api.Connection;
+import com.coderising.download.api.ConnectionException;
+import com.coderising.download.api.ConnectionManager;
+import com.coderising.download.api.DownloadListener;
+
+
+public class FileDownloader {
+
+ String url;
+
+ DownloadListener listener;
+
+ ConnectionManager cm;
+
+
+ public FileDownloader(String _url) {
+ this.url = _url;
+
+ }
+
+ public void execute(){
+ // 鍦ㄨ繖閲屽疄鐜颁綘鐨勪唬鐮侊紝 娉ㄦ剰锛 闇瑕佺敤澶氱嚎绋嬪疄鐜颁笅杞
+ // 杩欎釜绫讳緷璧栦簬鍏朵粬鍑犱釜鎺ュ彛, 浣犻渶瑕佸啓杩欏嚑涓帴鍙g殑瀹炵幇浠g爜
+ // (1) ConnectionManager , 鍙互鎵撳紑涓涓繛鎺ワ紝閫氳繃Connection鍙互璇诲彇鍏朵腑鐨勪竴娈碉紙鐢╯tartPos, endPos鏉ユ寚瀹氾級
+ // (2) DownloadListener, 鐢变簬鏄绾跨▼涓嬭浇锛 璋冪敤杩欎釜绫荤殑瀹㈡埛绔笉鐭ラ亾浠涔堟椂鍊欑粨鏉燂紝鎵浠ヤ綘闇瑕佸疄鐜板綋鎵鏈
+ // 绾跨▼閮芥墽琛屽畬浠ュ悗锛 璋冪敤listener鐨刵otifiedFinished鏂规硶锛 杩欐牱瀹㈡埛绔氨鑳芥敹鍒伴氱煡銆
+ // 鍏蜂綋鐨勫疄鐜版濊矾锛
+ // 1. 闇瑕佽皟鐢–onnectionManager鐨刼pen鏂规硶鎵撳紑杩炴帴锛 鐒跺悗閫氳繃Connection.getContentLength鏂规硶鑾峰緱鏂囦欢鐨勯暱搴
+ // 2. 鑷冲皯鍚姩3涓嚎绋嬩笅杞斤紝 娉ㄦ剰姣忎釜绾跨▼闇瑕佸厛璋冪敤ConnectionManager鐨刼pen鏂规硶
+ // 鐒跺悗璋冪敤read鏂规硶锛 read鏂规硶涓湁璇诲彇鏂囦欢鐨勫紑濮嬩綅缃拰缁撴潫浣嶇疆鐨勫弬鏁帮紝 杩斿洖鍊兼槸byte[]鏁扮粍
+ // 3. 鎶奲yte鏁扮粍鍐欏叆鍒版枃浠朵腑
+ // 4. 鎵鏈夌殑绾跨▼閮戒笅杞藉畬鎴愪互鍚庯紝 闇瑕佽皟鐢╨istener鐨刵otifiedFinished鏂规硶
+
+ // 涓嬮潰鐨勪唬鐮佹槸绀轰緥浠g爜锛 涔熷氨鏄鍙湁涓涓嚎绋嬶紝 浣犻渶瑕佹敼閫犳垚澶氱嚎绋嬬殑銆
+ Connection conn = null;
+ try {
+
+ conn = cm.open(this.url);
+
+ int length = conn.getContentLength();
+
+ new DownloadThread(conn,0,length-1).start();
+
+ } catch (ConnectionException e) {
+ e.printStackTrace();
+ }finally{
+ if(conn != null){
+ conn.close();
+ }
+ }
+
+
+
+
+ }
+
+ public void setListener(DownloadListener listener) {
+ this.listener = listener;
+ }
+
+
+
+ public void setConnectionManager(ConnectionManager ucm){
+ this.cm = ucm;
+ }
+
+ public DownloadListener getListener(){
+ return this.listener;
+ }
+
+}
diff --git a/group11/395443277/src/com/coderising/download/FileDownloaderTest.java b/group11/395443277/src/com/coderising/download/FileDownloaderTest.java
new file mode 100644
index 0000000000..4ff7f46ae0
--- /dev/null
+++ b/group11/395443277/src/com/coderising/download/FileDownloaderTest.java
@@ -0,0 +1,59 @@
+package com.coderising.download;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.coderising.download.api.ConnectionManager;
+import com.coderising.download.api.DownloadListener;
+import com.coderising.download.impl.ConnectionManagerImpl;
+
+public class FileDownloaderTest {
+ boolean downloadFinished = false;
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testDownload() {
+
+ String url = "http://localhost:8080/test.jpg";
+
+ FileDownloader downloader = new FileDownloader(url);
+
+
+ ConnectionManager cm = new ConnectionManagerImpl();
+ downloader.setConnectionManager(cm);
+
+ downloader.setListener(new DownloadListener() {
+ @Override
+ public void notifyFinished() {
+ downloadFinished = true;
+ }
+
+ });
+
+
+ downloader.execute();
+
+ // 绛夊緟澶氱嚎绋嬩笅杞界▼搴忔墽琛屽畬姣
+ while (!downloadFinished) {
+ try {
+ System.out.println("杩樻病鏈変笅杞藉畬鎴愶紝浼戠湢浜旂");
+ //浼戠湢5绉
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ System.out.println("涓嬭浇瀹屾垚锛");
+
+
+
+ }
+
+}
diff --git a/group11/395443277/src/com/coderising/download/api/Connection.java b/group11/395443277/src/com/coderising/download/api/Connection.java
new file mode 100644
index 0000000000..0957eaf7f4
--- /dev/null
+++ b/group11/395443277/src/com/coderising/download/api/Connection.java
@@ -0,0 +1,23 @@
+package com.coderising.download.api;
+
+import java.io.IOException;
+
+public interface Connection {
+ /**
+ * 缁欏畾寮濮嬪拰缁撴潫浣嶇疆锛 璇诲彇鏁版嵁锛 杩斿洖鍊兼槸瀛楄妭鏁扮粍
+ * @param startPos 寮濮嬩綅缃紝 浠0寮濮
+ * @param endPos 缁撴潫浣嶇疆
+ * @return
+ */
+ public byte[] read(int startPos,int endPos) throws IOException;
+ /**
+ * 寰楀埌鏁版嵁鍐呭鐨勯暱搴
+ * @return
+ */
+ public int getContentLength();
+
+ /**
+ * 鍏抽棴杩炴帴
+ */
+ public void close();
+}
diff --git a/group11/395443277/src/com/coderising/download/api/ConnectionException.java b/group11/395443277/src/com/coderising/download/api/ConnectionException.java
new file mode 100644
index 0000000000..1551a80b3d
--- /dev/null
+++ b/group11/395443277/src/com/coderising/download/api/ConnectionException.java
@@ -0,0 +1,5 @@
+package com.coderising.download.api;
+
+public class ConnectionException extends Exception {
+
+}
diff --git a/group11/395443277/src/com/coderising/download/api/ConnectionManager.java b/group11/395443277/src/com/coderising/download/api/ConnectionManager.java
new file mode 100644
index 0000000000..ce045393b1
--- /dev/null
+++ b/group11/395443277/src/com/coderising/download/api/ConnectionManager.java
@@ -0,0 +1,10 @@
+package com.coderising.download.api;
+
+public interface ConnectionManager {
+ /**
+ * 缁欏畾涓涓猽rl , 鎵撳紑涓涓繛鎺
+ * @param url
+ * @return
+ */
+ public Connection open(String url) throws ConnectionException;
+}
diff --git a/group11/395443277/src/com/coderising/download/api/DownloadListener.java b/group11/395443277/src/com/coderising/download/api/DownloadListener.java
new file mode 100644
index 0000000000..bf9807b307
--- /dev/null
+++ b/group11/395443277/src/com/coderising/download/api/DownloadListener.java
@@ -0,0 +1,5 @@
+package com.coderising.download.api;
+
+public interface DownloadListener {
+ public void notifyFinished();
+}
diff --git a/group11/395443277/src/com/coderising/download/impl/ConnectionImpl.java b/group11/395443277/src/com/coderising/download/impl/ConnectionImpl.java
new file mode 100644
index 0000000000..36a9d2ce15
--- /dev/null
+++ b/group11/395443277/src/com/coderising/download/impl/ConnectionImpl.java
@@ -0,0 +1,27 @@
+package com.coderising.download.impl;
+
+import java.io.IOException;
+
+import com.coderising.download.api.Connection;
+
+public class ConnectionImpl implements Connection{
+
+ @Override
+ public byte[] read(int startPos, int endPos) throws IOException {
+
+ return null;
+ }
+
+ @Override
+ public int getContentLength() {
+
+ return 0;
+ }
+
+ @Override
+ public void close() {
+
+
+ }
+
+}
diff --git a/group11/395443277/src/com/coderising/download/impl/ConnectionManagerImpl.java b/group11/395443277/src/com/coderising/download/impl/ConnectionManagerImpl.java
new file mode 100644
index 0000000000..172371dd55
--- /dev/null
+++ b/group11/395443277/src/com/coderising/download/impl/ConnectionManagerImpl.java
@@ -0,0 +1,15 @@
+package com.coderising.download.impl;
+
+import com.coderising.download.api.Connection;
+import com.coderising.download.api.ConnectionException;
+import com.coderising.download.api.ConnectionManager;
+
+public class ConnectionManagerImpl implements ConnectionManager {
+
+ @Override
+ public Connection open(String url) throws ConnectionException {
+
+ return null;
+ }
+
+}
diff --git a/group11/395443277/src/com/coding/basic/LinkedList.java b/group11/395443277/src/com/coding/basic/LinkedList.java
index fb9fbd81ca..df5d62aed8 100644
--- a/group11/395443277/src/com/coding/basic/LinkedList.java
+++ b/group11/395443277/src/com/coding/basic/LinkedList.java
@@ -3,84 +3,99 @@
import java.util.NoSuchElementException;
public class LinkedList implements List {
+
private Node head;
-
- public void add(Object o){
+
+ public void add(Object o) {
Node newNode = new Node();
newNode.data = o;
newNode.next = null;
-
+
if (head == null) {
head = newNode;
} else {
Node curr = head;
- while(curr.next != null) {
+ while (curr.next != null) {
curr = curr.next;
}
curr.next = newNode;
}
}
- public void add(int index , Object o){
+
+ public void add(int index, Object o) {
Node newNode = new Node();
newNode.data = o;
newNode.next = null;
-
+
+ if (index == 0) {
+ this.addFirst(o);
+ return;
+ }
+
if (head == null) {
head = newNode;
} else {
Node curr = head;
Node prev = curr;
- while(index >0 && curr.next != null) {
+ while (index > 0 && curr.next != null) {
prev = curr;
curr = curr.next;
index--;
}
-
+
prev.next = newNode;
newNode.next = curr;
}
}
- public Object get(int index){
+
+ public Object get(int index) {
+ if (index >= this.size()) {
+ return null;
+ }
+
Node curr = head;
- while(index > 0) {
+ while (index > 0) {
curr = curr.next;
index--;
- }
+ }
return curr.data;
}
- public Object remove(int index){
- if (index ==0) {
+
+ public Object remove(int index) {
+ if (index == 0) {
return this.removeFirst();
}
-
+
Node curr = head;
Node prev = curr;
- while(index >0 && curr.next != null) {
+ while (index > 0 && curr.next != null) {
prev = curr;
curr = curr.next;
index--;
}
-
+
Object target = curr.data;
prev.next = curr.next;
curr.next = null;
-
+
return target;
}
- public int size(){
+
+ public int size() {
int size = 0;
Node curr = head;
- while(curr != null) {
+ while (curr != null) {
size++;
curr = curr.next;
}
return size;
}
- public void addFirst(Object o){
+
+ public void addFirst(Object o) {
Node newNode = new Node();
newNode.data = o;
newNode.next = null;
-
+
if (head == null) {
head = newNode;
} else {
@@ -88,37 +103,40 @@ public void addFirst(Object o){
head.next = newNode;
}
}
- public void addLast(Object o){
+
+ public void addLast(Object o) {
Node newNode = new Node();
newNode.data = o;
newNode.next = null;
-
+
Node curr = head;
if (head == null) {
head = newNode;
} else {
- while(curr.next != null) {
+ while (curr.next != null) {
curr = curr.next;
}
curr.next = newNode;
}
}
- public Object removeFirst(){
+
+ public Object removeFirst() {
if (head == null) {
return null;
}
-
+
Object target = head.data;
head = head.next;
return target;
}
- public Object removeLast(){
+
+ public Object removeLast() {
if (head == null) {
return null;
}
Node curr = head;
Node prev = curr;
- while(curr.next != null) {
+ while (curr.next != null) {
prev = curr;
curr = curr.next;
}
@@ -126,13 +144,23 @@ public Object removeLast(){
prev.next = null;
return target;
}
- public Iterator iterator(){
+
+ public void print() {
+ Node curr = head;
+
+ while (curr != null) {
+ System.out.println(curr.data);
+ curr = curr.next;
+ }
+ }
+
+ public Iterator iterator() {
return new SeqIterator();
}
-
+
private class SeqIterator implements Iterator {
Node curr = head;
-
+
@Override
public boolean hasNext() {
return curr != null;
@@ -140,17 +168,262 @@ public boolean hasNext() {
@Override
public Object next() {
- if (!hasNext()) throw new NoSuchElementException();
+ if (!hasNext())
+ throw new NoSuchElementException();
Object target = curr.data;
curr = curr.next;
return target;
}
}
-
- private static class Node{
+
+ private static class Node {
Object data;
Node next;
-
+ }
+
+ /**
+ * 鎶婅閾捐〃閫嗙疆 渚嬪閾捐〃涓 3->7->10 , 閫嗙疆鍚庡彉涓 10->7->3
+ */
+ public void reverse() {
+ if (head != null) {
+ Node curr = head;
+ Node nextNode = null;
+ Node prev = null;
+
+ // move curr node link
+ while (curr != null) {
+ // move link
+ nextNode = curr.next;
+ curr.next = prev;
+
+ // move forward
+ prev = curr;
+ curr = nextNode;
+ }
+
+ head = prev;
+ }
+ }
+
+ /**
+ * 鍒犻櫎涓涓崟閾捐〃鐨勫墠鍗婇儴鍒 渚嬪锛歭ist = 2->5->7->8 , 鍒犻櫎浠ュ悗鐨勫间负 7->8 濡傛灉list = 2->5->7->8->10
+ * ,鍒犻櫎浠ュ悗鐨勫间负7,8,10
+ *
+ */
+ public void removeFirstHalf() {
+ if (head != null) {
+ int listSize = this.size();
+ int half = (int) Math.ceil(listSize / 2);
+
+ Node curr = head;
+ while (half > 0) {
+ curr = curr.next;
+ head = curr;
+ half--;
+ }
+ }
+ }
+
+ /**
+ * 浠庣i涓厓绱犲紑濮嬶紝 鍒犻櫎length 涓厓绱 锛 娉ㄦ剰i浠0寮濮
+ *
+ * @param i
+ * @param length
+ */
+ public void remove(int i, int length) {
+ if (head == null) {
+ return;
+ }
+
+ if (i < 0) {
+ return;
+ }
+
+ if (i > this.size() - 1) {
+ return;
+ }
+
+ Node curr = head;
+ Node prev = head;
+ // move to index i
+ while (i > 0 && curr != null) {
+ prev = curr;
+ curr = curr.next;
+ i--;
+ }
+
+ // if curr is out of bound return
+ if (curr == null) {
+ return;
+ }
+
+ // else move length
+ while (length > 0 && curr != null) {
+ curr = curr.next;
+ length--;
+ }
+
+ // special case to head
+ if (prev == head) {
+ head = curr;
+ } else {
+ prev.next = curr;
+ }
+ }
+
+ /**
+ * 鍋囧畾褰撳墠閾捐〃鍜宭ist鍧囧寘鍚凡鍗囧簭鎺掑垪鐨勬暣鏁 浠庡綋鍓嶉摼琛ㄤ腑鍙栧嚭閭d簺list鎵鎸囧畾鐨勫厓绱 渚嬪褰撳墠閾捐〃 =
+ * 11->101->201->301->401->501->601->701 listB = 1->3->4->6
+ * 杩斿洖鐨勭粨鏋滃簲璇ユ槸[101,301,401,601]
+ *
+ * @param list
+ */
+ public int[] getElements(LinkedList list) {
+ if (list.size() == 0) {
+ return null;
+ }
+
+ if (head == null) {
+ return null;
+ }
+
+ // TODO: remove list which not existed in the original list
+ // special case: 1->3->4->20
+
+ int[] newArr = new int[list.size()];
+ int i = 0;
+ Iterator it = list.iterator();
+ while (it.hasNext()) {
+ int id = (int) it.next();
+
+ // if element is not existed
+ if (this.get(id) != null) {
+ int listElement = (int) this.get(id);
+ newArr[i] = listElement;
+ i++;
+ }
+ }
+
+ return newArr;
+ }
+
+ /**
+ * 宸茬煡閾捐〃涓殑鍏冪礌浠ュ奸掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩 浠庡綋鍓嶉摼琛ㄤ腑涓垹闄ゅ湪list涓嚭鐜扮殑鍏冪礌
+ *
+ * @param list
+ */
+
+ public void subtract(LinkedList list) {
+ if (list.size() == 0) {
+ return;
+ }
+
+ if (head == null) {
+ return;
+ }
+
+ Iterator it = list.iterator();
+ while (it.hasNext()) {
+ int id = (int) it.next();
+ this.remove(id);
+ }
+ }
+
+ /**
+ * 宸茬煡褰撳墠閾捐〃涓殑鍏冪礌浠ュ奸掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩 鍒犻櫎琛ㄤ腑鎵鏈夊肩浉鍚岀殑澶氫綑鍏冪礌锛堜娇寰楁搷浣滃悗鐨勭嚎鎬ц〃涓墍鏈夊厓绱犵殑鍊煎潎涓嶇浉鍚岋級
+ */
+ public void removeDuplicateValues() {
+ if (head == null) {
+ return;
+ }
+
+ Node curr = head;
+
+ // note:
+ // duplicate value in the first or last
+ // all values the same
+ while (curr.next != null) {
+ if (curr.data.equals(curr.next.data)) {
+ curr.next = curr.next.next;
+ } else {
+ curr = curr.next;
+ }
+ }
+ }
+
+ /**
+ * 宸茬煡閾捐〃涓殑鍏冪礌浠ュ奸掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩 璇曞啓涓楂樻晥鐨勭畻娉曪紝鍒犻櫎琛ㄤ腑鎵鏈夊煎ぇ浜巑in涓斿皬浜巑ax鐨勫厓绱狅紙鑻ヨ〃涓瓨鍦ㄨ繖鏍风殑鍏冪礌锛
+ *
+ * @param min
+ * @param max
+ */
+ public void removeRange(int min, int max) {
+ if (head == null) {
+ return;
+ }
+
+ if (min > max) {
+ return;
+ }
+
+ // only works for integer
+ Node curr = head;
+ Node prev = head;
+ // include last node
+ while (curr != null) {
+ if ((int) curr.data > min && (int) curr.data < max) {
+ // special case for head
+ if (curr == head) {
+ head = curr.next;
+ } else {
+ prev.next = curr.next;
+ curr = curr.next;
+ }
+ } else {
+ prev = curr;
+ curr = curr.next;
+ }
+ }
+ }
+
+ /**
+ * 鍋囪褰撳墠閾捐〃鍜屽弬鏁發ist鎸囧畾鐨勯摼琛ㄥ潎浠ュ厓绱犱緷鍊奸掑鏈夊簭鎺掑垪锛堝悓涓琛ㄤ腑鐨勫厓绱犲煎悇涓嶇浉鍚岋級
+ * 鐜拌姹傜敓鎴愭柊閾捐〃C锛屽叾鍏冪礌涓哄綋鍓嶉摼琛ㄥ拰list涓厓绱犵殑浜ら泦锛屼笖琛–涓殑鍏冪礌鏈変緷鍊奸掑鏈夊簭鎺掑垪
+ *
+ * @param list
+ */
+ public LinkedList intersection(LinkedList list) {
+ if (list.size() == 0) {
+ return null;
+ }
+
+ if (head == null) {
+ return null;
+ }
+
+ // find size
+ int l1Size = this.size();
+ int l2Size = list.size();
+
+ // runner
+ int i = 0;
+ int j = 0;
+
+ LinkedList rtnList = new LinkedList();
+
+ while (i < l1Size && j < l2Size) {
+ if (this.get(i).equals(list.get(j))) {
+ rtnList.add(this.get(i));
+ i++;
+ j++;
+ } else if ((int) this.get(i) < (int) list.get(j)) {
+ i++;
+ } else {
+ j++;
+ }
+ }
+
+ return rtnList;
}
}
diff --git a/group11/395443277/src/com/coding/basic/LinkedListTest.java b/group11/395443277/src/com/coding/basic/LinkedListTest.java
index af5aa2d3a2..47418e188d 100644
--- a/group11/395443277/src/com/coding/basic/LinkedListTest.java
+++ b/group11/395443277/src/com/coding/basic/LinkedListTest.java
@@ -1,6 +1,7 @@
package com.coding.basic;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
import org.junit.Test;
@@ -124,4 +125,185 @@ public void testIterator() {
assertEquals(3, it.next());
assertEquals(2, it.next());
}
+
+ @Test
+ public void testReverse() {
+ LinkedList list = new LinkedList();
+ list.add(3);
+ list.add(7);
+ list.add(10);
+ list.add(15);
+
+ list.reverse();
+ assertEquals(15, list.get(0));
+
+ LinkedList list2 = new LinkedList();
+ list2.reverse();
+ }
+
+ @Test
+ public void testRemoveFirstHalf() {
+ LinkedList list = new LinkedList();
+ list.add(2);
+ list.add(5);
+ list.add(7);
+ list.add(8);
+ list.add(10);
+
+ list.removeFirstHalf();
+ }
+
+
+ @Test
+ public void testRemoveDuplicateValues() {
+ LinkedList list = new LinkedList();
+ list.add(1);
+
+ // with single element
+ assertEquals(1, list.get(0));
+
+ // add another one with 1->1
+ list.add(1);
+ list.removeDuplicateValues();
+ assertEquals(1, list.get(0));
+ assertEquals(1, list.size());
+
+ // test the duplicate value is the last one
+ for(int i=2; i<6; i++) {
+ list.add(i);
+ }
+ list.add(5);
+ list.removeDuplicateValues();
+ assertEquals(5, list.get(4));
+ assertEquals(5, list.size());
+
+ // regular
+ for(int i=0; i<6; i++) {
+ list.add(5);
+ }
+ list.add(6);
+
+ list.removeDuplicateValues();
+ assertEquals(6, list.get(5));
+ assertEquals(6, list.size());
+ }
+
+ @Test
+ public void testRemoveRange() {
+ LinkedList list = new LinkedList();
+
+ // regular
+ for(int i=1; i<7; i++) {
+ list.add(i);
+ }
+
+ list.removeRange(2, 4);
+ assertEquals(5, list.size());
+
+ // head case
+ list.add(1, 1);
+ list.removeRange(0, 3);
+ assertEquals(3, list.size());
+
+ // tail case
+ list.add(6);
+ list.add(7);
+ list.removeRange(5, 20);
+ assertEquals(2, list.size());
+ }
+
+ @Test
+ public void testRemoveLength() {
+ LinkedList list = new LinkedList();
+
+ // regular
+ for(int i=0; i<9; i++) {
+ list.add(i);
+ }
+
+ // regular
+ list.remove(4, 2);
+
+ // head
+ LinkedList list2 = new LinkedList();
+ for(int i=0; i<9; i++) {
+ list2.add(i);
+ }
+ list2.remove(0, 3);
+
+ // tail
+ LinkedList list3 = new LinkedList();
+ for(int i=0; i<10; i++) {
+ list3.add(i);
+ }
+ list3.remove(9, 3);
+ assertEquals(9, list3.size());
+ }
+
+ @Test
+ public void testGetElements() {
+ LinkedList list1 = new LinkedList();
+ // 11->101->201->301->401->501->601->701
+ list1.add(11);
+ list1.add(101);
+ list1.add(201);
+ list1.add(301);
+ list1.add(401);
+ list1.add(501);
+ list1.add(601);
+ list1.add(701);
+
+ LinkedList list2 = new LinkedList();
+ // 1->3->4->6
+ list2.add(1);
+ list2.add(3);
+ list2.add(4);
+ list2.add(6);
+
+ int[] newArr = list1.getElements(list2);
+ assertArrayEquals(new int[]{101,301,401,601}, newArr);
+ }
+
+ @Test
+ public void testSubtract() {
+ LinkedList list1 = new LinkedList();
+ // 11->101->201->301->401->501->601->701
+ list1.add(11);
+ list1.add(101);
+ list1.add(201);
+ list1.add(301);
+ list1.add(401);
+ list1.add(501);
+ list1.add(601);
+ list1.add(701);
+
+ LinkedList list2 = new LinkedList();
+ // 1->3->4->6
+ list2.add(1);
+ list2.add(3);
+ list2.add(4);
+ list2.add(6);
+
+ list1.subtract(list2);
+ // 11->201->501->701
+ assertEquals(4, list1.size());
+ }
+
+ @Test
+ public void testIntersection() {
+ LinkedList list1 = new LinkedList();
+ list1.add(1);
+ list1.add(2);
+ list1.add(4);
+ list1.add(5);
+
+ LinkedList list2 = new LinkedList();
+ list2.add(2);
+ list2.add(3);
+ list2.add(4);
+ list2.add(7);
+
+ LinkedList l3 = list1.intersection(list2);
+ assertEquals(2, l3.size());
+ }
}
From 032ee7251204241df8035e6a351b93b6924473d9 Mon Sep 17 00:00:00 2001
From: xiongrui
Date: Fri, 10 Mar 2017 12:22:41 +0800
Subject: [PATCH 020/155] add Stack notes and complete TestArrayList
---
group22/627559964/.classpath | 1 +
.../src/com/coding/basic/ArrayList.java | 11 +---
.../627559964/src/com/coding/basic/Queue.java | 2 +
.../627559964/src/com/coding/basic/Stack.java | 29 ++++++++-
group22/627559964/src/demo/Demo.java | 3 +
.../test/com/coding/basic/TestArrayList.java | 59 +++++++++++++++++++
6 files changed, 94 insertions(+), 11 deletions(-)
create mode 100644 group22/627559964/test/com/coding/basic/TestArrayList.java
diff --git a/group22/627559964/.classpath b/group22/627559964/.classpath
index 83b76b7922..e72ef7c0d4 100644
--- a/group22/627559964/.classpath
+++ b/group22/627559964/.classpath
@@ -3,5 +3,6 @@
+
diff --git a/group22/627559964/src/com/coding/basic/ArrayList.java b/group22/627559964/src/com/coding/basic/ArrayList.java
index e20bd4ca45..59d055dfa7 100644
--- a/group22/627559964/src/com/coding/basic/ArrayList.java
+++ b/group22/627559964/src/com/coding/basic/ArrayList.java
@@ -160,15 +160,6 @@ public Object next() {
@Override
public String toString() {
- StringBuffer list = new StringBuffer();
- list.append("[");
- for (int i = 0; i < elementData.length; i++) {
- list.append(elementData);
- if (i != elementData.length - 1) {
- list.append(",");
- }
- }
- list.append("]");
- return list.toString();
+ return Arrays.toString(Arrays.copyOf(elementData, size));
}
}
\ No newline at end of file
diff --git a/group22/627559964/src/com/coding/basic/Queue.java b/group22/627559964/src/com/coding/basic/Queue.java
index a487336ffe..0cc28034fe 100644
--- a/group22/627559964/src/com/coding/basic/Queue.java
+++ b/group22/627559964/src/com/coding/basic/Queue.java
@@ -1,6 +1,8 @@
package com.coding.basic;
public class Queue {
+
+ private Object[] queue;
public void enQueue(Object o) {
}
diff --git a/group22/627559964/src/com/coding/basic/Stack.java b/group22/627559964/src/com/coding/basic/Stack.java
index 0d93aabb47..84e90bfb75 100644
--- a/group22/627559964/src/com/coding/basic/Stack.java
+++ b/group22/627559964/src/com/coding/basic/Stack.java
@@ -1,23 +1,46 @@
package com.coding.basic;
+/**
+ * 自定义stack
+ *
+ * @author xiongrui233
+ *
+ */
public class Stack {
+ //元素集合
private ArrayList elementData = new ArrayList();
+ /**
+ * 向栈顶压入元素
+ * @param o
+ */
public void push(Object o) {
- elementData.add(o);
+ elementData.add(0,o);
}
+ /**
+ * 获得栈顶元素,并移除栈里该元素
+ * @return obj
+ */
public Object pop() {
Object obj = elementData.get(0);
elementData.remove(0);
return obj;
}
+ /**
+ * 获得栈顶元素,不移除栈里该元素
+ * @return obj
+ */
public Object peek() {
return elementData.get(0);
}
+ /**
+ * 判断该栈是否为空
+ * @return true/false
+ */
public boolean isEmpty() {
if (elementData.size() != 0) {
return false;
@@ -25,6 +48,10 @@ public boolean isEmpty() {
return true;
}
+ /**
+ * 获得栈的大小
+ * @return size
+ */
public int size() {
return elementData.size();
}
diff --git a/group22/627559964/src/demo/Demo.java b/group22/627559964/src/demo/Demo.java
index de5ec1a19c..156d8ec61a 100644
--- a/group22/627559964/src/demo/Demo.java
+++ b/group22/627559964/src/demo/Demo.java
@@ -1,5 +1,7 @@
package demo;
+import java.util.PriorityQueue;
+
import com.coding.basic.ArrayList;
import com.coding.basic.Iterator;
import com.coding.basic.List;
@@ -14,6 +16,7 @@ public static void main(String[] args) {
list.add(3, new Integer(233));
list.add(3, new Double(233.33));
list.remove(6);
+ System.out.println("List:" + list);
Double kk = (Double) list.get(3);
Iterator it = list.iterator();
while (it.hasNext()) {
diff --git a/group22/627559964/test/com/coding/basic/TestArrayList.java b/group22/627559964/test/com/coding/basic/TestArrayList.java
new file mode 100644
index 0000000000..68dabbb042
--- /dev/null
+++ b/group22/627559964/test/com/coding/basic/TestArrayList.java
@@ -0,0 +1,59 @@
+package com.coding.basic;
+
+import java.util.Arrays;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestArrayList {
+
+ private List list = null;
+
+ @Before
+ public void init() {
+ list = new ArrayList();
+
+ list.add(0);
+ list.add(1);
+ list.add(3);
+ }
+
+ @Test
+ public void addTest () {
+ list.add(2,2);
+// System.out.println(list.toString());
+ Assert.assertEquals("[0, 1, 2, 3]", list.toString());
+ }
+
+ @Test
+ public void getTest () {
+ Assert.assertEquals(3, list.get(2));
+ }
+
+ @Test
+ public void removeTest () {
+ list.remove(0);
+// System.out.println(list.toString());
+ Assert.assertEquals("[1, 3]", list.toString());
+ }
+
+ @Test
+ public void sizeTest () {
+ Assert.assertEquals(3, list.size());
+ }
+
+ @Test
+ public void iteratorTest () {
+ Object[] obj = new Object[list.size()];
+ Iterator it = list.iterator();
+ int i = 0;
+ while (it.hasNext()) {
+ obj[i] = it.next();
+ i ++;
+ }
+// System.out.println(Arrays.toString(obj));
+ Assert.assertEquals(Arrays.toString(obj), list.toString());
+ }
+
+}
From c05ed934d5749224aa15c0f060be4063f28e64da Mon Sep 17 00:00:00 2001
From: xiongrui
Date: Fri, 10 Mar 2017 13:37:19 +0800
Subject: [PATCH 021/155] simple complete BinaryTreeNode
---
.../src/com/coding/basic/BinaryTreeNode.java | 30 +++++++++++++++-
group22/627559964/src/demo/Demo.java | 34 ++++++++++++-------
2 files changed, 50 insertions(+), 14 deletions(-)
diff --git a/group22/627559964/src/com/coding/basic/BinaryTreeNode.java b/group22/627559964/src/com/coding/basic/BinaryTreeNode.java
index 981812cf59..9c416d3ad3 100644
--- a/group22/627559964/src/com/coding/basic/BinaryTreeNode.java
+++ b/group22/627559964/src/com/coding/basic/BinaryTreeNode.java
@@ -1,9 +1,18 @@
package com.coding.basic;
+/**
+ * 自定义二叉树
+ *
+ * @author xiongrui233
+ *
+ */
public class BinaryTreeNode {
+ //节点值
private Object data;
+ //左子树
private BinaryTreeNode left;
+ //右子树
private BinaryTreeNode right;
public Object getData() {
@@ -30,8 +39,27 @@ public void setRight(BinaryTreeNode right) {
this.right = right;
}
+ /**
+ * 插入元素
+ * @param o
+ * @return BinaryTreeNode
+ */
public BinaryTreeNode insert(Object o) {
- return null;
+ BinaryTreeNode node = null;
+ if (this.data == null) {
+ this.data = o;
+ node = this;
+ } else {
+ if (this.left.data == null) {
+ this.left.data = o;
+ node = this.left;
+ }
+ if (this.right.data == null) {
+ this.right.data = o;
+ node = this.right;
+ }
+ }
+ return node;
}
}
\ No newline at end of file
diff --git a/group22/627559964/src/demo/Demo.java b/group22/627559964/src/demo/Demo.java
index 156d8ec61a..10e4fbe402 100644
--- a/group22/627559964/src/demo/Demo.java
+++ b/group22/627559964/src/demo/Demo.java
@@ -4,24 +4,32 @@
import com.coding.basic.ArrayList;
import com.coding.basic.Iterator;
+import com.coding.basic.LinkedList;
import com.coding.basic.List;
public class Demo {
public static void main(String[] args) {
- List list = new ArrayList();
- for (int i = 0; i < 12; i++) {
- list.add(new Integer(123));
- }
- list.add(3, new Integer(233));
- list.add(3, new Double(233.33));
- list.remove(6);
- System.out.println("List:" + list);
- Double kk = (Double) list.get(3);
- Iterator it = list.iterator();
- while (it.hasNext()) {
- System.out.println(it.next());
- }
+// List list = new ArrayList();
+// for (int i = 0; i < 12; i++) {
+// list.add(new Integer(123));
+// }
+// list.add(3, new Integer(233));
+// list.add(3, new Double(233.33));
+// list.remove(6);
+// System.out.println("List:" + list);
+// Double kk = (Double) list.get(3);
+// Iterator it = list.iterator();
+// while (it.hasNext()) {
+// System.out.println(it.next());
+// }
+
+ List list = new LinkedList();
+ list.add(1);
+ list.add(2);
+ list.add(3);
+// list.add(0, 0);
+
System.out.println("End");
}
}
From 0c73e93c22f217a253f42e509fe57d8bffad6b2a Mon Sep 17 00:00:00 2001
From: xiongrui
Date: Fri, 10 Mar 2017 13:38:20 +0800
Subject: [PATCH 022/155] doing LinkedList
---
.../src/com/coding/basic/LinkedList.java | 95 ++++++++++++++++---
1 file changed, 82 insertions(+), 13 deletions(-)
diff --git a/group22/627559964/src/com/coding/basic/LinkedList.java b/group22/627559964/src/com/coding/basic/LinkedList.java
index 8aa70d53bd..0296f1019b 100644
--- a/group22/627559964/src/com/coding/basic/LinkedList.java
+++ b/group22/627559964/src/com/coding/basic/LinkedList.java
@@ -1,27 +1,102 @@
package com.coding.basic;
+/**
+ * 自定义LinkList
+ *
+ * @author xiongrui233
+ *
+ */
public class LinkedList implements List {
+
+ /**
+ * 定义链表节点结构
+ * @author xiongrui233
+ *
+ */
+ private static class Node {
+ Object data;
+ Node next;
+ }
+ //链表节点
+ private Node head = new Node();
- private Node head;
-
+ /**
+ * 添加元素
+ *
+ * @param o
+ */
public void add(Object o) {
-
+ Node node = head;
+ while (node.data != null) {
+ node = node.next;
+ }
+ node.data = o;
}
+ /**
+ * 添加元素
+ *
+ * @param index
+ * @param o
+ */
public void add(int index, Object o) {
-
+ Node node = head;
+ Node oldNode = head;
+ Node newNode = new Node();
+ for (int i = 0; i <= index; i++) {
+ if (i == index - 1) {
+ oldNode = node.next;
+ }
+ node = node.next;
+ }
+ newNode.data = o;
+ newNode.next = node;
+ oldNode.next = newNode;
}
+ /**
+ * 获取元素
+ *
+ * @param index
+ */
public Object get(int index) {
- return null;
+ Node node = head;
+ for (int i = 0; i <= index; i++) {
+ node = node.next;
+ }
+ return node.data;
}
+ /**
+ * 删除元素
+ *
+ * @param index
+ */
public Object remove(int index) {
- return null;
+ Node node = head;
+ Node oldNode = head;
+ Node newNode = new Node();
+ for (int i = 0; i <= index; i++) {
+ if (i == index - 1) {
+ oldNode = node.next;
+ }
+ node = node.next;
+ }
+ if (node.next != null) {
+ newNode = node.next;
+ } else {
+ newNode = node;
+ }
+ oldNode.next = newNode;
+ return node.data;
}
public int size() {
- return -1;
+ int size = 0;
+ while (head.next != null) {
+ size ++;
+ }
+ return size;
}
public void addFirst(Object o) {
@@ -44,12 +119,6 @@ public Iterator iterator() {
return null;
}
- private static class Node {
- Object data;
- Node next;
-
- }
-
/**
* 把该链表逆置 例如链表为 3->7->10 , 逆置后变为 10->7->3
*/
From d9c4b4e47e300a8e6beea48060f290156434c814 Mon Sep 17 00:00:00 2001
From: xiongrui
Date: Fri, 10 Mar 2017 17:31:30 +0800
Subject: [PATCH 023/155] =?UTF-8?q?simple=20complete=20LinkedList=EF=BC=8C?=
=?UTF-8?q?last=20TODO=20intersection()?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/com/coding/basic/LinkedList.java | 218 ++++++++++++++----
.../627559964/src/com/coding/basic/Queue.java | 11 +-
group22/627559964/src/demo/Demo.java | 55 ++++-
3 files changed, 235 insertions(+), 49 deletions(-)
diff --git a/group22/627559964/src/com/coding/basic/LinkedList.java b/group22/627559964/src/com/coding/basic/LinkedList.java
index 0296f1019b..dcae1fb835 100644
--- a/group22/627559964/src/com/coding/basic/LinkedList.java
+++ b/group22/627559964/src/com/coding/basic/LinkedList.java
@@ -7,9 +7,10 @@
*
*/
public class LinkedList implements List {
-
+
/**
* 定义链表节点结构
+ *
* @author xiongrui233
*
*/
@@ -17,20 +18,23 @@ private static class Node {
Object data;
Node next;
}
- //链表节点
+
+ // 链表节点
private Node head = new Node();
+ private int size = 0;
+
+ public LinkedList() {
+ head.next = head;
+ }
+
/**
* 添加元素
*
* @param o
*/
public void add(Object o) {
- Node node = head;
- while (node.data != null) {
- node = node.next;
- }
- node.data = o;
+ addLast(o);
}
/**
@@ -40,18 +44,23 @@ public void add(Object o) {
* @param o
*/
public void add(int index, Object o) {
+ if (index < 0 || index > size) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
Node node = head;
- Node oldNode = head;
- Node newNode = new Node();
- for (int i = 0; i <= index; i++) {
- if (i == index - 1) {
- oldNode = node.next;
- }
+ Node temp = new Node();
+ for (int i = 0; i < index; i++) {
node = node.next;
}
- newNode.data = o;
- newNode.next = node;
- oldNode.next = newNode;
+ temp.data = o;
+ if (index == size -1) {
+ node.next = temp;
+ temp.next = head;
+ } else {
+ temp.next = node.next;
+ node.next = temp;
+ }
+ size ++;
}
/**
@@ -73,57 +82,117 @@ public Object get(int index) {
* @param index
*/
public Object remove(int index) {
+ if (index < 0 || index > size) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
Node node = head;
- Node oldNode = head;
- Node newNode = new Node();
- for (int i = 0; i <= index; i++) {
- if (i == index - 1) {
- oldNode = node.next;
- }
+ Node temp = new Node();
+ for (int i = 0; i <= index - 1; i++) {
node = node.next;
}
- if (node.next != null) {
- newNode = node.next;
+ if (index == size -1) {
+ temp = node.next;
+ node.next = head;
} else {
- newNode = node;
+ temp = node.next;
+ node.next = node.next.next;
}
- oldNode.next = newNode;
- return node.data;
+ size --;
+ return temp.data;
}
+ /**
+ * 返回LinkedList的大小
+ *
+ * @return size
+ */
public int size() {
- int size = 0;
- while (head.next != null) {
- size ++;
- }
return size;
}
+ /**
+ * 在LinkedList第一的位置添加元素
+ *
+ * @param o
+ */
public void addFirst(Object o) {
-
+ add(0, o);
}
+ /**
+ * 在LinkedList最后添加元素
+ * @param o
+ */
public void addLast(Object o) {
-
+ Node node = head;
+ Node temp = new Node();
+ for (int i = 0; i < size; i++) {
+ node = node.next;
+ }
+ temp.data = o;
+ node.next = temp;
+ size ++;
}
+ /**
+ * 移除链表第一位元素
+ *
+ * @return obj
+ */
public Object removeFirst() {
- return null;
+ return remove(0);
}
+ /**
+ * 移除链表最后一位元素
+ *
+ * @return obj
+ */
public Object removeLast() {
- return null;
+ return remove(size - 1);
}
+ /**
+ * 实现Iterator接口
+ *
+ * @return Iterator
+ */
public Iterator iterator() {
- return null;
+
+ class IteratorImpl implements Iterator {
+
+ private Node node = head.next;
+
+ private Object temp = null;
+
+ @Override
+ public boolean hasNext() {
+ if (node != null && node.data != null) {
+ temp = node.data;
+ node = node.next;
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public Object next() {
+ return temp;
+ }
+
+ }
+ return new IteratorImpl();
}
/**
* 把该链表逆置 例如链表为 3->7->10 , 逆置后变为 10->7->3
*/
- public void reverse() {
-
+ public LinkedList reverse() {
+ LinkedList lis = new LinkedList();
+ for (int i = this.size - 1; i >= 0; i--) {
+ lis.add(this.get(i));
+ }
+ return lis;
}
/**
@@ -131,7 +200,10 @@ public void reverse() {
* ,删除以后的值为7,8,10
*/
public void removeFirstHalf() {
-
+ int mid = size/2;
+ for (int i = 0; i < mid; i++) {
+ remove(0);
+ }
}
/**
@@ -141,7 +213,15 @@ public void removeFirstHalf() {
* @param length
*/
public void remove(int i, int length) {
-
+ if (i > length) {
+ throw new IllegalArgumentException();
+ }
+ if (i < 0 || i > size) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+ for (int j = i; j <= length; j++) {
+ remove(i);
+ }
}
/**
@@ -151,8 +231,15 @@ public void remove(int i, int length) {
*
* @param list
*/
- public static int[] getElements(LinkedList list) {
- return null;
+ public int[] getElements(LinkedList list) {
+ if (this.size < (Integer)list.get(list.size - 1)) {
+ throw new IllegalArgumentException();
+ }
+ int[] elements = new int[list.size];
+ for (int i = 0; i < elements.length; i++) {
+ elements[i] = (Integer) this.get((Integer)list.get(i));
+ }
+ return elements;
}
/**
@@ -162,14 +249,30 @@ public static int[] getElements(LinkedList list) {
*/
public void subtract(LinkedList list) {
-
+ Iterator it = list.iterator();
+ while (it.hasNext()) {
+ Object obj = it.next();
+ for (int i = 0; i < this.size; i++) {
+ if (obj.equals(this.get(i))) {
+ this.remove(i);
+ }
+ }
+ }
}
/**
* 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同)
*/
public void removeDuplicateValues() {
-
+ for (int i = 0; i < this.size; i++) {
+ if (i + 1 >= this.size) {
+ return;
+ }
+ if (this.get(i).equals(this.get(i+1))) {
+ remove(i+1);
+ i--;
+ }
+ }
}
/**
@@ -179,16 +282,39 @@ public void removeDuplicateValues() {
* @param max
*/
public void removeRange(int min, int max) {
-
+ if (min >= max) {
+ throw new IllegalArgumentException();
+ }
+ for (int i = 0; i < this.size; i++) {
+ if ((Integer)this.get(i) > max) {
+ remove(i, this.size-1);
+ }
+ }
}
/**
* 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同)
* 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列
- *
+ * TODO
* @param list
*/
public LinkedList intersection(LinkedList list) {
return null;
}
+
+ @Override
+ public String toString() {
+ StringBuffer list = new StringBuffer();
+ list.append("List:[");
+ Node node = head.next;
+ for (int i = 0; i < size; i++) {
+ list.append(node.data);
+ node = node.next;
+ if (i != size -1) {
+ list.append(", ");
+ }
+ }
+ list.append("]");
+ return list.toString();
+ }
}
\ No newline at end of file
diff --git a/group22/627559964/src/com/coding/basic/Queue.java b/group22/627559964/src/com/coding/basic/Queue.java
index 0cc28034fe..90f845e6cd 100644
--- a/group22/627559964/src/com/coding/basic/Queue.java
+++ b/group22/627559964/src/com/coding/basic/Queue.java
@@ -1,10 +1,19 @@
package com.coding.basic;
+/**
+ * 自定义队列
+ *
+ * @author xiongrui233
+ *
+ */
public class Queue {
+
+ private Object[] queue = new Object[10];
- private Object[] queue;
+ private int size = 0;
public void enQueue(Object o) {
+
}
public Object deQueue() {
diff --git a/group22/627559964/src/demo/Demo.java b/group22/627559964/src/demo/Demo.java
index 10e4fbe402..4fbb5c6b40 100644
--- a/group22/627559964/src/demo/Demo.java
+++ b/group22/627559964/src/demo/Demo.java
@@ -1,5 +1,6 @@
package demo;
+import java.util.Arrays;
import java.util.PriorityQueue;
import com.coding.basic.ArrayList;
@@ -24,12 +25,62 @@ public static void main(String[] args) {
// System.out.println(it.next());
// }
- List list = new LinkedList();
+ LinkedList list = new LinkedList();
list.add(1);
list.add(2);
list.add(3);
-// list.add(0, 0);
+ list.add(5);
+ list.add(0, 0);
+ list.add(2, 4);
+
+ System.out.println(list);
+
+ System.out.println(list.size());
+
+ System.out.println(list.get(4));
+
+ System.out.println(list.remove(4));
+
+ System.out.println(list);
+
+ System.out.println(list.reverse());
+
+ Iterator it = list.iterator();
+ while (it.hasNext()) {
+ System.out.print(it.next() + " ");
+ }
+ System.out.println();
+
+ list.removeFirstHalf();
+ System.out.println(list);
+
+ list.remove(0, 1);
+ System.out.println(list);
+
+ LinkedList ls = new LinkedList();
+ list.add(6);
+ list.add(7);
+ list.add(8);
+ ls.add(1);
+ ls.add(2);
+ System.out.println(list);
+ System.out.println(ls);
+ System.out.println(Arrays.toString(list.getElements(ls)));
+
+ ls.add(6);
+ list.subtract(ls);
+ System.out.println(list);
+
+ list.add(1, 6);
+// list.add(1, 6);
+ System.out.println(list);
+// list.removeDuplicateValues();
+// System.out.println(list);
System.out.println("End");
+
+ list.removeRange(4, 7);
+ System.out.println(list);
+
}
}
From 170ad340bc4866dda0f7649bda50764345c1861f Mon Sep 17 00:00:00 2001
From: cjl1407 <115847486@qq.com>
Date: Fri, 10 Mar 2017 18:37:33 +0800
Subject: [PATCH 024/155] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E4=BD=9C?=
=?UTF-8?q?=E4=B8=9A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/TestCollection/ArrayList.java | 42 ++++
.../src/TestCollection/LinkedList.java | 184 ++++++++++++++++++
.../1158477486/src/TestCollection/Queue.java | 38 ++++
.../1158477486/src/TestCollection/Stack.java | 36 ++++
4 files changed, 300 insertions(+)
create mode 100644 group22/1158477486/src/TestCollection/ArrayList.java
create mode 100644 group22/1158477486/src/TestCollection/LinkedList.java
create mode 100644 group22/1158477486/src/TestCollection/Queue.java
create mode 100644 group22/1158477486/src/TestCollection/Stack.java
diff --git a/group22/1158477486/src/TestCollection/ArrayList.java b/group22/1158477486/src/TestCollection/ArrayList.java
new file mode 100644
index 0000000000..b097267d50
--- /dev/null
+++ b/group22/1158477486/src/TestCollection/ArrayList.java
@@ -0,0 +1,42 @@
+package TestCollection;
+
+public class ArrayList implements List {
+
+
+
+ private Object[] elementData = new Object[100];
+ private int size ;
+ public void add(Object o){
+ if(size==elementData.length){
+ Object[]newData=new Object[size*2+1];//将数组扩容
+ System.arraycopy(elementData, 0, newData, 0, elementData.length);
+ elementData=newData;
+ }
+ elementData[size++]=o;
+
+ }
+ public void add(int index, Object o){
+ System.arraycopy(elementData, index, elementData,index+1 , size-index);
+ elementData[index]=o;
+ size++;
+ }
+
+ public Object get(int index){
+ return elementData[index];
+ }
+
+ public Object remove(int index){
+ System.arraycopy(elementData, index+1, elementData, index, size-index-1);
+ elementData[--size]=null;
+ return null;
+ }
+
+ public int size(){
+ return size;
+ }
+
+ public Iterator iterator(){
+ return null;
+ }
+
+}
diff --git a/group22/1158477486/src/TestCollection/LinkedList.java b/group22/1158477486/src/TestCollection/LinkedList.java
new file mode 100644
index 0000000000..6e1feda532
--- /dev/null
+++ b/group22/1158477486/src/TestCollection/LinkedList.java
@@ -0,0 +1,184 @@
+package TestCollection;
+
+
+
+public class LinkedList implements List {
+
+ private Node head=new Node();;
+ private int size;
+ public Node node(int a){//鍒涘缓寰楀埌a浣嶇疆鑺傜偣鐨勬柟娉
+ Node teamp=null;
+
+ if(head!=null){
+ if(a<=size ){
+ teamp=head;
+ for(int i=0;i7->10 , 閫嗙疆鍚庡彉涓 10->7->3
+ */
+ public void reverse(){
+
+ }
+
+ /**
+ * 鍒犻櫎涓涓崟閾捐〃鐨勫墠鍗婇儴鍒
+ * 渚嬪锛歭ist = 2->5->7->8 , 鍒犻櫎浠ュ悗鐨勫间负 7->8
+ * 濡傛灉list = 2->5->7->8->10 ,鍒犻櫎浠ュ悗鐨勫间负7,8,10
+
+ */
+ public void removeFirstHalf(){
+
+ }
+
+ /**
+ * 浠庣i涓厓绱犲紑濮嬶紝 鍒犻櫎length 涓厓绱 锛 娉ㄦ剰i浠0寮濮
+ * @param i
+ * @param length
+ */
+ public void remove(int i, int length){
+
+ }
+ /**
+ * 鍋囧畾褰撳墠閾捐〃鍜宭ist鍧囧寘鍚凡鍗囧簭鎺掑垪鐨勬暣鏁
+ * 浠庡綋鍓嶉摼琛ㄤ腑鍙栧嚭閭d簺list鎵鎸囧畾鐨勫厓绱
+ * 渚嬪褰撳墠閾捐〃 = 11->101->201->301->401->501->601->701
+ * listB = 1->3->4->6
+ * 杩斿洖鐨勭粨鏋滃簲璇ユ槸[101,301,401,601]
+ * @param list
+ */
+ public static int[] getElements(LinkedList list){
+ return null;
+ }
+
+ /**
+ * 宸茬煡閾捐〃涓殑鍏冪礌浠ュ奸掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩
+ * 浠庡綋鍓嶉摼琛ㄤ腑涓垹闄ゅ湪list涓嚭鐜扮殑鍏冪礌
+
+ * @param list
+ */
+
+ public void subtract(LinkedList list){
+
+ }
+
+ /**
+ * 宸茬煡褰撳墠閾捐〃涓殑鍏冪礌浠ュ奸掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩
+ * 鍒犻櫎琛ㄤ腑鎵鏈夊肩浉鍚岀殑澶氫綑鍏冪礌锛堜娇寰楁搷浣滃悗鐨勭嚎鎬ц〃涓墍鏈夊厓绱犵殑鍊煎潎涓嶇浉鍚岋級
+ */
+ public void removeDuplicateValues(){
+
+ }
+
+ /**
+ * 宸茬煡閾捐〃涓殑鍏冪礌浠ュ奸掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩
+ * 璇曞啓涓楂樻晥鐨勭畻娉曪紝鍒犻櫎琛ㄤ腑鎵鏈夊煎ぇ浜巑in涓斿皬浜巑ax鐨勫厓绱狅紙鑻ヨ〃涓瓨鍦ㄨ繖鏍风殑鍏冪礌锛
+ * @param min
+ * @param max
+ */
+ public void removeRange(int min, int max){
+
+ }
+
+ /**
+ * 鍋囪褰撳墠閾捐〃鍜屽弬鏁發ist鎸囧畾鐨勯摼琛ㄥ潎浠ュ厓绱犱緷鍊奸掑鏈夊簭鎺掑垪锛堝悓涓琛ㄤ腑鐨勫厓绱犲煎悇涓嶇浉鍚岋級
+ * 鐜拌姹傜敓鎴愭柊閾捐〃C锛屽叾鍏冪礌涓哄綋鍓嶉摼琛ㄥ拰list涓厓绱犵殑浜ら泦锛屼笖琛–涓殑鍏冪礌鏈変緷鍊奸掑鏈夊簭鎺掑垪
+ * @param list
+ */
+ public LinkedList intersection( LinkedList list){
+ return null;
+ }
+}
+
+
\ No newline at end of file
diff --git a/group22/1158477486/src/TestCollection/Queue.java b/group22/1158477486/src/TestCollection/Queue.java
new file mode 100644
index 0000000000..4699235e98
--- /dev/null
+++ b/group22/1158477486/src/TestCollection/Queue.java
@@ -0,0 +1,38 @@
+package TestCollection;
+
+ ;
+
+public class Queue {
+ private LinkedList list=new LinkedList();
+
+ public void enQueue(Object o){
+ list.addLast ( o) ;//问题用add(index, o)出错
+ }
+
+ public Object deQueue(){
+ Object o=list.get(1);
+ list.remove(1);
+ return o;
+ }
+
+ public boolean isEmpty(){
+ if(list.size()!=0){
+ return false;}else
+ return true;
+ }
+
+ public int size(){
+ return list.size();
+ }
+ public static void main(String[] args) {
+ Queue q=new Queue();
+ q.enQueue("1");
+ q.enQueue("2");
+ q.enQueue("3");
+ System.out.println(q.size());
+ Object o=q.deQueue();
+ System.out.println(o);
+ System.out.println(q.size());
+
+ }
+}
diff --git a/group22/1158477486/src/TestCollection/Stack.java b/group22/1158477486/src/TestCollection/Stack.java
new file mode 100644
index 0000000000..35fdc6f31b
--- /dev/null
+++ b/group22/1158477486/src/TestCollection/Stack.java
@@ -0,0 +1,36 @@
+package TestCollection;
+
+public class Stack {
+ private ArrayList elementData = new ArrayList();
+
+ public void push(Object o){
+ elementData.add(o);
+ }
+
+ public Object pop(){
+ return elementData.get(elementData.size()-1) ;
+ }
+
+ public Object peek(){
+ elementData.remove(elementData.size()-1);
+ return elementData.get(elementData.size()-1);
+ }
+ public boolean isEmpty(){
+ if(elementData.size()!=0){
+ return false;}
+ return true;
+ }
+ public int size(){
+ return elementData.size();
+ }
+ public static void main(String[] args) {
+ Stack s=new Stack();
+ s.push("111");
+ s.push("211");
+ s.push("311");
+ System.out.println(s.size());//3
+ System.out.println(s.pop());
+ System.out.println(s.size());
+ System.out.println(s.peek());
+ System.out.println(s.size());
+ }}
From f0284b7cde7b9eea489136e82776cf7f3776f5ca Mon Sep 17 00:00:00 2001
From: cjl1407 <2832829901@qq.com>
Date: Fri, 10 Mar 2017 18:42:13 +0800
Subject: [PATCH 025/155] Delete Test.java
---
group22/1158477486/src/Test.java | 9 ---------
1 file changed, 9 deletions(-)
delete mode 100644 group22/1158477486/src/Test.java
diff --git a/group22/1158477486/src/Test.java b/group22/1158477486/src/Test.java
deleted file mode 100644
index f106f0d3df..0000000000
--- a/group22/1158477486/src/Test.java
+++ /dev/null
@@ -1,9 +0,0 @@
-
-public class Test {
-
- public static void main(String[] args) {
- // TODO Auto-generated method stub
-System.out.println("测试中------------");
- }
-
-}
From a2a3d252f1dbb1b17420f50a20d181162129a364 Mon Sep 17 00:00:00 2001
From: cjl1407 <2832829901@qq.com>
Date: Fri, 10 Mar 2017 18:42:33 +0800
Subject: [PATCH 026/155] Delete my.txt
---
group22/1158477486/src/my.txt | 1 -
1 file changed, 1 deletion(-)
delete mode 100644 group22/1158477486/src/my.txt
diff --git a/group22/1158477486/src/my.txt b/group22/1158477486/src/my.txt
deleted file mode 100644
index 605f61fe72..0000000000
--- a/group22/1158477486/src/my.txt
+++ /dev/null
@@ -1 +0,0 @@
-这是我的一个Git
\ No newline at end of file
From 1203ca2ef020d297e5cf221c911fb8dcb7ce5f4f Mon Sep 17 00:00:00 2001
From: cjl1407 <2832829901@qq.com>
Date: Fri, 10 Mar 2017 18:42:49 +0800
Subject: [PATCH 027/155] Delete myFist.java
---
group22/1158477486/src/myFist.java | 6 ------
1 file changed, 6 deletions(-)
delete mode 100644 group22/1158477486/src/myFist.java
diff --git a/group22/1158477486/src/myFist.java b/group22/1158477486/src/myFist.java
deleted file mode 100644
index 136079fbac..0000000000
--- a/group22/1158477486/src/myFist.java
+++ /dev/null
@@ -1,6 +0,0 @@
-
-public class myFist {
-public static void main(String[] args) {
- System.out.println("hello my love");
-}
-}
From ac67112337be177b648af74242d19aad27e2c566 Mon Sep 17 00:00:00 2001
From: PengyuanWei
Date: Sat, 11 Mar 2017 15:57:53 +0800
Subject: [PATCH 028/155] =?UTF-8?q?week01=20-=20=E6=95=B0=E6=8D=AE?=
=?UTF-8?q?=E7=BB=93=E6=9E=84=E4=BD=9C=E4=B8=9A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../910725683/RemoteSystemsTempFiles/.project | 12 +
group22/910725683/week01/.classpath | 8 +
group22/910725683/week01/.gitignore | 4 +
group22/910725683/week01/.project | 17 +
.../src/com/coding/basic/ArrayList.java | 98 ++++++
.../src/com/coding/basic/BinaryTreeNode.java | 110 ++++++
.../week01/src/com/coding/basic/Iterator.java | 7 +
.../src/com/coding/basic/LinkedList.java | 327 ++++++++++++++++++
.../week01/src/com/coding/basic/List.java | 10 +
.../week01/src/com/coding/basic/Queue.java | 26 ++
.../week01/src/com/coding/basic/Stack.java | 27 ++
.../test/com/coding/basic/ArrayListTest.java | 53 +++
.../com/coding/basic/BinaryTreeNodeTest.java | 47 +++
.../test/com/coding/basic/LinkedListTest.java | 137 ++++++++
.../test/com/coding/basic/QueueTest.java | 40 +++
.../test/com/coding/basic/StackTest.java | 48 +++
16 files changed, 971 insertions(+)
create mode 100644 group22/910725683/RemoteSystemsTempFiles/.project
create mode 100644 group22/910725683/week01/.classpath
create mode 100644 group22/910725683/week01/.gitignore
create mode 100644 group22/910725683/week01/.project
create mode 100644 group22/910725683/week01/src/com/coding/basic/ArrayList.java
create mode 100644 group22/910725683/week01/src/com/coding/basic/BinaryTreeNode.java
create mode 100644 group22/910725683/week01/src/com/coding/basic/Iterator.java
create mode 100644 group22/910725683/week01/src/com/coding/basic/LinkedList.java
create mode 100644 group22/910725683/week01/src/com/coding/basic/List.java
create mode 100644 group22/910725683/week01/src/com/coding/basic/Queue.java
create mode 100644 group22/910725683/week01/src/com/coding/basic/Stack.java
create mode 100644 group22/910725683/week01/test/com/coding/basic/ArrayListTest.java
create mode 100644 group22/910725683/week01/test/com/coding/basic/BinaryTreeNodeTest.java
create mode 100644 group22/910725683/week01/test/com/coding/basic/LinkedListTest.java
create mode 100644 group22/910725683/week01/test/com/coding/basic/QueueTest.java
create mode 100644 group22/910725683/week01/test/com/coding/basic/StackTest.java
diff --git a/group22/910725683/RemoteSystemsTempFiles/.project b/group22/910725683/RemoteSystemsTempFiles/.project
new file mode 100644
index 0000000000..5447a64fa9
--- /dev/null
+++ b/group22/910725683/RemoteSystemsTempFiles/.project
@@ -0,0 +1,12 @@
+
+
+ RemoteSystemsTempFiles
+
+
+
+
+
+
+ org.eclipse.rse.ui.remoteSystemsTempNature
+
+
diff --git a/group22/910725683/week01/.classpath b/group22/910725683/week01/.classpath
new file mode 100644
index 0000000000..1b83178c00
--- /dev/null
+++ b/group22/910725683/week01/.classpath
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/group22/910725683/week01/.gitignore b/group22/910725683/week01/.gitignore
new file mode 100644
index 0000000000..6a59c3a991
--- /dev/null
+++ b/group22/910725683/week01/.gitignore
@@ -0,0 +1,4 @@
+/bin/
+/.settings/
+.classpatch
+.prject
\ No newline at end of file
diff --git a/group22/910725683/week01/.project b/group22/910725683/week01/.project
new file mode 100644
index 0000000000..3b3c4fa7ee
--- /dev/null
+++ b/group22/910725683/week01/.project
@@ -0,0 +1,17 @@
+
+
+ week01
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group22/910725683/week01/src/com/coding/basic/ArrayList.java b/group22/910725683/week01/src/com/coding/basic/ArrayList.java
new file mode 100644
index 0000000000..acc0e9f8f4
--- /dev/null
+++ b/group22/910725683/week01/src/com/coding/basic/ArrayList.java
@@ -0,0 +1,98 @@
+package com.coding.basic;
+import java.util.Arrays;
+
+public class ArrayList implements List {
+
+ //数组初始容量//
+ private final int DEFAULT_CAPICITY=7;
+
+ //数组元素个数//
+ private int size = 0;
+
+ private Object[] elementData = new Object[DEFAULT_CAPICITY];
+
+ public void add(Object o){
+ ensureCapcity(size+1);
+ elementData[size++]=o;
+ }
+ public void add(int index, Object o){
+ //index要连续的增加//
+ checkIndex(index);
+ ensureCapcity(size+1);
+ /* index及后面的元素左移一位,即从index开始移动,注意index从0开始,
+ * 即还要+1,则长度为size-((index)+1)+1
+ */
+ 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 temp=elementData[index];
+ /* index后面的元素左移一位,即从index+1开始移动,注意index从0开始,
+ * 即还要+1,则长度为size-((index+1)+1)+1
+ */
+ System.arraycopy(elementData, index+1, elementData, index, size-index-1);
+ size--;
+ return temp;
+ }
+
+ public int size(){
+ return size;
+ }
+
+ public Iterator iterator(){
+ return new Iterator();
+ }
+
+ private class Iterator{
+ private int index=0;
+ public boolean hasNext(){
+ return index=size){
+ throw new IndexOutOfBoundsException("get " + index+" in "+size);
+ }
+ }
+
+ //判断是否需要扩容并完成扩容//
+ private void ensureCapcity(int size){
+ int oldLength=elementData.length;
+ if (size>=oldLength){
+ //util.ArrayList中的公式,源代码使用的右移1,即除2//
+ int newLength=oldLength/2+oldLength;
+ if (newLength7->10 , 逆置后变为 10->7->3
+ */
+ public void reverse(){
+ /*两个指针,开始的时候指向头跟头后面的一个(前指针、后指针)
+ *循环:每次向后移动步长1,至后指针移到链表尾,size-1个节点需要移动(size-1)-1次
+ *先保留前指针的值temp,即当前逆序链表的头,然后再移动前、后指针
+ *移动后,将前指针的节点连接到逆序链表的头,开始下一次移动
+ *循环结束后,注意到实际重连的只有旧链表的第二个节点到倒数第个节点,需要单独处理旧链表的头尾节点
+ *旧链表的尾节点需要链接到逆序链表的头,旧链表的头节点的指针置空,不然会1<->2
+ *维护头尾标记
+ */
+ Node current=head;
+ Node currentAfter=current.next;
+ Node temp;
+ for (int i=0;i5->7->8 , 删除以后的值为 7->8
+ * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10
+ */
+ public void removeFirstHalf(){
+ //int截断,不会有小数//
+ int removeLength = size / 2;
+ for (int i=1;i<=removeLength;i++){
+ removeFirst();
+ }
+ }
+
+ /**
+ * 从第i个元素开始, 删除length 个元素 , 注意i从0开始
+ * @param i
+ * @param length
+ */
+ public void remove(int i, int length){
+ checkIndex(i);
+ length=length+i-1;
+ if (i+length-1>size){
+ length=size-i;
+ }
+ //从后往前删除,防止越界//
+ for (int k=length;k>=i;k--){
+ remove(k);
+ }
+ }
+ /**
+ * 假定当前链表和list均包含已升序排列的整数
+ * 从当前链表中取出那些list所指定的元素
+ * 例如当前链表 = 11->101->201->301->401->501->601->701
+ * listB = 1->3->4->6
+ * 返回的结果应该是[101,301,401,601]
+ * @param list
+ */
+ public int[] getElements(LinkedList list){
+ int indexLength=list.size();
+ int[] result=new int[indexLength];
+ for (int i=0;isize){
+ result[i]=0;
+ }else{
+ result[i]=(int)list.get(index);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。
+ * 从当前链表中中删除在list中出现的元素
+ * @param list
+ */
+ //注意到递增,在外层循环list的时候,保留内层循环的被比较链表的节点的下标并递增即可//
+ public void subtract(LinkedList list){
+ int startIndex=0;
+ Iterator iter=list.iterator();
+ while(iter.hasNext()){
+ int src =(int) iter.next();
+ while(startIndexmax){
+ if (isHeadNoed){
+ current=current.next;
+ removeFirst();
+ }else{
+ temp.next=current.next;
+ current=current.next;
+ size--;
+ }
+ }else{
+ temp=current;
+ current=current.next;
+ isHeadNoed=false;
+ }
+
+ }
+ }
+
+ /**
+ * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同)
+ * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列
+ * @param list
+ */
+ //注意到递增,保留内循环下标位置递增即可//
+ public LinkedList intersection( LinkedList list){
+ LinkedList result = new LinkedList();
+ int startIndex = 0;
+ for (Iterator iter = list.iterator();iter.hasNext();){
+ int src = (int) iter.next();
+ while (startIndex=size){
+ throw new IndexOutOfBoundsException("get " + index+" in "+size);
+ }
+ }
+
+ public String toString(){
+ StringBuilder sb = new StringBuilder();
+ Node current = head;
+ for (int i=0;i");
+ }
+ current=current.next;
+ }
+ return sb.toString();
+ }
+}
\ No newline at end of file
diff --git a/group22/910725683/week01/src/com/coding/basic/List.java b/group22/910725683/week01/src/com/coding/basic/List.java
new file mode 100644
index 0000000000..29caa79f69
--- /dev/null
+++ b/group22/910725683/week01/src/com/coding/basic/List.java
@@ -0,0 +1,10 @@
+package com.coding.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();
+}
\ No newline at end of file
diff --git a/group22/910725683/week01/src/com/coding/basic/Queue.java b/group22/910725683/week01/src/com/coding/basic/Queue.java
new file mode 100644
index 0000000000..6e1b288ebc
--- /dev/null
+++ b/group22/910725683/week01/src/com/coding/basic/Queue.java
@@ -0,0 +1,26 @@
+package com.coding.basic;
+
+public class Queue {
+
+ private LinkedList queue = new LinkedList();
+
+ public void enQueue(Object o){
+ queue.add(o);
+ }
+
+ public Object deQueue(){
+ return queue.removeFirst();
+ }
+
+ public boolean isEmpty(){
+ return queue.size()==0;
+ }
+
+ public int size(){
+ return queue.size();
+ }
+
+ public String toString() {
+ return queue.toString();
+ }
+}
\ No newline at end of file
diff --git a/group22/910725683/week01/src/com/coding/basic/Stack.java b/group22/910725683/week01/src/com/coding/basic/Stack.java
new file mode 100644
index 0000000000..a8d071b707
--- /dev/null
+++ b/group22/910725683/week01/src/com/coding/basic/Stack.java
@@ -0,0 +1,27 @@
+package com.coding.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 String toString() {
+ return elementData.toString();
+ }
+}
\ No newline at end of file
diff --git a/group22/910725683/week01/test/com/coding/basic/ArrayListTest.java b/group22/910725683/week01/test/com/coding/basic/ArrayListTest.java
new file mode 100644
index 0000000000..e0940e8acb
--- /dev/null
+++ b/group22/910725683/week01/test/com/coding/basic/ArrayListTest.java
@@ -0,0 +1,53 @@
+package com.coding.basic;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class ArrayListTest {
+
+ ArrayList al = new ArrayList();
+
+ @Test
+ public void testAddObject() {
+ for (int i=1;i<=5;i++){
+ al.add(i);
+ }
+ }
+
+ @Test
+ public void testAddIntObject() {
+ testAddObject();
+ al.add(3, 12);
+ System.out.println("inser index 3 value 12 : "+al.toString());
+ }
+
+ @Test
+ public void testGet() {
+ testAddObject();
+ System.out.println("get index 4 : "+al.get(4));
+ }
+
+ @Test
+ public void testRemove() {
+ testAddObject();
+ System.out.println("remove index 3 : "+al.remove(3));
+ }
+
+ @Test
+ public void testSize() {
+ testAddObject();
+ System.out.println("get size : "+al.size());
+ }
+
+ @Test
+ public void testIterator() {
+ fail("Not yet implemented");
+ }
+
+ @Test
+ public void testToString() {
+ fail("Not yet implemented");
+ }
+
+}
diff --git a/group22/910725683/week01/test/com/coding/basic/BinaryTreeNodeTest.java b/group22/910725683/week01/test/com/coding/basic/BinaryTreeNodeTest.java
new file mode 100644
index 0000000000..b32b779091
--- /dev/null
+++ b/group22/910725683/week01/test/com/coding/basic/BinaryTreeNodeTest.java
@@ -0,0 +1,47 @@
+package com.coding.basic;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+import com.coding.basic.BinaryTreeNode;
+
+public class BinaryTreeNodeTest {
+
+ BinaryTreeNode btn = new BinaryTreeNode();
+
+ @Test
+ public void testPreOrder() {
+ testInsert();
+ System.out.print("preOrde : ");
+ btn.preOrder(btn);
+ System.out.println("");
+ }
+
+ @Test
+ public void testInOrder() {
+ testInsert();
+ System.out.print("inOrder : ");
+ btn.inOrder(btn);
+ System.out.println("");
+ }
+
+ @Test
+ public void testPostOrder() {
+ testInsert();
+ System.out.print("postOrder : ");
+ btn.postOrder(btn);
+ System.out.println("");
+ }
+
+ @Test
+ public void testInsert() {
+ btn.insert(45);
+ btn.insert(24);
+ btn.insert(53);
+ btn.insert(12);
+ btn.insert(37);
+ btn.insert(93);
+ }
+
+}
diff --git a/group22/910725683/week01/test/com/coding/basic/LinkedListTest.java b/group22/910725683/week01/test/com/coding/basic/LinkedListTest.java
new file mode 100644
index 0000000000..2d22e2e92d
--- /dev/null
+++ b/group22/910725683/week01/test/com/coding/basic/LinkedListTest.java
@@ -0,0 +1,137 @@
+package com.coding.basic;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+import com.coding.basic.LinkedList;
+
+public class LinkedListTest {
+ LinkedList ll =new LinkedList();
+ @Test
+ public void testAddObject() {
+ for (int i=0;i<9;i++){
+ ll.add(i);
+ }
+ }
+
+ @Test
+ public void testAddIntObject() {
+ testAddObject();
+ ll.add(4, 22);
+ ll.add(0, 23);
+ System.out.println("add int : " + ll.toString());
+ }
+
+ @Test
+ public void testGet() {
+ testAddObject();
+ System.out.println("get index 3 : "+ll.get(3));
+ }
+
+ @Test
+ public void testRemoveInt() {
+ testAddObject();
+ System.out.println("remove index 5 : "+ll.get(5));
+ }
+
+ @Test
+ public void testSize() {
+ testAddObject();
+ System.out.println("get size : "+ll.size());
+ }
+
+ @Test
+ public void testAddFirst() {
+ testAddObject();
+ ll.addFirst(12);
+ System.out.println("add first : "+ll.toString());
+ }
+
+ @Test
+ public void testAddLast() {
+ testAddObject();
+ ll.addLast(23);
+ System.out.println("add first : "+ll.toString());
+ }
+
+ @Test
+ public void testRemoveFirst() {
+ testAddObject();
+ ll.removeFirst();
+ System.out.println("remove first : "+ll.toString());
+ }
+
+ @Test
+ public void testRemoveLast() {
+ testAddObject();
+ ll.removeLast();
+ System.out.println("remove last : "+ll.toString());
+ }
+
+ @Test
+ public void testReverse() {
+ testAddObject();
+ ll.reverse();
+ System.out.println("reverse : "+ll.toString());
+ }
+
+ @Test
+ public void testRemoveFirstHalf() {
+ testAddObject();
+ ll.removeFirstHalf();
+ System.out.println("remove first half : "+ll.toString());
+ }
+
+ @Test
+ public void testRemoveIntInt() {
+ testAddObject();
+ ll.remove(2, 4);
+ System.out.println("remove index 2 length 4 : "+ll.toString());
+ }
+
+ @Test
+ public void testGetElements() {
+ testAddObject();
+ System.out.println("get index 2 : "+ll.get(2));
+ }
+
+ @Test
+ public void testSubtract() {
+ testAddObject();
+ LinkedList test1 =new LinkedList();
+ for (int i=2;i<5;i++){
+ test1.add(i);
+ }
+ ll.subtract(test1);
+ System.out.println("subtract "+test1.toString()+" : "+ll.toString());
+ }
+
+ @Test
+ public void testRemoveDuplicateValues() {
+ testAddObject();
+ for (int i=6;i>2;i--){
+ ll.add(i,i);
+ }
+ ll.removeDuplicateValues();
+ System.out.println("remove dupl : "+ll.toString());
+ }
+
+ @Test
+ public void testRemoveRange() {
+ testAddObject();
+ ll.removeRange(3, 6);
+ System.out.println("remove range[3,6] : "+ll.toString());
+ }
+
+ @Test
+ public void testIntersection() {
+ testAddObject();
+ LinkedList test2 =new LinkedList();
+ for (int i=4;i<14;i=i+2){
+ test2.add(i);
+ }
+ System.out.println("intersection "+test2.toString()+" : "+ll.intersection(test2));
+ }
+
+}
diff --git a/group22/910725683/week01/test/com/coding/basic/QueueTest.java b/group22/910725683/week01/test/com/coding/basic/QueueTest.java
new file mode 100644
index 0000000000..18cba75d07
--- /dev/null
+++ b/group22/910725683/week01/test/com/coding/basic/QueueTest.java
@@ -0,0 +1,40 @@
+package com.coding.basic;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+import com.coding.basic.Queue;
+
+public class QueueTest {
+ Queue queue = new Queue();
+
+ @Test
+ public void testEnQueue() {
+ for (int i=0;i<10;i++){
+ queue.enQueue(i);
+ }
+ }
+
+ @Test
+ public void testDeQueue() {
+ testEnQueue();
+ for (int i=0;i<3;i++){
+ System.out.println("deQueue : " + queue.deQueue());
+ }
+ }
+
+ @Test
+ public void testIsEmpty() {
+ System.out.println("is empty(true) : "+queue.isEmpty());
+ testEnQueue();
+ System.out.println("is empty(false) : "+queue.isEmpty());
+ }
+
+ @Test
+ public void testSize() {
+ testEnQueue();
+ System.out.println("size : "+queue.size());
+ }
+
+}
diff --git a/group22/910725683/week01/test/com/coding/basic/StackTest.java b/group22/910725683/week01/test/com/coding/basic/StackTest.java
new file mode 100644
index 0000000000..0c8095d79c
--- /dev/null
+++ b/group22/910725683/week01/test/com/coding/basic/StackTest.java
@@ -0,0 +1,48 @@
+package com.coding.basic;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+import com.coding.basic.Stack;
+
+public class StackTest {
+ Stack stack = new Stack();
+
+ @Test
+ public void testPush() {
+ for (int i = 0; i < 10; i++) {
+ stack.push(i);
+ }
+ }
+
+ @Test
+ public void testPop() {
+ testPush();
+ for (int i = 0; i < 3; i++) {
+ System.out.println("pop : "+stack.pop());
+ }
+ }
+
+ @Test
+ public void testPeek() {
+ testPush();
+ for (int i = 0; i < 3; i++) {
+ System.out.println("peek : "+stack.peek());
+ }
+ }
+
+ @Test
+ public void testIsEmpty() {
+ System.out.println("is empty(true) : "+stack.isEmpty());
+ testPush();
+ System.out.println("is empty(false) : "+stack.isEmpty());
+ }
+
+ @Test
+ public void testSize() {
+ testPush();
+ System.out.println("size : "+stack.size());
+ }
+
+}
From 27102f7976c974d7209a70bcd643e34c33585872 Mon Sep 17 00:00:00 2001
From: Kewy2017
Date: Sat, 11 Mar 2017 17:12:13 +0800
Subject: [PATCH 029/155] Mywork for first week
data structure: ArrayList, LinkedList, Stack, Queue, BinaryTree
unit test: creat a class for student test score, and use Junit to call
method written.
---
group22/1014331282/Mywork_LX/.classpath | 7 +
group22/1014331282/Mywork_LX/.project | 17 ++
.../.settings/org.eclipse.jdt.core.prefs | 11 ++
.../Mywork_LX/src/week1_0306/ArrayList.java | 114 +++++++++++
.../Mywork_LX/src/week1_0306/BinaryTree.java | 135 +++++++++++++
.../Mywork_LX/src/week1_0306/Iterator.java | 9 +
.../Mywork_LX/src/week1_0306/LinkedList.java | 181 ++++++++++++++++++
.../Mywork_LX/src/week1_0306/List.java | 18 ++
.../Mywork_LX/src/week1_0306/Queue.java | 35 ++++
.../Mywork_LX/src/week1_0306/ScoreRecord.java | 180 +++++++++++++++++
.../Mywork_LX/src/week1_0306/Stack.java | 36 ++++
.../src/week1_0306/Test_ArrayList.java | 56 ++++++
.../Mywork_LX/src/week1_0306/Test_BTree.java | 41 ++++
.../Mywork_LX/src/week1_0306/Test_Queue.java | 45 +++++
.../Mywork_LX/src/week1_0306/Test_Stack.java | 48 +++++
15 files changed, 933 insertions(+)
create mode 100644 group22/1014331282/Mywork_LX/.classpath
create mode 100644 group22/1014331282/Mywork_LX/.project
create mode 100644 group22/1014331282/Mywork_LX/.settings/org.eclipse.jdt.core.prefs
create mode 100644 group22/1014331282/Mywork_LX/src/week1_0306/ArrayList.java
create mode 100644 group22/1014331282/Mywork_LX/src/week1_0306/BinaryTree.java
create mode 100644 group22/1014331282/Mywork_LX/src/week1_0306/Iterator.java
create mode 100644 group22/1014331282/Mywork_LX/src/week1_0306/LinkedList.java
create mode 100644 group22/1014331282/Mywork_LX/src/week1_0306/List.java
create mode 100644 group22/1014331282/Mywork_LX/src/week1_0306/Queue.java
create mode 100644 group22/1014331282/Mywork_LX/src/week1_0306/ScoreRecord.java
create mode 100644 group22/1014331282/Mywork_LX/src/week1_0306/Stack.java
create mode 100644 group22/1014331282/Mywork_LX/src/week1_0306/Test_ArrayList.java
create mode 100644 group22/1014331282/Mywork_LX/src/week1_0306/Test_BTree.java
create mode 100644 group22/1014331282/Mywork_LX/src/week1_0306/Test_Queue.java
create mode 100644 group22/1014331282/Mywork_LX/src/week1_0306/Test_Stack.java
diff --git a/group22/1014331282/Mywork_LX/.classpath b/group22/1014331282/Mywork_LX/.classpath
new file mode 100644
index 0000000000..373dce4005
--- /dev/null
+++ b/group22/1014331282/Mywork_LX/.classpath
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/group22/1014331282/Mywork_LX/.project b/group22/1014331282/Mywork_LX/.project
new file mode 100644
index 0000000000..1290d27942
--- /dev/null
+++ b/group22/1014331282/Mywork_LX/.project
@@ -0,0 +1,17 @@
+
+
+ Mywork_LX
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group22/1014331282/Mywork_LX/.settings/org.eclipse.jdt.core.prefs b/group22/1014331282/Mywork_LX/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000000..3a21537071
--- /dev/null
+++ b/group22/1014331282/Mywork_LX/.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/group22/1014331282/Mywork_LX/src/week1_0306/ArrayList.java b/group22/1014331282/Mywork_LX/src/week1_0306/ArrayList.java
new file mode 100644
index 0000000000..5446c9b557
--- /dev/null
+++ b/group22/1014331282/Mywork_LX/src/week1_0306/ArrayList.java
@@ -0,0 +1,114 @@
+package week1_0306;
+
+
+
+public class ArrayList implements List
+{
+
+ private int size;
+
+ private Object[] elementData ;
+
+ public ArrayList()
+ {
+ elementData = new Object[3];
+ size=-1;
+ }
+
+ public void add(Object o)
+ {
+ if(size >= elementData.length-1)
+ {
+ Object[] replaceData=new Object[elementData.length+5];
+ System.arraycopy(elementData, 0, replaceData, 0, elementData.length);
+ elementData = replaceData;
+ }
+ elementData[++size] = o;
+ }
+
+ public void add(int index, Object o)
+ {
+ Object[] replaceData=new Object[11];
+ for(int i=0;i=0 && size>=0)
+ return elementData[index];
+ else return null;
+ }
+
+
+ public Object remove(int index)
+ {
+ size--;
+ Object o=elementData[index];
+ if (index0)
+ {
+ for(int i=index;i=0)
+ return size+1;
+ else
+ return 0;
+ }
+
+ public Iterator iterator()
+ {
+ return new ArrayListIterator(this);
+ }
+
+ private class ArrayListIterator implements Iterator
+ {
+ ArrayList l=null;
+ int pos = 0;
+ private ArrayListIterator(ArrayList l)
+ {
+ this.l=l;
+ }
+
+ @Override
+ public boolean hasNext() {
+ // TODO Auto-generated method stub
+ pos++;
+ if(pos > size)
+ return false;
+ else return true;
+ }
+
+ @Override
+ public Object next() {
+ // TODO Auto-generated method stub
+ return elementData[pos];
+
+ }
+
+ public Object remove()
+ {
+ return this.l.remove(pos);
+ }
+
+ }
+
+}
diff --git a/group22/1014331282/Mywork_LX/src/week1_0306/BinaryTree.java b/group22/1014331282/Mywork_LX/src/week1_0306/BinaryTree.java
new file mode 100644
index 0000000000..e5b23d37ce
--- /dev/null
+++ b/group22/1014331282/Mywork_LX/src/week1_0306/BinaryTree.java
@@ -0,0 +1,135 @@
+package week1_0306;
+
+import java.util.Comparator;
+
+import week1_0306.BinaryTree.BinaryTreeNode;
+
+public class BinaryTree
+{
+ private BinaryTreeNode root;
+
+ private BinaryTreeNode pointer;
+
+ public BinaryTreeNode getRoot() {
+ return root;
+ }
+
+ public void setRoot(BinaryTreeNode root) {
+ this.root = root;
+ }
+
+ public BinaryTreeNode getPointer() {
+ return pointer;
+ }
+
+ public void setPointer(BinaryTreeNode pointer) {
+ this.pointer = pointer;
+ }
+
+ public BinaryTree()
+ {
+ root=new BinaryTreeNode();
+ pointer=root;
+ }
+
+ public BinaryTreeNode insert(Object o,Comparator c)
+ {
+
+ pointer= root.insert(o, c);
+ return pointer;
+ }
+
+ public void printTree()
+ {
+ root.printNode();
+ }
+
+ 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() {
+ pointer=left;
+ return left;
+ }
+
+ public void setLeft(BinaryTreeNode left) {
+ this.left = left;
+ }
+
+ public BinaryTreeNode getRight() {
+ pointer=right;
+ return right;
+ }
+
+ public void setRight(BinaryTreeNode right) {
+ this.right = right;
+ }
+
+
+
+ public BinaryTreeNode insert(Object o, Comparator c) //建有规律的树+插入
+ {
+ if(this.data == null)
+ {
+ this.data = o;
+ return this;
+ }
+
+ int i = c.compare(this.data,o);
+
+ if( i > 0 )
+ {
+ if(this.left == null)
+ {
+ this.left=new BinaryTreeNode();
+ this.left.data=o;
+ return this.left;
+ }
+ else
+ return this.left.insert(o, c);
+ }
+ else if(i < 0)
+ {
+ if(this.right == null)
+ {
+ this.right=new BinaryTreeNode();
+ this.right.data = o;
+ return this.right;
+ }
+
+ else
+ return this.right.insert(o, c);
+ }
+ else
+ {
+ return this;
+ }
+
+ }
+
+ public void printNode()
+ {
+ ScoreRecord s=(ScoreRecord)(this.getData());
+ System.out.println(s.getName()+" "+s.getId());
+ if(this.getLeft()!=null)
+ this.getLeft().printNode();
+ if(this.getRight()!=null)
+ this.getRight().printNode();
+ else return;
+ }
+
+ }
+
+}
diff --git a/group22/1014331282/Mywork_LX/src/week1_0306/Iterator.java b/group22/1014331282/Mywork_LX/src/week1_0306/Iterator.java
new file mode 100644
index 0000000000..26471af1cd
--- /dev/null
+++ b/group22/1014331282/Mywork_LX/src/week1_0306/Iterator.java
@@ -0,0 +1,9 @@
+package week1_0306;
+
+public interface Iterator {
+
+ public boolean hasNext();
+ public Object next();
+ public Object remove();
+
+}
diff --git a/group22/1014331282/Mywork_LX/src/week1_0306/LinkedList.java b/group22/1014331282/Mywork_LX/src/week1_0306/LinkedList.java
new file mode 100644
index 0000000000..e540a7c115
--- /dev/null
+++ b/group22/1014331282/Mywork_LX/src/week1_0306/LinkedList.java
@@ -0,0 +1,181 @@
+package week1_0306;
+
+
+
+public class LinkedList implements List
+{
+ private Node head;
+
+ private static int size = 0;
+
+ public LinkedList()
+ {
+ head=new Node();
+
+ }
+
+
+ private static class Node
+ {
+ Object data;
+ Node next;
+ }
+
+ public void add(Object o)
+ {
+ Node h = head;
+ while(h.next!= null)
+ {
+ h=h.next;
+ }
+ Node p = new Node();
+ p.data=o;
+ p.next=null;
+ h.next= p;
+
+ size++;
+ }
+
+ public void add(int index, Object o)
+ {
+ Node h=head.next;
+ int i=0;
+ while(i size)
+ return false;
+ else return true;
+ }
+
+ @Override
+ public Object next() {
+ // TODO Auto-generated method stub
+ return l.get(pos);
+
+ }
+
+ public Object remove()
+ {
+ return this.l.remove(pos);
+ }
+
+ }
+
+
+}
+
diff --git a/group22/1014331282/Mywork_LX/src/week1_0306/List.java b/group22/1014331282/Mywork_LX/src/week1_0306/List.java
new file mode 100644
index 0000000000..7ec758f832
--- /dev/null
+++ b/group22/1014331282/Mywork_LX/src/week1_0306/List.java
@@ -0,0 +1,18 @@
+package week1_0306;
+
+
+
+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/group22/1014331282/Mywork_LX/src/week1_0306/Queue.java b/group22/1014331282/Mywork_LX/src/week1_0306/Queue.java
new file mode 100644
index 0000000000..e9c32b8e68
--- /dev/null
+++ b/group22/1014331282/Mywork_LX/src/week1_0306/Queue.java
@@ -0,0 +1,35 @@
+package week1_0306;
+
+public class Queue {
+
+ private LinkedList queue = new LinkedList();
+
+ public void enQueue(Object o)//进队列
+ {
+ queue.addFirst(o);
+ }
+
+ public Object deQueue()//出队列
+ {
+ return queue.removeLast();
+ }
+
+ public boolean isEmpty()
+ {
+ if(queue.get(0)==null)
+ return true;
+ else return false;
+ }
+
+ public int size()
+ {
+ return queue.size();
+ }
+
+ public Queue() {
+ // TODO Auto-generated constructor stub
+ }
+
+
+
+}
diff --git a/group22/1014331282/Mywork_LX/src/week1_0306/ScoreRecord.java b/group22/1014331282/Mywork_LX/src/week1_0306/ScoreRecord.java
new file mode 100644
index 0000000000..f3bce47950
--- /dev/null
+++ b/group22/1014331282/Mywork_LX/src/week1_0306/ScoreRecord.java
@@ -0,0 +1,180 @@
+package week1_0306;
+/*
+提示录入几个学生信息
+录入学号姓名三门成绩
+打印学生中语文数学英语成绩最高的那个人
+统计每门课的平均成绩及总成绩的平均值
+封装处理
+*/
+import java.util.Scanner;
+import java.util.Comparator;
+
+public class ScoreRecord implements Comparator
+{
+
+ private int id;
+ private String name;
+ private float C_Score;
+ private float M_Score;
+ private float E_Score;
+
+ public ScoreRecord(){};
+
+ public ScoreRecord(int id,String name,float C_Score, float M_Score, float E_Score)
+ {
+ this.id=id;
+ this.name=name;
+ this.C_Score=C_Score;
+ this.E_Score=E_Score;
+ this.M_Score=M_Score;
+ }
+
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public float getC_Score() {
+ return C_Score;
+ }
+
+ public void setC_Score(float c_Score) {
+ C_Score = c_Score;
+ }
+
+ public float getM_Score() {
+ return M_Score;
+ }
+
+ public void setM_Score(float m_Score) {
+ M_Score = m_Score;
+ }
+
+ public float getE_Score() {
+ return E_Score;
+ }
+
+ public void setE_Score(float e_Score) {
+ E_Score = e_Score;
+ }
+
+ public int compare(Object o1, Object o2)
+ {
+ ScoreRecord s1 = (ScoreRecord) o1;
+ ScoreRecord s2 = (ScoreRecord) o2;
+ if(s1.id>s2.id)
+ return 1;
+ else if(s1.id==s2.id)
+ return 0;
+ else
+ return -1;
+ }
+
+ public int compareTo(Object o1)
+ {
+ ScoreRecord s = (ScoreRecord) o1;
+ if(this.id>s.id)
+ return 1;
+ else if(this.id==s.id)
+ return 0;
+ else return -1;
+ }
+
+ public static void readData(ScoreRecord[] arr)
+ {
+ Scanner a=new Scanner(System.in);
+ for(int i=0;i
Date: Sat, 11 Mar 2017 19:01:42 +0800
Subject: [PATCH 030/155] done with LinkedList&Queue&Stack no Test
---
group22/2622819383/Task1/LinkedList.java | 127 +++++++++++++++++------
group22/2622819383/Task1/Queue.java | 10 +-
group22/2622819383/Task1/Stack.java | 11 +-
3 files changed, 105 insertions(+), 43 deletions(-)
diff --git a/group22/2622819383/Task1/LinkedList.java b/group22/2622819383/Task1/LinkedList.java
index d431e25fdb..70ddd5d7a0 100644
--- a/group22/2622819383/Task1/LinkedList.java
+++ b/group22/2622819383/Task1/LinkedList.java
@@ -1,59 +1,118 @@
public class LinkedList implements List {
- private Node head;
+ private Node header;
+
+ private Node trailer;
+
+ private int theSize;
+
+ public LinkedList() {
+ header = new Node(null, null, null);
+ trailer = new Node(null, header, null);
+ header.succ = trailer;
+ theSize = 0;
+ }
public void add(Object o){
-
+ add(size(), o);
}
public void add(int index , Object o){
-
+ if (index < 0 || theSize < index) throw new IndexOutOfBoundsException();
+ Node p = header;
+ while (0 < index--) p = p.succ();
+ p.insertAsSucc(o);
+ theSize++;
}
public Object get(int index){
- return null;
+ if (index < 0 || theSize <= index) throw new IndexOutOfBoundsException();
+ Node p = header.succ();
+ while (0 < index--) p = p.succ();
+
+ return p.data();
}
public Object remove(int index){
- return null;
+ if (0 < index || theSize <= index) throw new IndexOutOfBoundsException();
+ Node p = header.succ();
+ while (0 < index--) p = p.succ();
+ Object removed = p.data();
+ p.pred().succ = p.succ();
+ p.succ().pred = p.pred();
+ theSize--;
+ return removed;
}
public int size(){
- return -1;
+ return theSize;
}
public void addFirst(Object o){
-
+ header.insertAsSucc(o);
}
public void addLast(Object o){
-
+ trailer.insertAsPred(o);
}
public Object removeFirst(){
- return null;
+ return remove(0);
}
public Object removeLast(){
- return null;
+ return remove(theSize - 1);
}
public Iterator iterator(){
- return null;
- }
-
+ return new LinkedListIterator();
+ }
+ private class LinkedListIterator implements Iterator {
+ private Node current = header.succ();
+ public boolean hasNext() {
+ return current != trailer;
+ }
+ public Object next() {
+ if (!hasNext()) throw new java.util.NoSuchElementException();
+ Object item = current.data();
+ current = current.succ();
+ return item;
+ }
+ }
- private static class Node{
- Object data;
- Node next;
+ private static class Node{
+ private Object data;
+ private Node pred;
+ private Node succ;
+ public Node(Object d, Node p, Node s) {
+ data = d;
+ pred = p;
+ succ = s;
+ }
+ public Object data() { return data; }
+ public Node succ() { return succ; }
+ public Node pred() { return pred; }
+ //插入前驱节点,返回新节点
+ public Node insertAsPred(Object data) {
+ Node p = new Node(data, pred, this);
+ pred = pred.succ = p;
+ return p;
+ }
+ public Node insertAsSucc(Object data) {
+ Node p = new Node(data, this, succ);
+ succ = succ.pred = p;
+ return p;
+ }
+
+
}
/**
- * 鎶婅閾捐〃閫嗙疆
- * 渚嬪閾捐〃涓 3->7->10 , 閫嗙疆鍚庡彉涓 10->7->3
+ * 把该链表逆置
+ * 例如链表为 3->7->10 , 逆置后变为 10->7->3
*/
public void reverse(){
}
/**
- * 鍒犻櫎涓涓崟閾捐〃鐨勫墠鍗婇儴鍒
- * 渚嬪锛歭ist = 2->5->7->8 , 鍒犻櫎浠ュ悗鐨勫间负 7->8
- * 濡傛灉list = 2->5->7->8->10 ,鍒犻櫎浠ュ悗鐨勫间负7,8,10
+ * 删除一个单链表的前半部分
+ * 例如:list = 2->5->7->8 , 删除以后的值为 7->8
+ * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10
*/
public void removeFirstHalf(){
@@ -61,7 +120,7 @@ public void removeFirstHalf(){
}
/**
- * 浠庣i涓厓绱犲紑濮嬶紝 鍒犻櫎length 涓厓绱 锛 娉ㄦ剰i浠0寮濮
+ * 从第i个元素开始, 删除length 个元素 , 注意i从0开始
* @param i
* @param length
*/
@@ -69,11 +128,11 @@ public void remove(int i, int length){
}
/**
- * 鍋囧畾褰撳墠閾捐〃鍜宭ist鍧囧寘鍚凡鍗囧簭鎺掑垪鐨勬暣鏁
- * 浠庡綋鍓嶉摼琛ㄤ腑鍙栧嚭閭d簺list鎵鎸囧畾鐨勫厓绱
- * 渚嬪褰撳墠閾捐〃 = 11->101->201->301->401->501->601->701
+ * 假定当前链表和list均包含已升序排列的整数
+ * 从当前链表中取出那些list所指定的元素
+ * 例如当前链表 = 11->101->201->301->401->501->601->701
* listB = 1->3->4->6
- * 杩斿洖鐨勭粨鏋滃簲璇ユ槸[101,301,401,601]
+ * 返回的结果应该是[101,301,401,601]
* @param list
*/
public static int[] getElements(LinkedList list){
@@ -81,8 +140,8 @@ public static int[] getElements(LinkedList list){
}
/**
- * 宸茬煡閾捐〃涓殑鍏冪礌浠ュ奸掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩
- * 浠庡綋鍓嶉摼琛ㄤ腑涓垹闄ゅ湪list涓嚭鐜扮殑鍏冪礌
+ * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。
+ * 从当前链表中中删除在list中出现的元素
* @param list
*/
@@ -92,16 +151,16 @@ public void subtract(LinkedList list){
}
/**
- * 宸茬煡褰撳墠閾捐〃涓殑鍏冪礌浠ュ奸掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩
- * 鍒犻櫎琛ㄤ腑鎵鏈夊肩浉鍚岀殑澶氫綑鍏冪礌锛堜娇寰楁搷浣滃悗鐨勭嚎鎬ц〃涓墍鏈夊厓绱犵殑鍊煎潎涓嶇浉鍚岋級
+ * 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。
+ * 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同)
*/
public void removeDuplicateValues(){
}
/**
- * 宸茬煡閾捐〃涓殑鍏冪礌浠ュ奸掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩
- * 璇曞啓涓楂樻晥鐨勭畻娉曪紝鍒犻櫎琛ㄤ腑鎵鏈夊煎ぇ浜巑in涓斿皬浜巑ax鐨勫厓绱狅紙鑻ヨ〃涓瓨鍦ㄨ繖鏍风殑鍏冪礌锛
+ * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。
+ * 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素)
* @param min
* @param max
*/
@@ -110,8 +169,8 @@ public void removeRange(int min, int max){
}
/**
- * 鍋囪褰撳墠閾捐〃鍜屽弬鏁發ist鎸囧畾鐨勯摼琛ㄥ潎浠ュ厓绱犱緷鍊奸掑鏈夊簭鎺掑垪锛堝悓涓琛ㄤ腑鐨勫厓绱犲煎悇涓嶇浉鍚岋級
- * 鐜拌姹傜敓鎴愭柊閾捐〃C锛屽叾鍏冪礌涓哄綋鍓嶉摼琛ㄥ拰list涓厓绱犵殑浜ら泦锛屼笖琛–涓殑鍏冪礌鏈変緷鍊奸掑鏈夊簭鎺掑垪
+ * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同)
+ * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列
* @param list
*/
public LinkedList intersection( LinkedList list){
diff --git a/group22/2622819383/Task1/Queue.java b/group22/2622819383/Task1/Queue.java
index 08f1e8ba29..654a1e3e38 100644
--- a/group22/2622819383/Task1/Queue.java
+++ b/group22/2622819383/Task1/Queue.java
@@ -1,17 +1,19 @@
public class Queue {
+ private LinkedList elementData = new LinkedList();
- public void enQueue(Object o){
+ public void enQueue(Object o){
+ elementData.addLast(o);
}
public Object deQueue(){
- return null;
+ return elementData.removeFirst();
}
public boolean isEmpty(){
- return false;
+ return size() == 0;
}
public int size(){
- return -1;
+ return elementData.size();
}
}
diff --git a/group22/2622819383/Task1/Stack.java b/group22/2622819383/Task1/Stack.java
index 6c8c49bb10..17a4d0bd0f 100644
--- a/group22/2622819383/Task1/Stack.java
+++ b/group22/2622819383/Task1/Stack.java
@@ -1,20 +1,21 @@
public class Stack {
private ArrayList elementData = new ArrayList();
- public void push(Object o){
+ public void push(Object o){
+ elementData.add(o);
}
public Object pop(){
- return null;
+ return elementData.remove(size() - 1);
}
public Object peek(){
- return null;
+ return elementData.get(size() - 1);
}
public boolean isEmpty(){
- return false;
+ return size() == 0;
}
public int size(){
- return -1;
+ return elementData.size();
}
}
From ee94cd7ce5ff84826a35d360a631f4cb09e8110e Mon Sep 17 00:00:00 2001
From: laoheihei
Date: Sat, 11 Mar 2017 19:25:05 +0800
Subject: [PATCH 031/155] change from GB2312 to UTF-8
---
group22/2622819383/Task1/ArrayList.java | 103 ++++++++++++++----------
1 file changed, 60 insertions(+), 43 deletions(-)
diff --git a/group22/2622819383/Task1/ArrayList.java b/group22/2622819383/Task1/ArrayList.java
index 1c060ffe3a..19b0b6ca53 100644
--- a/group22/2622819383/Task1/ArrayList.java
+++ b/group22/2622819383/Task1/ArrayList.java
@@ -8,11 +8,10 @@ public class ArrayList implements List {
private Object[] elementData;
- //add()时用于扩容
+ //add()鏃剁敤浜庡湪蹇呰鏃跺埢鎵╁厖搴曞眰鏁扮粍瀹归噺
private void expand() {
- if (size < capacity) return;//尚未满员,不必扩容
-
- if (capacity < DEFAULT_CAPACITY) capacity = DEFAULT_CAPACITY;//不低于最小容量
+ if (size < capacity) return;//灏氭湭婊″憳锛屼笉蹇呮墿瀹
+ if (capacity < DEFAULT_CAPACITY) capacity = DEFAULT_CAPACITY;//涓嶄綆浜庢渶灏忓閲
Object[] oldElem = elementData;
elementData = new Object[capacity <<= 1];
@@ -20,67 +19,65 @@ private void expand() {
elementData[i] = oldElem[i];
}
- //remove()时用于缩容
+ //remove()鏃剁敤浜庡湪蹇呰鏃跺埢缂╁皬搴曞眰鏁扮粍瀹归噺
private void shrink() {
- if (capacity < DEFAULT_CAPACITY << 1) return;//不致收缩至DEFAULT_CAPACITY以下
-
- if (capacity >> 2 < size) return; //以25%为界
+ if (capacity < DEFAULT_CAPACITY << 1) return;//涓嶈嚧鏀剁缉鑷矰EFAULT_CAPACITY浠ヤ笅
+ if (capacity >> 2 < size) return; //浠25%涓虹晫
Object[] oldElem = elementData; elementData = new Object[capacity >>= 1];
for (int i = 0; i < size; i++)
- elementData[i] = oldElem[i];
-
+ elementData[i] = oldElem[i];
}
public ArrayList() {
clear();
}
- public ArrayList(Object ...args) {
- this();
- for (Object o : args)
- add(o);
- }
public void clear() {
size = 0;
elementData = new Object[capacity = DEFAULT_CAPACITY];
}
- public int size() { return size; }
+ public int size() {
+ return size;
+ }
- public int capacity() { return capacity; }//用于测试shrink()&expand()
+ public int capacity() { //鐢ㄤ簬娴嬭瘯shrink()&expand()
+ return capacity;
+ }
- public boolean isEmpty() { return size == 0; }
+ public boolean isEmpty() {
+ return size == 0;
+ }
public void add(Object o){
add(size(), o);
}
+
public void add(int index, Object o){
- if (index < 0 || size < index) throw new IndexOutOfBoundsException();
- expand();
+ if (index < 0 || size < index)
+ throw new IndexOutOfBoundsException();
+ expand();
for (int i = size; i > index; i--)
elementData[i] = elementData[i - 1];
elementData[index] = o;
-
size++;
}
- public void add(Object ...args) {
- for (Object o : args)
- add(o);
- }
-
+
public Object get(int index){
- if (index < 0 || size <= index) throw new IndexOutOfBoundsException();
- return elementData[index];
+ if (index < 0 || size <= index)
+ throw new IndexOutOfBoundsException();
+
+ return elementData[index];
}
public Object remove(int index){
- if (index < 0 || size <= index) throw new IndexOutOfBoundsException();
+ if (index < 0 || size <= index)
+ throw new IndexOutOfBoundsException();
Object removed = elementData[index];
-
for (int i = index; i < size - 1; i++)
elementData[i] = elementData[i + 1];
size--;
@@ -88,10 +85,7 @@ public Object remove(int index){
return removed;
}
- public void removeElems(int ...args) {
- for (int i : args)
- remove(i);
- }
+
public Iterator iterator(){
return new ArrayListIterator();
@@ -99,15 +93,39 @@ public Iterator iterator(){
private class ArrayListIterator implements Iterator {
private int current;
- public boolean hasNext() { return current != size; }
+
+ public boolean hasNext() {
+ return current != size;
+ }
+
public Object next() {
- if (!hasNext()) throw new java.util.NoSuchElementException();
+ if (!hasNext())
+ throw new java.util.NoSuchElementException();
return elementData[current++];
}
}
+
+
+ //浠ヤ笅鏂规硶渚夸簬娴嬭瘯
+
+ public ArrayList(Object ...args) {
+ this();
+ for (Object o : args)
+ add(o);
+ }
+
+ public void add(Object ...args) {
+ for (Object o : args)
+ add(o);
+ }
+
+ public void removeElems(int ...args) {
+ for (int i : args)
+ remove(i);
+ }
public static void showElements(ArrayList list) {
- System.out.print("当前list中元素:");
+ System.out.print("褰撳墠list涓厓绱狅細");
Iterator iter = list.iterator();
while (iter.hasNext())
System.out.print(iter.next() + " ");
@@ -115,12 +133,11 @@ public static void showElements(ArrayList list) {
}
public static void test(ArrayList list) {
- System.out.println("--------基本方法测试---------");
- System.out.println("当前list.isEmpty(): " + list.isEmpty());
- System.out.println("当前list.size(): " + list.size());
- System.out.println("当前list.capacity(): " + list.capacity());
- showElements(list);
-
+ System.out.println("--------鍩烘湰鏂规硶娴嬭瘯---------");
+ System.out.println("褰撳墠list.isEmpty(): " + list.isEmpty());
+ System.out.println("褰撳墠list.size(): " + list.size());
+ System.out.println("褰撳墠list.capacity(): " + list.capacity());
+ showElements(list);
}
public static void main(String[] args) {
From 4b527d28acde98b013b06bbe658bdcd9e749b792 Mon Sep 17 00:00:00 2001
From: laoheihei
Date: Sat, 11 Mar 2017 19:33:45 +0800
Subject: [PATCH 032/155] change Tab
---
group22/2622819383/Task1/ArrayList.java | 62 ++++++++++++-------------
1 file changed, 31 insertions(+), 31 deletions(-)
diff --git a/group22/2622819383/Task1/ArrayList.java b/group22/2622819383/Task1/ArrayList.java
index 19b0b6ca53..55c8c616d0 100644
--- a/group22/2622819383/Task1/ArrayList.java
+++ b/group22/2622819383/Task1/ArrayList.java
@@ -1,12 +1,12 @@
public class ArrayList implements List {
- private int size;
+ private int size;
private int capacity;
private static final int DEFAULT_CAPACITY = 10;
- private Object[] elementData;
+ private Object[] elementData;
//add()鏃剁敤浜庡湪蹇呰鏃跺埢鎵╁厖搴曞眰鏁扮粍瀹归噺
private void expand() {
@@ -51,29 +51,29 @@ public boolean isEmpty() {
return size == 0;
}
- public void add(Object o){
- add(size(), o);
- }
-
- public void add(int index, Object o){
+ public void add(Object o){
+ add(size(), o);
+ }
+
+ public void add(int index, Object o){
if (index < 0 || size < index)
throw new IndexOutOfBoundsException();
- expand();
+ expand();
for (int i = size; i > index; i--)
elementData[i] = elementData[i - 1];
elementData[index] = o;
size++;
- }
-
- public Object get(int index){
+ }
+
+ public Object get(int index){
if (index < 0 || size <= index)
throw new IndexOutOfBoundsException();
-
+
return elementData[index];
- }
-
- public Object remove(int index){
+ }
+
+ public Object remove(int index){
if (index < 0 || size <= index)
throw new IndexOutOfBoundsException();
@@ -82,15 +82,15 @@ public Object remove(int index){
elementData[i] = elementData[i + 1];
size--;
shrink();
- return removed;
- }
-
-
-
- public Iterator iterator(){
- return new ArrayListIterator();
- }
-
+ return removed;
+ }
+
+
+
+ public Iterator iterator(){
+ return new ArrayListIterator();
+ }
+
private class ArrayListIterator implements Iterator {
private int current;
@@ -105,21 +105,21 @@ public Object next() {
return elementData[current++];
}
}
-
-
+
+
//浠ヤ笅鏂规硶渚夸簬娴嬭瘯
-
+
public ArrayList(Object ...args) {
this();
for (Object o : args)
add(o);
}
-
+
public void add(Object ...args) {
for (Object o : args)
add(o);
}
-
+
public void removeElems(int ...args) {
for (int i : args)
remove(i);
@@ -131,7 +131,7 @@ public static void showElements(ArrayList list) {
System.out.print(iter.next() + " ");
System.out.println();
}
-
+
public static void test(ArrayList list) {
System.out.println("--------鍩烘湰鏂规硶娴嬭瘯---------");
System.out.println("褰撳墠list.isEmpty(): " + list.isEmpty());
@@ -139,7 +139,7 @@ public static void test(ArrayList list) {
System.out.println("褰撳墠list.capacity(): " + list.capacity());
showElements(list);
}
-
+
public static void main(String[] args) {
ArrayList list = new ArrayList(1, 2, 3, 4, 5);
test(list);
From b67c212a381e5a8a669b73c8ca721a6a51b25ef0 Mon Sep 17 00:00:00 2001
From: xxp17457741 <17457741@qq.com>
Date: Sat, 11 Mar 2017 19:40:03 +0800
Subject: [PATCH 033/155] 17457741
---
address.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 address.txt
diff --git a/address.txt b/address.txt
new file mode 100644
index 0000000000..975ea2b26d
--- /dev/null
+++ b/address.txt
@@ -0,0 +1 @@
+ http://www.cnblogs.com/xxp17457741/p/6504673.html
\ No newline at end of file
From 892f436bf02f02df43f92aab723665a23e454615 Mon Sep 17 00:00:00 2001
From: xxp17457741 <17457741@qq.com>
Date: Sat, 11 Mar 2017 19:46:39 +0800
Subject: [PATCH 034/155] 17457741
---
group22/17457741/src/address.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 group22/17457741/src/address.txt
diff --git a/group22/17457741/src/address.txt b/group22/17457741/src/address.txt
new file mode 100644
index 0000000000..975ea2b26d
--- /dev/null
+++ b/group22/17457741/src/address.txt
@@ -0,0 +1 @@
+ http://www.cnblogs.com/xxp17457741/p/6504673.html
\ No newline at end of file
From d19d48ffff0c04569e98553a5a78a457f85324dd Mon Sep 17 00:00:00 2001
From: xxp17457741 <17457741@qq.com>
Date: Sat, 11 Mar 2017 19:47:44 +0800
Subject: [PATCH 035/155] Delete address.txt
---
address.txt | 1 -
1 file changed, 1 deletion(-)
delete mode 100644 address.txt
diff --git a/address.txt b/address.txt
deleted file mode 100644
index 975ea2b26d..0000000000
--- a/address.txt
+++ /dev/null
@@ -1 +0,0 @@
- http://www.cnblogs.com/xxp17457741/p/6504673.html
\ No newline at end of file
From 05f0a9dcc608600e67b50bae9f679ba0b2a799a6 Mon Sep 17 00:00:00 2001
From: laoheihei
Date: Sat, 11 Mar 2017 19:48:05 +0800
Subject: [PATCH 036/155] change Tab
---
group22/2622819383/Task1/Iterator.java | 4 +--
group22/2622819383/Task1/LinkedList.java | 43 ++++++++++++++++++------
group22/2622819383/Task1/List.java | 10 +++---
group22/2622819383/Task1/Queue.java | 30 ++++++++---------
group22/2622819383/Task1/Stack.java | 38 +++++++++++----------
5 files changed, 74 insertions(+), 51 deletions(-)
diff --git a/group22/2622819383/Task1/Iterator.java b/group22/2622819383/Task1/Iterator.java
index 96a43dbe0a..f390e63f3a 100644
--- a/group22/2622819383/Task1/Iterator.java
+++ b/group22/2622819383/Task1/Iterator.java
@@ -1,5 +1,5 @@
public interface Iterator {
- public boolean hasNext();
- public Object next();
+ public boolean hasNext();
+ public Object next();
}
diff --git a/group22/2622819383/Task1/LinkedList.java b/group22/2622819383/Task1/LinkedList.java
index 70ddd5d7a0..d1af15765f 100644
--- a/group22/2622819383/Task1/LinkedList.java
+++ b/group22/2622819383/Task1/LinkedList.java
@@ -1,6 +1,6 @@
public class LinkedList implements List {
- private Node header;
+ private Node header;
private Node trailer;
@@ -12,26 +12,30 @@ public LinkedList() {
header.succ = trailer;
theSize = 0;
}
-
public void add(Object o){
add(size(), o);
}
+
public void add(int index , Object o){
if (index < 0 || theSize < index) throw new IndexOutOfBoundsException();
+
Node p = header;
while (0 < index--) p = p.succ();
p.insertAsSucc(o);
theSize++;
}
+
public Object get(int index){
if (index < 0 || theSize <= index) throw new IndexOutOfBoundsException();
+
Node p = header.succ();
while (0 < index--) p = p.succ();
-
return p.data();
}
+
public Object remove(int index){
if (0 < index || theSize <= index) throw new IndexOutOfBoundsException();
+
Node p = header.succ();
while (0 < index--) p = p.succ();
Object removed = p.data();
@@ -48,23 +52,30 @@ public int size(){
public void addFirst(Object o){
header.insertAsSucc(o);
}
+
public void addLast(Object o){
trailer.insertAsPred(o);
}
+
public Object removeFirst(){
return remove(0);
}
+
public Object removeLast(){
return remove(theSize - 1);
}
+
public Iterator iterator(){
return new LinkedListIterator();
}
+
private class LinkedListIterator implements Iterator {
private Node current = header.succ();
+
public boolean hasNext() {
return current != trailer;
}
+
public Object next() {
if (!hasNext()) throw new java.util.NoSuchElementException();
Object item = current.data();
@@ -77,28 +88,38 @@ private static class Node{
private Object data;
private Node pred;
private Node succ;
+
public Node(Object d, Node p, Node s) {
data = d;
pred = p;
succ = s;
}
- public Object data() { return data; }
- public Node succ() { return succ; }
- public Node pred() { return pred; }
- //插入前驱节点,返回新节点
+
+ public Object data() {
+ return data;
+ }
+
+ public Node succ() {
+ return succ;
+ }
+
+ public Node pred() {
+ return pred;
+ }
+
+ //插入前驱节点,返回插入的新节点
public Node insertAsPred(Object data) {
Node p = new Node(data, pred, this);
pred = pred.succ = p;
return p;
}
+
+ //插入后继节点,返回插入的新节点
public Node insertAsSucc(Object data) {
Node p = new Node(data, this, succ);
succ = succ.pred = p;
return p;
- }
-
-
-
+ }
}
/**
diff --git a/group22/2622819383/Task1/List.java b/group22/2622819383/Task1/List.java
index 4f7bcc71a8..c8f6da95a8 100644
--- a/group22/2622819383/Task1/List.java
+++ b/group22/2622819383/Task1/List.java
@@ -1,7 +1,7 @@
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 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/group22/2622819383/Task1/Queue.java b/group22/2622819383/Task1/Queue.java
index 654a1e3e38..fa916cb089 100644
--- a/group22/2622819383/Task1/Queue.java
+++ b/group22/2622819383/Task1/Queue.java
@@ -1,19 +1,19 @@
public class Queue {
private LinkedList elementData = new LinkedList();
-
- public void enQueue(Object o){
+
+ public void enQueue(Object o){
elementData.addLast(o);
- }
-
- public Object deQueue(){
- return elementData.removeFirst();
- }
-
- public boolean isEmpty(){
- return size() == 0;
- }
-
- public int size(){
- return elementData.size();
- }
+ }
+
+ public Object deQueue(){
+ return elementData.removeFirst();
+ }
+
+ public boolean isEmpty(){
+ return size() == 0;
+ }
+
+ public int size(){
+ return elementData.size();
+ }
}
diff --git a/group22/2622819383/Task1/Stack.java b/group22/2622819383/Task1/Stack.java
index 17a4d0bd0f..3072c65370 100644
--- a/group22/2622819383/Task1/Stack.java
+++ b/group22/2622819383/Task1/Stack.java
@@ -1,21 +1,23 @@
public class Stack {
- private ArrayList elementData = new ArrayList();
-
- public void push(Object o){
+ private ArrayList elementData = new ArrayList();
+
+ 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 size() == 0;
- }
- public int size(){
- return elementData.size();
- }
+ }
+
+ public Object pop(){
+ return elementData.remove(size() - 1);
+ }
+
+ public Object peek(){
+ return elementData.get(size() - 1);
+ }
+
+ public boolean isEmpty(){
+ return size() == 0;
+ }
+
+ public int size(){
+ return elementData.size();
+ }
}
From 6fc5ae0ccfe9d2f3d4862dd808cea4eec35b25ce Mon Sep 17 00:00:00 2001
From: laoheihei
Date: Sat, 11 Mar 2017 20:07:43 +0800
Subject: [PATCH 037/155] change Tab
---
group22/2622819383/Task1/LinkedList.java | 263 ++++++++++++-----------
1 file changed, 132 insertions(+), 131 deletions(-)
diff --git a/group22/2622819383/Task1/LinkedList.java b/group22/2622819383/Task1/LinkedList.java
index d1af15765f..0d87d2d72a 100644
--- a/group22/2622819383/Task1/LinkedList.java
+++ b/group22/2622819383/Task1/LinkedList.java
@@ -12,30 +12,31 @@ public LinkedList() {
header.succ = trailer;
theSize = 0;
}
- public void add(Object o){
- add(size(), o);
- }
- public void add(int index , Object o){
- if (index < 0 || theSize < index) throw new IndexOutOfBoundsException();
-
+ public void add(Object o) {
+ add(size(), o);
+ }
+
+ public void add(int index , Object o) {
+ if (index < 0 || theSize < index) throw new IndexOutOfBoundsException();
+
Node p = header;
while (0 < index--) p = p.succ();
p.insertAsSucc(o);
theSize++;
- }
-
- public Object get(int index){
+ }
+
+ public Object get(int index) {
if (index < 0 || theSize <= index) throw new IndexOutOfBoundsException();
-
- Node p = header.succ();
+
+ Node p = header.succ();
while (0 < index--) p = p.succ();
return p.data();
- }
-
- public Object remove(int index){
- if (0 < index || theSize <= index) throw new IndexOutOfBoundsException();
-
+ }
+
+ public Object remove(int index) {
+ if (0 < index || theSize <= index) throw new IndexOutOfBoundsException();
+
Node p = header.succ();
while (0 < index--) p = p.succ();
Object removed = p.data();
@@ -43,39 +44,39 @@ public Object remove(int index){
p.succ().pred = p.pred();
theSize--;
return removed;
- }
-
- public int size(){
- return theSize;
- }
-
- public void addFirst(Object o){
- header.insertAsSucc(o);
- }
-
- public void addLast(Object o){
- trailer.insertAsPred(o);
- }
-
- public Object removeFirst(){
- return remove(0);
- }
-
- public Object removeLast(){
- return remove(theSize - 1);
- }
-
- public Iterator iterator(){
- return new LinkedListIterator();
- }
-
- private class LinkedListIterator implements Iterator {
+ }
+
+ public int size() {
+ return theSize;
+ }
+
+ public void addFirst(Object o) {
+ header.insertAsSucc(o);
+ }
+
+ public void addLast(Object o) {
+ trailer.insertAsPred(o);
+ }
+
+ public Object removeFirst() {
+ return remove(0);
+ }
+
+ public Object removeLast() {
+ return remove(theSize - 1);
+ }
+
+ public Iterator iterator() {
+ return new LinkedListIterator();
+ }
+
+ private class LinkedListIterator implements Iterator {
private Node current = header.succ();
-
+
public boolean hasNext() {
return current != trailer;
}
-
+
public Object next() {
if (!hasNext()) throw new java.util.NoSuchElementException();
Object item = current.data();
@@ -83,118 +84,118 @@ public Object next() {
return item;
}
}
-
- private static class Node{
- private Object data;
- private Node pred;
+
+ private static class Node {
+ private Object data;
+ private Node pred;
private Node succ;
-
+
public Node(Object d, Node p, Node s) {
data = d;
pred = p;
succ = s;
}
-
+
public Object data() {
return data;
}
-
+
public Node succ() {
return succ;
}
-
+
public Node pred() {
return pred;
}
-
+
//插入前驱节点,返回插入的新节点
public Node insertAsPred(Object data) {
Node p = new Node(data, pred, this);
pred = pred.succ = p;
return p;
}
-
+
//插入后继节点,返回插入的新节点
public Node insertAsSucc(Object data) {
Node p = new Node(data, this, succ);
succ = succ.pred = p;
return p;
}
- }
-
- /**
- * 把该链表逆置
- * 例如链表为 3->7->10 , 逆置后变为 10->7->3
- */
- public void reverse(){
-
- }
-
- /**
- * 删除一个单链表的前半部分
- * 例如:list = 2->5->7->8 , 删除以后的值为 7->8
- * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10
-
- */
- public void removeFirstHalf(){
-
- }
-
- /**
- * 从第i个元素开始, 删除length 个元素 , 注意i从0开始
- * @param i
- * @param length
- */
- public void remove(int i, int length){
-
- }
- /**
- * 假定当前链表和list均包含已升序排列的整数
- * 从当前链表中取出那些list所指定的元素
- * 例如当前链表 = 11->101->201->301->401->501->601->701
- * listB = 1->3->4->6
- * 返回的结果应该是[101,301,401,601]
- * @param list
- */
- public static int[] getElements(LinkedList list){
- return null;
- }
-
- /**
- * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。
- * 从当前链表中中删除在list中出现的元素
+ }
- * @param list
- */
-
- public void subtract(LinkedList list){
-
- }
-
- /**
- * 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。
- * 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同)
- */
- public void removeDuplicateValues(){
-
- }
-
- /**
- * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。
- * 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素)
- * @param min
- * @param max
- */
- public void removeRange(int min, int max){
-
- }
-
- /**
- * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同)
- * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列
- * @param list
- */
- public LinkedList intersection( LinkedList list){
- return null;
- }
+ /**
+ * 把该链表逆置
+ * 例如链表为 3->7->10 , 逆置后变为 10->7->3
+ */
+ public void reverse(){
+
+ }
+
+ /**
+ * 删除一个单链表的前半部分
+ * 例如:list = 2->5->7->8 , 删除以后的值为 7->8
+ * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10
+
+ */
+ public void removeFirstHalf(){
+
+ }
+
+ /**
+ * 从第i个元素开始, 删除length 个元素 , 注意i从0开始
+ * @param i
+ * @param length
+ */
+ public void remove(int i, int length){
+
+ }
+ /**
+ * 假定当前链表和list均包含已升序排列的整数
+ * 从当前链表中取出那些list所指定的元素
+ * 例如当前链表 = 11->101->201->301->401->501->601->701
+ * listB = 1->3->4->6
+ * 返回的结果应该是[101,301,401,601]
+ * @param list
+ */
+ public static int[] getElements(LinkedList list){
+ return null;
+ }
+
+ /**
+ * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。
+ * 从当前链表中中删除在list中出现的元素
+
+ * @param list
+ */
+
+ public void subtract(LinkedList list){
+
+ }
+
+ /**
+ * 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。
+ * 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同)
+ */
+ public void removeDuplicateValues(){
+
+ }
+
+ /**
+ * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。
+ * 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素)
+ * @param min
+ * @param max
+ */
+ public void removeRange(int min, int max){
+
+ }
+
+ /**
+ * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同)
+ * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列
+ * @param list
+ */
+ public LinkedList intersection( LinkedList list){
+ return null;
+ }
}
From 6f45e392fe43e5a043cd976034ec706eacf66056 Mon Sep 17 00:00:00 2001
From: xiongrui233
Date: Sat, 11 Mar 2017 20:17:26 +0800
Subject: [PATCH 038/155] complete simple queue
---
group22/.gitignore | 1 +
group22/627559964/src/com/coding/basic/Queue.java | 13 +++++++++----
2 files changed, 10 insertions(+), 4 deletions(-)
create mode 100644 group22/.gitignore
diff --git a/group22/.gitignore b/group22/.gitignore
new file mode 100644
index 0000000000..d1945e125c
--- /dev/null
+++ b/group22/.gitignore
@@ -0,0 +1 @@
+/627559964/
diff --git a/group22/627559964/src/com/coding/basic/Queue.java b/group22/627559964/src/com/coding/basic/Queue.java
index 90f845e6cd..965894a9ea 100644
--- a/group22/627559964/src/com/coding/basic/Queue.java
+++ b/group22/627559964/src/com/coding/basic/Queue.java
@@ -8,23 +8,28 @@
*/
public class Queue {
- private Object[] queue = new Object[10];
+ private LinkedList elements = new LinkedList();;
private int size = 0;
public void enQueue(Object o) {
-
+ elements.add(o);
+ size ++;
}
public Object deQueue() {
- return null;
+ size --;
+ return elements.removeLast();
}
public boolean isEmpty() {
+ if (size == 0) {
+ return true;
+ }
return false;
}
public int size() {
- return -1;
+ return size;
}
}
\ No newline at end of file
From 5ad297828ae916ee3c50eccbfcb6c69341af2890 Mon Sep 17 00:00:00 2001
From: xiongrui233
Date: Sat, 11 Mar 2017 20:20:32 +0800
Subject: [PATCH 039/155] delete .classpath .project
---
group22/627559964/.gitignore | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/group22/627559964/.gitignore b/group22/627559964/.gitignore
index 3727029200..6ef2139e00 100644
--- a/group22/627559964/.gitignore
+++ b/group22/627559964/.gitignore
@@ -1,2 +1,4 @@
/bin/
-.metadata
\ No newline at end of file
+.metadatas
+.classpath
+.project
\ No newline at end of file
From df1b1fe9a3236a754a587674a8ac2d489ea3d93d Mon Sep 17 00:00:00 2001
From: xiongrui233
Date: Sat, 11 Mar 2017 20:22:27 +0800
Subject: [PATCH 040/155] delete ignore file
---
group22/627559964/.classpath | 8 --------
group22/627559964/.gitignore | 4 ----
group22/627559964/.project | 17 -----------------
3 files changed, 29 deletions(-)
delete mode 100644 group22/627559964/.classpath
delete mode 100644 group22/627559964/.gitignore
delete mode 100644 group22/627559964/.project
diff --git a/group22/627559964/.classpath b/group22/627559964/.classpath
deleted file mode 100644
index e72ef7c0d4..0000000000
--- a/group22/627559964/.classpath
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/group22/627559964/.gitignore b/group22/627559964/.gitignore
deleted file mode 100644
index 6ef2139e00..0000000000
--- a/group22/627559964/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-/bin/
-.metadatas
-.classpath
-.project
\ No newline at end of file
diff --git a/group22/627559964/.project b/group22/627559964/.project
deleted file mode 100644
index 870f65f4a0..0000000000
--- a/group22/627559964/.project
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
- 627559964
-
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
-
- org.eclipse.jdt.core.javanature
-
-
From 9af937c194a2d0dfc73dfb7578fc81b31140124b Mon Sep 17 00:00:00 2001
From: laoheihei
Date: Sat, 11 Mar 2017 22:26:27 +0800
Subject: [PATCH 041/155] no test
---
group22/2622819383/Task1/ArrayList.java | 1 +
group22/2622819383/Task1/BinaryTreeNode.java | 78 +++++++++++++-------
group22/2622819383/Task1/LinkedList.java | 6 +-
3 files changed, 56 insertions(+), 29 deletions(-)
diff --git a/group22/2622819383/Task1/ArrayList.java b/group22/2622819383/Task1/ArrayList.java
index 55c8c616d0..d438fba17d 100644
--- a/group22/2622819383/Task1/ArrayList.java
+++ b/group22/2622819383/Task1/ArrayList.java
@@ -1,3 +1,4 @@
+//浠g爜鍙傝冭嚜銆婃暟鎹粨鏋勪笌绠楁硶鍒嗘瀽銆
public class ArrayList implements List {
private int size;
diff --git a/group22/2622819383/Task1/BinaryTreeNode.java b/group22/2622819383/Task1/BinaryTreeNode.java
index 1f07869939..8c2b4492d2 100644
--- a/group22/2622819383/Task1/BinaryTreeNode.java
+++ b/group22/2622819383/Task1/BinaryTreeNode.java
@@ -1,30 +1,54 @@
+//代码参考自《数据结构与算法分析》
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;
- }
-
+ 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;
+ }
+
+ private BinaryTreeNode parrent;
+ private BinaryTreeNode hot; //表示search(Object o)方法返回的命中节点的父亲
+
+ public BinaryTreeNode(Object o, BinaryTreeNode p) {
+ data = o;
+ parrent = p;
+ }
+ //在以v为根的二叉树中查找关键码o,返回命中的节点(真实存在得或者虚拟存在的)
+ public static BinaryTreeNode search(BinaryTreeNode v, Object o, BinaryTreeNode hot) {
+ int vData = (int)v.getData();
+ int searched = (int)o;
+ if (v == null || vData == searched) return v;
+
+ hot = v;
+ return search(searched < vData ? v.getLeft() : v.getRight(), o, hot);
+ }
+
+ public BinaryTreeNode insert(Object o){
+ BinaryTreeNode node = search(this, o, this.parrent);
+ if (node != null) return node;
+
+ node = new BinaryTreeNode(o, hot);
+ if ((int)o < (int)hot.getData()) hot.setLeft(node);
+ else hot.setRight(node);
+ return node;
+ }
+
}
diff --git a/group22/2622819383/Task1/LinkedList.java b/group22/2622819383/Task1/LinkedList.java
index 0d87d2d72a..81c1db409c 100644
--- a/group22/2622819383/Task1/LinkedList.java
+++ b/group22/2622819383/Task1/LinkedList.java
@@ -1,3 +1,4 @@
+//代码参考自《数据结构与算法分析》
public class LinkedList implements List {
private Node header;
@@ -86,6 +87,7 @@ public Object next() {
}
private static class Node {
+ //pred、succ代表属性;pred()、succ()代表Node节点
private Object data;
private Node pred;
private Node succ;
@@ -111,14 +113,14 @@ public Node pred() {
//插入前驱节点,返回插入的新节点
public Node insertAsPred(Object data) {
Node p = new Node(data, pred, this);
- pred = pred.succ = p;
+ pred = pred().succ = p;
return p;
}
//插入后继节点,返回插入的新节点
public Node insertAsSucc(Object data) {
Node p = new Node(data, this, succ);
- succ = succ.pred = p;
+ succ = succ().pred = p;
return p;
}
}
From 7d13bef6e864b63b1f9beac119905865146ede7c Mon Sep 17 00:00:00 2001
From: wenGQ
Date: Sat, 11 Mar 2017 22:54:12 +0800
Subject: [PATCH 042/155] =?UTF-8?q?=E6=9B=B4=E6=96=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../com/github/mrwengq/first/ArrayList.java | 104 ++++++++
.../github/mrwengq/first/BinaryTreeNode.java | 77 ++++++
.../com/github/mrwengq/first/Iterator.java | 10 +
.../com/github/mrwengq/first/LinkedList.java | 244 ++++++++++++++++++
.../src/com/github/mrwengq/first/List.java | 16 ++
.../src/com/github/mrwengq/first/Queue.java | 29 +++
.../src/com/github/mrwengq/first/Stack.java | 40 +++
7 files changed, 520 insertions(+)
create mode 100644 group22/1193590951/githubitem/src/com/github/mrwengq/first/ArrayList.java
create mode 100644 group22/1193590951/githubitem/src/com/github/mrwengq/first/BinaryTreeNode.java
create mode 100644 group22/1193590951/githubitem/src/com/github/mrwengq/first/Iterator.java
create mode 100644 group22/1193590951/githubitem/src/com/github/mrwengq/first/LinkedList.java
create mode 100644 group22/1193590951/githubitem/src/com/github/mrwengq/first/List.java
create mode 100644 group22/1193590951/githubitem/src/com/github/mrwengq/first/Queue.java
create mode 100644 group22/1193590951/githubitem/src/com/github/mrwengq/first/Stack.java
diff --git a/group22/1193590951/githubitem/src/com/github/mrwengq/first/ArrayList.java b/group22/1193590951/githubitem/src/com/github/mrwengq/first/ArrayList.java
new file mode 100644
index 0000000000..f627f38abb
--- /dev/null
+++ b/group22/1193590951/githubitem/src/com/github/mrwengq/first/ArrayList.java
@@ -0,0 +1,104 @@
+package com.github.mrwengq.first;
+
+public class ArrayList implements List {
+
+ private int size = 0;
+ private Object elementData[] = new Object[5];
+
+ public void add(Object o) {
+ if (size >= elementData.length)
+ elementData = copyAddArray(elementData);
+ elementData[size] = o;
+ size++;
+ }
+
+ public void add(int index, Object o) {
+ if (index > size - 1 || index < 0) {
+ throw new ArrayIndexOutOfBoundsException();
+ } else {
+ elementData = addUpdateArray(elementData, index);
+ elementData[index] = o;
+ size++;
+ return;
+ }
+ }
+
+ public Object get(int index) {
+ if (index > size - 1 || index < 0)
+ throw new ArrayIndexOutOfBoundsException();
+ else
+ return elementData[index];
+ }
+
+ public Object remove(int index) {
+ if (index > size - 1 || index < 0)
+ throw new ArrayIndexOutOfBoundsException();
+ if (index == size - 1) {
+ elementData[index] = null;
+ size--;
+ return null;
+ } else {
+ delUpdateArray(elementData, index);
+ size--;
+ return null;
+ }
+ }
+
+ public int size() {
+ return size;
+ }
+
+ public Iterator iterator() {
+ return new Iterator() {
+
+ int index;
+
+ public boolean hasNext() {
+ index++;
+ Object ob = elementData[index];
+ return ob != null;
+ }
+
+ public Object next() {
+ return elementData[index];
+ }
+
+ };
+ }
+
+ private Object[] copyAddArray(Object elementData[]) {
+ Object ob[] = new Object[(elementData.length * 3) / 4];
+ System.arraycopy(((Object) (elementData)), 0, ((Object) (ob)), 0,
+ elementData.length);
+ return ob;
+ }
+
+ private Object[] addUpdateArray(Object elementData[], int index) {
+ Object temp = null;
+ for (int i = 0; i < size; i++)
+ if (i > index) {
+ temp = elementData[index];
+ elementData[index] = elementData[i];
+ elementData[i] = temp;
+ if (i == size - 1) {
+ if (size > elementData.length)
+ elementData = copyAddArray(elementData);
+ elementData[size] = elementData[index];
+ }
+ }
+
+ return elementData;
+ }
+
+ private void delUpdateArray(Object elementData[], int index) {
+ Object temp = null;
+ for (int i = 0; i < size; i++)
+ if (i > index && i < size - 1)
+ elementData[i - 1] = elementData[i];
+ else if (i == size - 1)
+ elementData[i] = null;
+
+ }
+
+
+}
diff --git a/group22/1193590951/githubitem/src/com/github/mrwengq/first/BinaryTreeNode.java b/group22/1193590951/githubitem/src/com/github/mrwengq/first/BinaryTreeNode.java
new file mode 100644
index 0000000000..37bc363cdb
--- /dev/null
+++ b/group22/1193590951/githubitem/src/com/github/mrwengq/first/BinaryTreeNode.java
@@ -0,0 +1,77 @@
+package com.github.mrwengq.first;
+
+import java.util.Comparator;
+
+public class BinaryTreeNode {
+
+ private Object data;
+ private BinaryTreeNode left;
+ private BinaryTreeNode right;
+ private Comparator cpt;
+ public BinaryTreeNode() {
+ cpt = new Comparator() {
+
+ public int compare(Object o1, Object o2) {
+ int ob1 = ((Integer) o1).intValue();
+ int ob2 = ((Integer) o2).intValue();
+ if (ob1 > ob2){
+ return 1;
+ }
+ if(ob1 0) {
+ if (getLeft() == null) {
+ this.setLeft(tree);
+ return null;
+ }
+ left.insert(o);
+ } else if (comValue < 0) {
+ if (getRight() == null) {
+ this.setRight(tree);
+ return null;
+ }
+ right.insert(o);
+ }
+ return null;
+ }
+
+}
diff --git a/group22/1193590951/githubitem/src/com/github/mrwengq/first/Iterator.java b/group22/1193590951/githubitem/src/com/github/mrwengq/first/Iterator.java
new file mode 100644
index 0000000000..2947813ffd
--- /dev/null
+++ b/group22/1193590951/githubitem/src/com/github/mrwengq/first/Iterator.java
@@ -0,0 +1,10 @@
+package com.github.mrwengq.first;
+
+
+public interface Iterator
+{
+
+ public abstract boolean hasNext();
+
+ public abstract Object next();
+}
diff --git a/group22/1193590951/githubitem/src/com/github/mrwengq/first/LinkedList.java b/group22/1193590951/githubitem/src/com/github/mrwengq/first/LinkedList.java
new file mode 100644
index 0000000000..a8ef6f6413
--- /dev/null
+++ b/group22/1193590951/githubitem/src/com/github/mrwengq/first/LinkedList.java
@@ -0,0 +1,244 @@
+package com.github.mrwengq.first;
+
+public class LinkedList implements List {
+ private Node head;
+ private int size =0;
+ private static class Node {
+
+ Object data;
+ Node next;
+
+ public Node(Object o) {
+ data = o;
+ next = null;
+ }
+ }
+
+
+ public void add(Object o) {
+ if (size == 0) {
+ head = new Node(o);
+ } else {
+ Node node = new Node(o);
+ Node lastNode = findNode(size);
+ lastNode.next = node;
+ }
+ size++;
+ }
+
+ private Node findNode(int index) {
+ Node no = head;
+ for (; index - 1 > 0; index--)
+ no = no.next;
+
+ return no;
+ }
+
+ public void add(int index, Object o) {
+ if (index < 0 || index > size - 1)
+ throw new ArrayIndexOutOfBoundsException();
+ Node node = new Node(o);
+ Node indexNode = findNode(index);
+ if (index - 1 < 0) {
+ node.next = indexNode;
+ head = node;
+ size++;
+ return;
+ } else {
+ Node lastNode = findNode(index - 1);
+ lastNode.next = node;
+ node.next = indexNode;
+ size++;
+ return;
+ }
+ }
+
+ public Object get(int index) {
+ if (index < 0 || index > size - 1)
+ throw new ArrayIndexOutOfBoundsException();
+ else
+ return findNode(index).data;
+ }
+
+ public Object remove(int index) {
+ if (index < 0 || index > size - 1 || size == 0)
+ throw new ArrayIndexOutOfBoundsException();
+ Node indexNode = findNode(index);
+ if (size == 1) {
+ head = null;
+ size = 0;
+ return indexNode.data;
+ }
+ Node nextNode = null;
+ Node lastNode = null;
+ if (index + 1 < size - 1)
+ nextNode = findNode(index + 1);
+ if (index - 1 > 0)
+ lastNode = findNode(index - 1);
+ if (lastNode == null) {
+ head = nextNode;
+ size--;
+ return indexNode.data;
+ }
+ if (nextNode == null) {
+ lastNode.next = null;
+ size--;
+ return indexNode.data;
+ } else {
+ lastNode.next = nextNode;
+ size--;
+ return indexNode.data;
+ }
+ }
+
+ public int size() {
+ return size;
+ }
+
+ public void addFirst(Object o) {
+ Node node = new Node(o);
+ if (size == 0) {
+ head = node;
+ size++;
+ return;
+ } else {
+ node.next = head;
+ head = node;
+ size++;
+ return;
+ }
+ }
+
+ public void addLast(Object o) {
+ Node node = new Node(o);
+ if (size == 0) {
+ head = node;
+ size++;
+ return;
+ } else {
+ Node lastNode = findNode(size);
+ lastNode.next = node;
+ size++;
+ return;
+ }
+ }
+
+ public Object removeFirst() {
+ if (size == 0) {
+ return null;
+ } else {
+ Node nextNode = head.next;
+ Object ob = head.data;
+ head = nextNode;
+ size--;
+ return ob;
+ }
+ }
+
+ public Object removeLast() {
+ if (size == 0) {
+ return null;
+ } else {
+ Node node = findNode(size);
+ Node lastNode = findNode(size - 1);
+ lastNode.next = null;
+ size--;
+ return node.data;
+ }
+ }
+
+ public Iterator iterator() {
+ return new Iterator() {
+
+ int index = -1;
+
+ public boolean hasNext() {
+ index++;
+ return findNode(index) != null;
+ }
+
+ public Object next() {
+ return findNode(index).data;
+ }
+
+
+ };
+ }
+
+ /**
+ * 鎶婅閾捐〃閫嗙疆
+ * 渚嬪閾捐〃涓 3->7->10 , 閫嗙疆鍚庡彉涓 10->7->3
+ */
+ public void reverse(){
+
+ }
+
+ /**
+ * 鍒犻櫎涓涓崟閾捐〃鐨勫墠鍗婇儴鍒
+ * 渚嬪锛歭ist = 2->5->7->8 , 鍒犻櫎浠ュ悗鐨勫间负 7->8
+ * 濡傛灉list = 2->5->7->8->10 ,鍒犻櫎浠ュ悗鐨勫间负7,8,10
+
+ */
+ public void removeFirstHalf(){
+
+ }
+
+ /**
+ * 浠庣i涓厓绱犲紑濮嬶紝 鍒犻櫎length 涓厓绱 锛 娉ㄦ剰i浠0寮濮
+ * @param i
+ * @param length
+ */
+ public void remove(int i, int length){
+
+ }
+ /**
+ * 鍋囧畾褰撳墠閾捐〃鍜宭ist鍧囧寘鍚凡鍗囧簭鎺掑垪鐨勬暣鏁
+ * 浠庡綋鍓嶉摼琛ㄤ腑鍙栧嚭閭d簺list鎵鎸囧畾鐨勫厓绱
+ * 渚嬪褰撳墠閾捐〃 = 11->101->201->301->401->501->601->701
+ * listB = 1->3->4->6
+ * 杩斿洖鐨勭粨鏋滃簲璇ユ槸[101,301,401,601]
+ * @param list
+ */
+ public static int[] getElements(LinkedList list){
+ return null;
+ }
+
+ /**
+ * 宸茬煡閾捐〃涓殑鍏冪礌浠ュ奸掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩
+ * 浠庡綋鍓嶉摼琛ㄤ腑涓垹闄ゅ湪list涓嚭鐜扮殑鍏冪礌
+
+ * @param list
+ */
+
+ public void subtract(LinkedList list){
+
+ }
+
+ /**
+ * 宸茬煡褰撳墠閾捐〃涓殑鍏冪礌浠ュ奸掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩
+ * 鍒犻櫎琛ㄤ腑鎵鏈夊肩浉鍚岀殑澶氫綑鍏冪礌锛堜娇寰楁搷浣滃悗鐨勭嚎鎬ц〃涓墍鏈夊厓绱犵殑鍊煎潎涓嶇浉鍚岋級
+ */
+ public void removeDuplicateValues(){
+
+ }
+
+ /**
+ * 宸茬煡閾捐〃涓殑鍏冪礌浠ュ奸掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩
+ * 璇曞啓涓楂樻晥鐨勭畻娉曪紝鍒犻櫎琛ㄤ腑鎵鏈夊煎ぇ浜巑in涓斿皬浜巑ax鐨勫厓绱狅紙鑻ヨ〃涓瓨鍦ㄨ繖鏍风殑鍏冪礌锛
+ * @param min
+ * @param max
+ */
+ public void removeRange(int min, int max){
+
+ }
+
+ /**
+ * 鍋囪褰撳墠閾捐〃鍜屽弬鏁發ist鎸囧畾鐨勯摼琛ㄥ潎浠ュ厓绱犱緷鍊奸掑鏈夊簭鎺掑垪锛堝悓涓琛ㄤ腑鐨勫厓绱犲煎悇涓嶇浉鍚岋級
+ * 鐜拌姹傜敓鎴愭柊閾捐〃C锛屽叾鍏冪礌涓哄綋鍓嶉摼琛ㄥ拰list涓厓绱犵殑浜ら泦锛屼笖琛–涓殑鍏冪礌鏈変緷鍊奸掑鏈夊簭鎺掑垪
+ * @param list
+ */
+ public LinkedList intersection( LinkedList list){
+ return null;
+ }
+
+}
diff --git a/group22/1193590951/githubitem/src/com/github/mrwengq/first/List.java b/group22/1193590951/githubitem/src/com/github/mrwengq/first/List.java
new file mode 100644
index 0000000000..d36d04b8b6
--- /dev/null
+++ b/group22/1193590951/githubitem/src/com/github/mrwengq/first/List.java
@@ -0,0 +1,16 @@
+package com.github.mrwengq.first;
+
+
+public interface List
+{
+
+ public abstract void add(Object obj);
+
+ public abstract void add(int i, Object obj);
+
+ public abstract Object get(int i);
+
+ public abstract Object remove(int i);
+
+ public abstract int size();
+}
diff --git a/group22/1193590951/githubitem/src/com/github/mrwengq/first/Queue.java b/group22/1193590951/githubitem/src/com/github/mrwengq/first/Queue.java
new file mode 100644
index 0000000000..004ac39e6b
--- /dev/null
+++ b/group22/1193590951/githubitem/src/com/github/mrwengq/first/Queue.java
@@ -0,0 +1,29 @@
+package com.github.mrwengq.first;
+
+public class Queue {
+
+ private ArrayList elementData;
+ public Queue() {
+ elementData = new ArrayList();
+ }
+
+ public void enQueue(Object o) {
+ elementData.add(o);
+ }
+
+ public Object deQueue() {
+ Object ob = null;
+ ob = elementData.get(0);
+ elementData.remove(0);
+ return ob;
+ }
+
+ public boolean isEmpty() {
+ return elementData.size() == 0;
+ }
+
+ public int size() {
+ return elementData.size();
+ }
+
+}
diff --git a/group22/1193590951/githubitem/src/com/github/mrwengq/first/Stack.java b/group22/1193590951/githubitem/src/com/github/mrwengq/first/Stack.java
new file mode 100644
index 0000000000..f0614a13df
--- /dev/null
+++ b/group22/1193590951/githubitem/src/com/github/mrwengq/first/Stack.java
@@ -0,0 +1,40 @@
+package com.github.mrwengq.first;
+
+public class Stack {
+
+
+ private ArrayList elementData;
+ public Stack() {
+ elementData = new ArrayList();
+ }
+
+ public void push(Object o) {
+ elementData.add(o);
+ }
+
+ public Object pop() {
+ if (elementData.size() == 0) {
+ return null;
+ } else {
+ Object ob = null;
+ ob = elementData.get(elementData.size() - 1);
+ elementData.remove(elementData.size() - 1);
+ return ob;
+ }
+ }
+
+ public Object peek() {
+ if (elementData.size() == 0)
+ return null;
+ else
+ return elementData.get(elementData.size() - 1);
+ }
+
+ public boolean isEmpty() {
+ return elementData.size() == 0;
+ }
+
+ public int size() {
+ return elementData.size();
+ }
+}
From 9e1a6ebeccad0fd3bfc8059c48b7b0d589ce3f7c Mon Sep 17 00:00:00 2001
From: 240094626
Date: Sun, 12 Mar 2017 11:36:08 +0800
Subject: [PATCH 043/155] 240094626-work0305-linkedlist
---
.../com/coderising/linkedlist/Iterator.java | 8 +
.../com/coderising/linkedlist/LinkedList.java | 293 ++++++++++++++++++
.../coderising/linkedlist/LinkedListTest.java | 163 ++++++++++
.../src/com/coderising/linkedlist/List.java | 9 +
.../coderising/linkedlist/SLinkedList.java | 119 +++++++
5 files changed, 592 insertions(+)
create mode 100644 group17/240094626/work_0305/src/com/coderising/linkedlist/Iterator.java
create mode 100644 group17/240094626/work_0305/src/com/coderising/linkedlist/LinkedList.java
create mode 100644 group17/240094626/work_0305/src/com/coderising/linkedlist/LinkedListTest.java
create mode 100644 group17/240094626/work_0305/src/com/coderising/linkedlist/List.java
create mode 100644 group17/240094626/work_0305/src/com/coderising/linkedlist/SLinkedList.java
diff --git a/group17/240094626/work_0305/src/com/coderising/linkedlist/Iterator.java b/group17/240094626/work_0305/src/com/coderising/linkedlist/Iterator.java
new file mode 100644
index 0000000000..30ea750ecc
--- /dev/null
+++ b/group17/240094626/work_0305/src/com/coderising/linkedlist/Iterator.java
@@ -0,0 +1,8 @@
+package com.coderising.linkedlist;
+
+public interface Iterator {
+
+ public boolean hasNext();
+
+ public E next();
+}
diff --git a/group17/240094626/work_0305/src/com/coderising/linkedlist/LinkedList.java b/group17/240094626/work_0305/src/com/coderising/linkedlist/LinkedList.java
new file mode 100644
index 0000000000..feddaedd23
--- /dev/null
+++ b/group17/240094626/work_0305/src/com/coderising/linkedlist/LinkedList.java
@@ -0,0 +1,293 @@
+package com.coderising.linkedlist;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class LinkedList implements List {
+
+ transient Node head;
+ transient int size;
+
+ public LinkedList(){
+ head = new Node(null,head);
+ size = 0;
+ }
+ public void addFirst(E e){
+ head.next = new Node(e,head.next);
+ size++;
+ }
+
+
+ public void addAfter(Node n, E e){
+ if(n == head){
+ addFirst(e);
+ }else{
+ Node curr = new Node(e,n.next);
+ n.next = curr;
+ size++;
+ }
+ }
+
+
+ private void checkRange(int index){
+ if(index < 0 || index >= size){
+ throw new IndexOutOfBoundsException("Index:"+index+",Size:"+size);
+ }
+ }
+
+ private Node getNode(int index){
+ checkRange(index);
+ Node curr = head;
+ for(; index >= 0 ; index--){
+ curr = curr.next;
+ }
+ return curr;
+ }
+
+ public void add(E e) {
+ add(size,e);
+ }
+
+ public void add(int index, E e) {
+ if(index < 0 || index > size){
+ throw new IndexOutOfBoundsException("Index:"+index+",Size:"+size);
+ }
+ if(index == 0){
+ addFirst(e);
+ }else{
+ addAfter(getNode(index-1), e);
+ }
+ }
+
+ public E get(int index) {
+ Node n = getNode(index);
+ return n.e;
+ }
+
+
+ public E remove(int index) {
+ checkRange(index);
+ Node preN = null,
+ currN = null;
+ if(index == 0){
+ preN = head;
+ }else{
+ preN = getNode(index-1);
+ }
+ currN = preN.next;
+ preN.next = currN.next;
+ E e = currN.e;
+ currN.e = null;
+ currN.next = null;
+ size--;
+ return e;
+
+ }
+
+ public int size() {
+ return size;
+ }
+
+
+ private static class Node{
+ E e ;
+ Node next;
+
+ public Node(E e,Node next){
+ this.e = e;
+ this.next = next;
+ }
+ }
+
+ private Iterator iterator(){
+ return new LinkedListIterator();
+ }
+
+ private class LinkedListIterator implements Iterator{
+
+ int index;
+ public LinkedListIterator(){
+ index = 0;
+ }
+
+ @Override
+ public boolean hasNext() {
+ if(index < size){
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public E next() {
+ Node curr = (Node) getNode(index++);
+ return curr.e;
+ }
+
+ }
+
+
+ /**
+ * 鎶婅閾捐〃閫嗙疆
+ * 渚嬪閾捐〃涓 3->7->10 , 閫嗙疆鍚庡彉涓 10->7->3
+ */
+ public void reverse(){
+ if(size > 1){
+ int index = 0;
+ Node a = null,
+ preA = null,
+ b = null,
+ preB = null;
+ for(;index < size/2; index++){
+ if(index == 0){
+ preA = head;
+ a = head.next;
+ b = getNode(size-1);
+ preB = getNode(size-2);
+
+ head.next = b;
+ preB.next = a;
+ b.next = a.next;
+ a.next = head;
+ }else{
+ preA = getNode(index-1);
+ a = preA.next;
+ preB = getNode(size-2-index);
+ b = preB.next;
+
+ preA.next = b;
+ preB.next = a;
+ Node tmp = a.next;
+ a.next = b.next;
+ b.next = tmp;
+ }
+
+ }
+ }
+ }
+
+ /**
+ * 鍒犻櫎涓涓崟閾捐〃鐨勫墠鍗婇儴鍒
+ * 渚嬪锛歭ist = 2->5->7->8 , 鍒犻櫎浠ュ悗鐨勫间负 7->8
+ * 濡傛灉list = 2->5->7->8->10 ,鍒犻櫎浠ュ悗鐨勫间负7,8,10
+
+ */
+ public void removeFirstHalf(){
+ remove(0, size/2);
+ }
+
+ /**
+ * 浠庣i涓厓绱犲紑濮嬶紝 鍒犻櫎length 涓厓绱 锛 娉ㄦ剰i浠0寮濮
+ * @param i
+ * @param length
+ */
+ public void remove(int i, int length){
+ while(length > 0){
+ remove(i);
+ length--;
+ }
+ }
+ /**
+ * 鍋囧畾褰撳墠閾捐〃鍜宭ist鍧囧寘鍚凡鍗囧簭鎺掑垪鐨勬暣鏁
+ * 浠庡綋鍓嶉摼琛ㄤ腑鍙栧嚭閭d簺list鎵鎸囧畾鐨勫厓绱
+ * 渚嬪褰撳墠閾捐〃 = 11->101->201->301->401->501->601->701
+ * listB = 1->3->4->6
+ * 杩斿洖鐨勭粨鏋滃簲璇ユ槸[101,301,401,601]
+ * @param list
+ */
+ public int[] getElements(LinkedList list){
+ int[] a = new int[list.size];
+ for(int i = 0; i < list.size; i++){
+ Node curr = getNode((int)list.get(i));
+ a[i] = (int) curr.e;
+ }
+ return a;
+ }
+
+ /**
+ * 宸茬煡閾捐〃涓殑鍏冪礌浠ュ奸掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩
+ * 浠庡綋鍓嶉摼琛ㄤ腑涓垹闄ゅ湪list涓嚭鐜扮殑鍏冪礌
+ * @param list
+ */
+
+ public void subtract(LinkedList list){
+ int i = 0,
+ j = 0;
+ for(; i < list.size; i++){
+ E a = (E) list.get(i);
+ while(j < size){
+ E b = get(j);
+ if(a.equals(b)){
+ remove(j);
+ break;
+ }
+ j++;
+ }
+ }
+ }
+
+ /**
+ * 宸茬煡褰撳墠閾捐〃涓殑鍏冪礌浠ュ奸掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩
+ * 鍒犻櫎琛ㄤ腑鎵鏈夊肩浉鍚岀殑澶氫綑鍏冪礌锛堜娇寰楁搷浣滃悗鐨勭嚎鎬ц〃涓墍鏈夊厓绱犵殑鍊煎潎涓嶇浉鍚岋級
+ */
+ public void removeDuplicateValues(){
+ Map map = new HashMap(size);
+ for(int i = 0; i < size; ){
+ if(map.get(getNode(i).e) == null){
+ map.put(getNode(i).e, i);
+ i++;
+ }else{
+ remove(i);
+ }
+ }
+ }
+
+ /**
+ * 宸茬煡閾捐〃涓殑鍏冪礌浠ュ奸掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩
+ * 璇曞啓涓楂樻晥鐨勭畻娉曪紝鍒犻櫎琛ㄤ腑鎵鏈夊煎ぇ浜巑in涓斿皬浜巑ax鐨勫厓绱狅紙鑻ヨ〃涓瓨鍦ㄨ繖鏍风殑鍏冪礌锛
+ * @param min
+ * @param max
+ */
+ public void removeRange(int min, int max){
+ if(min >= max){
+ return ;
+ }
+ for(int i = 0; i < size; ){
+ int a = (int)get(i);
+ if(min < a && max > a){
+ remove(i);
+ continue;
+ }
+ i++;
+ }
+ }
+
+ /**
+ * 鍋囪褰撳墠閾捐〃鍜屽弬鏁發ist鎸囧畾鐨勯摼琛ㄥ潎浠ュ厓绱犱緷鍊奸掑鏈夊簭鎺掑垪锛堝悓涓琛ㄤ腑鐨勫厓绱犲煎悇涓嶇浉鍚岋級
+ * 鐜拌姹傜敓鎴愭柊閾捐〃C锛屽叾鍏冪礌涓哄綋鍓嶉摼琛ㄥ拰list涓厓绱犵殑浜ら泦锛屼笖琛–涓殑鍏冪礌鏈変緷鍊奸掑鏈夊簭鎺掑垪
+ * @param list
+ */
+ public LinkedList intersection( LinkedList list){
+ LinkedList c = new LinkedList();
+ if(list.size == 0){
+ return c;
+ }
+ Map map = new HashMap();
+ for(int i = 0; i < list.size; i++){
+ E a = list.get(i);
+ if(null == map.get(a)){
+ map.put(a, true);
+ }
+ }
+ for(int i = 0; i < size; i++){
+ E a = get(i);
+ if(null == map.get(a)){
+ map.put(a, true);
+ }else if(map.get(a)){
+ c.add(get(i));
+ }
+ }
+
+ return c;
+ }
+}
diff --git a/group17/240094626/work_0305/src/com/coderising/linkedlist/LinkedListTest.java b/group17/240094626/work_0305/src/com/coderising/linkedlist/LinkedListTest.java
new file mode 100644
index 0000000000..b245851f2a
--- /dev/null
+++ b/group17/240094626/work_0305/src/com/coderising/linkedlist/LinkedListTest.java
@@ -0,0 +1,163 @@
+package com.coderising.linkedlist;
+
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class LinkedListTest {
+ LinkedList