From a459047b8944ac86dc9ceea93c644a598e6f6615 Mon Sep 17 00:00:00 2001
From: chishiwu <1107225491@qq.com>
Date: Tue, 7 Mar 2017 15:51:56 +0800
Subject: [PATCH 01/26] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E6=B5=8B?=
=?UTF-8?q?=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
group24/1107225491/1107225491/.classpath | 6 ++++++
group24/1107225491/1107225491/.project | 17 +++++++++++++++++
.../.settings/org.eclipse.jdt.core.prefs | 11 +++++++++++
group24/1107225491/1107225491/test.txt | 1 +
4 files changed, 35 insertions(+)
create mode 100644 group24/1107225491/1107225491/.classpath
create mode 100644 group24/1107225491/1107225491/.project
create mode 100644 group24/1107225491/1107225491/.settings/org.eclipse.jdt.core.prefs
create mode 100644 group24/1107225491/1107225491/test.txt
diff --git a/group24/1107225491/1107225491/.classpath b/group24/1107225491/1107225491/.classpath
new file mode 100644
index 0000000000..07ca123c63
--- /dev/null
+++ b/group24/1107225491/1107225491/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/group24/1107225491/1107225491/.project b/group24/1107225491/1107225491/.project
new file mode 100644
index 0000000000..2d1d33be8a
--- /dev/null
+++ b/group24/1107225491/1107225491/.project
@@ -0,0 +1,17 @@
+
+
+ 1107225491
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/group24/1107225491/1107225491/.settings/org.eclipse.jdt.core.prefs b/group24/1107225491/1107225491/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000000..54e493c07c
--- /dev/null
+++ b/group24/1107225491/1107225491/.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.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+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.6
diff --git a/group24/1107225491/1107225491/test.txt b/group24/1107225491/1107225491/test.txt
new file mode 100644
index 0000000000..2086f8809c
--- /dev/null
+++ b/group24/1107225491/1107225491/test.txt
@@ -0,0 +1 @@
+�ܶ��ܶ�
\ No newline at end of file
From c4b94e171d1f2b3f840282b6ce875318cd81e94a Mon Sep 17 00:00:00 2001
From: xiaozi
Date: Wed, 8 Mar 2017 23:08:18 +0800
Subject: [PATCH 02/26] This is a test.
---
group24/1054283210/.classpath | 6 ++++++
group24/1054283210/.gitignore | 1 +
group24/1054283210/.project | 17 +++++++++++++++++
3 files changed, 24 insertions(+)
create mode 100644 group24/1054283210/.classpath
create mode 100644 group24/1054283210/.gitignore
create mode 100644 group24/1054283210/.project
diff --git a/group24/1054283210/.classpath b/group24/1054283210/.classpath
new file mode 100644
index 0000000000..d171cd4c12
--- /dev/null
+++ b/group24/1054283210/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/group24/1054283210/.gitignore b/group24/1054283210/.gitignore
new file mode 100644
index 0000000000..ae3c172604
--- /dev/null
+++ b/group24/1054283210/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/group24/1054283210/.project b/group24/1054283210/.project
new file mode 100644
index 0000000000..b401802bd0
--- /dev/null
+++ b/group24/1054283210/.project
@@ -0,0 +1,17 @@
+
+
+ 1054283210Learning
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
From bfc1e2476e4fee5b46d344b5a0ffc4506b59c2e8 Mon Sep 17 00:00:00 2001
From: ipk
Date: Thu, 9 Mar 2017 01:29:01 +0800
Subject: [PATCH 03/26] this is test for git
---
group24/121111914/src/com/ipk/code2017/TestGit.java | 10 ++++++++++
1 file changed, 10 insertions(+)
create mode 100644 group24/121111914/src/com/ipk/code2017/TestGit.java
diff --git a/group24/121111914/src/com/ipk/code2017/TestGit.java b/group24/121111914/src/com/ipk/code2017/TestGit.java
new file mode 100644
index 0000000000..dbfa49c571
--- /dev/null
+++ b/group24/121111914/src/com/ipk/code2017/TestGit.java
@@ -0,0 +1,10 @@
+package com.ipk.code2017;
+
+public class TestGit {
+
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+ System.out.println("hehe");
+ }
+
+}
From 391f19c32957f463d2af82e383a963f53932ee02 Mon Sep 17 00:00:00 2001
From: LF
Date: Thu, 9 Mar 2017 01:35:01 +0800
Subject: [PATCH 04/26] test for git
---
group24/121111914/src/com/ipk/code2017/TestGit1.java | 10 ++++++++++
1 file changed, 10 insertions(+)
create mode 100644 group24/121111914/src/com/ipk/code2017/TestGit1.java
diff --git a/group24/121111914/src/com/ipk/code2017/TestGit1.java b/group24/121111914/src/com/ipk/code2017/TestGit1.java
new file mode 100644
index 0000000000..2b1a0cd7ca
--- /dev/null
+++ b/group24/121111914/src/com/ipk/code2017/TestGit1.java
@@ -0,0 +1,10 @@
+package com.ipk.code2017;
+
+public class TestGit1 {
+
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
From 87a70cdb6239aa7bc2e5a0ade0f70366c14f8ff3 Mon Sep 17 00:00:00 2001
From: LF
Date: Thu, 9 Mar 2017 23:46:56 +0800
Subject: [PATCH 05/26] test for newName
---
.../ipk2015/coding2017/basic/TestForNewName.java | 10 ++++++++++
1 file changed, 10 insertions(+)
create mode 100644 group24/121111914/src/com/github/ipk2015/coding2017/basic/TestForNewName.java
diff --git a/group24/121111914/src/com/github/ipk2015/coding2017/basic/TestForNewName.java b/group24/121111914/src/com/github/ipk2015/coding2017/basic/TestForNewName.java
new file mode 100644
index 0000000000..79a296c37d
--- /dev/null
+++ b/group24/121111914/src/com/github/ipk2015/coding2017/basic/TestForNewName.java
@@ -0,0 +1,10 @@
+package com.github.ipk2015.coding2017.basic;
+
+public class TestForNewName {
+
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
From be43af55826ff74d93cbe1dde9af45df58a37ca1 Mon Sep 17 00:00:00 2001
From: LF
Date: Thu, 9 Mar 2017 23:48:23 +0800
Subject: [PATCH 06/26] delete the test
---
group24/121111914/src/com/ipk/code2017/TestGit.java | 10 ----------
group24/121111914/src/com/ipk/code2017/TestGit1.java | 10 ----------
2 files changed, 20 deletions(-)
delete mode 100644 group24/121111914/src/com/ipk/code2017/TestGit.java
delete mode 100644 group24/121111914/src/com/ipk/code2017/TestGit1.java
diff --git a/group24/121111914/src/com/ipk/code2017/TestGit.java b/group24/121111914/src/com/ipk/code2017/TestGit.java
deleted file mode 100644
index dbfa49c571..0000000000
--- a/group24/121111914/src/com/ipk/code2017/TestGit.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.ipk.code2017;
-
-public class TestGit {
-
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- System.out.println("hehe");
- }
-
-}
diff --git a/group24/121111914/src/com/ipk/code2017/TestGit1.java b/group24/121111914/src/com/ipk/code2017/TestGit1.java
deleted file mode 100644
index 2b1a0cd7ca..0000000000
--- a/group24/121111914/src/com/ipk/code2017/TestGit1.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.ipk.code2017;
-
-public class TestGit1 {
-
- public static void main(String[] args) {
- // TODO Auto-generated method stub
-
- }
-
-}
From 53397c7b35d908ca2549be6b1c6a437d772dedde Mon Sep 17 00:00:00 2001
From: LF
Date: Thu, 9 Mar 2017 23:56:26 +0800
Subject: [PATCH 07/26] delete the test
---
.../ipk2015/coding2017/basic/TestForNewName.java | 10 ----------
1 file changed, 10 deletions(-)
delete mode 100644 group24/121111914/src/com/github/ipk2015/coding2017/basic/TestForNewName.java
diff --git a/group24/121111914/src/com/github/ipk2015/coding2017/basic/TestForNewName.java b/group24/121111914/src/com/github/ipk2015/coding2017/basic/TestForNewName.java
deleted file mode 100644
index 79a296c37d..0000000000
--- a/group24/121111914/src/com/github/ipk2015/coding2017/basic/TestForNewName.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.github.ipk2015.coding2017.basic;
-
-public class TestForNewName {
-
- public static void main(String[] args) {
- // TODO Auto-generated method stub
-
- }
-
-}
From 0d834083eef96e49b6ec067e95dd03dd5ff8795c Mon Sep 17 00:00:00 2001
From: wangxin
Date: Fri, 10 Mar 2017 17:58:33 +0800
Subject: [PATCH 08/26] init
---
group24/626451284Learning/pom.xml | 12 ++
.../wdn/coding2017/basic/ArrayList.java | 32 +++++
.../wdn/coding2017/basic/BinaryTreeNode.java | 32 +++++
.../github/wdn/coding2017/basic/Iterator.java | 7 +
.../wdn/coding2017/basic/LinkedList.java | 124 ++++++++++++++++++
.../com/github/wdn/coding2017/basic/List.java | 9 ++
.../github/wdn/coding2017/basic/Queue.java | 19 +++
.../github/wdn/coding2017/basic/Stack.java | 22 ++++
.../coderising/array/ArrayUtil.java | 96 ++++++++++++++
.../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 +++
.../coderising/litestruts/LoginAction.java | 39 ++++++
.../coderising/litestruts/Struts.java | 34 +++++
.../coderising/litestruts/StrutsTest.java | 43 ++++++
.../coderising/litestruts/View.java | 23 ++++
.../coderising/litestruts/struts.xml | 11 ++
23 files changed, 740 insertions(+)
create mode 100644 group24/626451284Learning/pom.xml
create mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/ArrayList.java
create mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/BinaryTreeNode.java
create mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Iterator.java
create mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/LinkedList.java
create mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/List.java
create mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Queue.java
create mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Stack.java
create mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/array/ArrayUtil.java
create mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/DownloadThread.java
create mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/FileDownloader.java
create mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/FileDownloaderTest.java
create mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/Connection.java
create mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/ConnectionException.java
create mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/ConnectionManager.java
create mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/DownloadListener.java
create mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/impl/ConnectionImpl.java
create mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/impl/ConnectionManagerImpl.java
create mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/LoginAction.java
create mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/Struts.java
create mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/StrutsTest.java
create mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/View.java
create mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/struts.xml
diff --git a/group24/626451284Learning/pom.xml b/group24/626451284Learning/pom.xml
new file mode 100644
index 0000000000..534ff39232
--- /dev/null
+++ b/group24/626451284Learning/pom.xml
@@ -0,0 +1,12 @@
+
+
+ 4.0.0
+
+ com.github.wdn
+ coding2017
+ 1.0-SNAPSHOT
+
+
+
\ No newline at end of file
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/ArrayList.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/ArrayList.java
new file mode 100644
index 0000000000..bfd96d3202
--- /dev/null
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/ArrayList.java
@@ -0,0 +1,32 @@
+package com.github.wdn.coding2017.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;
+ }
+
+}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/BinaryTreeNode.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/BinaryTreeNode.java
new file mode 100644
index 0000000000..39d4e62c93
--- /dev/null
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/BinaryTreeNode.java
@@ -0,0 +1,32 @@
+package com.github.wdn.coding2017.basic;
+
+public class BinaryTreeNode {
+
+ private Object data;
+ private BinaryTreeNode left;
+ private BinaryTreeNode right;
+
+ public Object getData() {
+ return data;
+ }
+ public void setData(Object data) {
+ this.data = data;
+ }
+ public BinaryTreeNode getLeft() {
+ return left;
+ }
+ public void setLeft(BinaryTreeNode left) {
+ this.left = left;
+ }
+ public BinaryTreeNode getRight() {
+ return right;
+ }
+ public void setRight(BinaryTreeNode right) {
+ this.right = right;
+ }
+
+ public BinaryTreeNode insert(Object o){
+ return null;
+ }
+
+}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Iterator.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Iterator.java
new file mode 100644
index 0000000000..f601a50c7b
--- /dev/null
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Iterator.java
@@ -0,0 +1,7 @@
+package com.github.wdn.coding2017.basic;
+
+public interface Iterator {
+ public boolean hasNext();
+ public Object next();
+
+}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/LinkedList.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/LinkedList.java
new file mode 100644
index 0000000000..ba5b32cb90
--- /dev/null
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/LinkedList.java
@@ -0,0 +1,124 @@
+package com.github.wdn.coding2017.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;
+ }
+}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/List.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/List.java
new file mode 100644
index 0000000000..d6c9e95cb0
--- /dev/null
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/List.java
@@ -0,0 +1,9 @@
+package com.github.wdn.coding2017.basic;
+
+public interface List {
+ public void add(Object o);
+ public void add(int index, Object o);
+ public Object get(int index);
+ public Object remove(int index);
+ public int size();
+}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Queue.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Queue.java
new file mode 100644
index 0000000000..627f2d3a87
--- /dev/null
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Queue.java
@@ -0,0 +1,19 @@
+package com.github.wdn.coding2017.basic;
+
+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/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Stack.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Stack.java
new file mode 100644
index 0000000000..a5970ed4c7
--- /dev/null
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Stack.java
@@ -0,0 +1,22 @@
+package com.github.wdn.coding2017.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;
+ }
+}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/array/ArrayUtil.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/array/ArrayUtil.java
new file mode 100644
index 0000000000..45c32815f4
--- /dev/null
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/array/ArrayUtil.java
@@ -0,0 +1,96 @@
+package com.github.wdn.coding2017.coderising.array;
+
+public class ArrayUtil {
+
+ /**
+ * 给定一个整形数组a , 对该数组的值进行置换
+ 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7]
+ 如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7]
+ * @param origin
+ * @return
+ */
+ public void reverseArray(int[] origin){
+
+ }
+
+ /**
+ * 现在有如下的一个数组: 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){
+ return null;
+ }
+
+ /**
+ * 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的
+ * 例如 a1 = [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复
+ * @param array1
+ * @param array2
+ * @return
+ */
+
+ public int[] merge(int[] array1, int[] array2){
+ return null;
+ }
+ /**
+ * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
+ * 注意,老数组的元素在新数组中需要保持
+ * 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
+ * [2,3,6,0,0,0]
+ * @param oldArray
+ * @param size
+ * @return
+ */
+ public int[] grow(int [] oldArray, int size){
+ return null;
+ }
+
+ /**
+ * 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列
+ * 例如, max = 15 , 则返回的数组应该为 [1,1,2,3,5,8,13]
+ * max = 1, 则返回空数组 []
+ * @param max
+ * @return
+ */
+ public int[] fibonacci(int max){
+ return null;
+ }
+
+ /**
+ * 返回小于给定最大值max的所有素数数组
+ * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
+ * @param max
+ * @return
+ */
+ public int[] getPrimes(int max){
+ return null;
+ }
+
+ /**
+ * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
+ * 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
+ * @param max
+ * @return
+ */
+ public int[] getPerfectNumbers(int max){
+ return null;
+ }
+
+ /**
+ * 用seperator 把数组 array给连接起来
+ * 例如array= [3,8,9], seperator = "-"
+ * 则返回值为"3-8-9"
+ * @param array
+ * @param s
+ * @return
+ */
+ public String join(int[] array, String seperator){
+ return null;
+ }
+
+
+}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/DownloadThread.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/DownloadThread.java
new file mode 100644
index 0000000000..cc0e750c98
--- /dev/null
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/DownloadThread.java
@@ -0,0 +1,20 @@
+package com.github.wdn.coding2017.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/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/FileDownloader.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/FileDownloader.java
new file mode 100644
index 0000000000..a5c19a7d77
--- /dev/null
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/FileDownloader.java
@@ -0,0 +1,73 @@
+package com.github.wdn.coding2017.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(){
+ // 在这里实现你的代码, 注意: 需要用多线程实现下载
+ // 这个类依赖于其他几个接口, 你需要写这几个接口的实现代码
+ // (1) ConnectionManager , 可以打开一个连接,通过Connection可以读取其中的一段(用startPos, endPos来指定)
+ // (2) DownloadListener, 由于是多线程下载, 调用这个类的客户端不知道什么时候结束,所以你需要实现当所有
+ // 线程都执行完以后, 调用listener的notifiedFinished方法, 这样客户端就能收到通知。
+ // 具体的实现思路:
+ // 1. 需要调用ConnectionManager的open方法打开连接, 然后通过Connection.getContentLength方法获得文件的长度
+ // 2. 至少启动3个线程下载, 注意每个线程需要先调用ConnectionManager的open方法
+ // 然后调用read方法, read方法中有读取文件的开始位置和结束位置的参数, 返回值是byte[]数组
+ // 3. 把byte数组写入到文件中
+ // 4. 所有的线程都下载完成以后, 需要调用listener的notifiedFinished方法
+
+ // 下面的代码是示例代码, 也就是说只有一个线程, 你需要改造成多线程的。
+ 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/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/FileDownloaderTest.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/FileDownloaderTest.java
new file mode 100644
index 0000000000..490db5c08b
--- /dev/null
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/FileDownloaderTest.java
@@ -0,0 +1,59 @@
+package com.github.wdn.coding2017.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/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/Connection.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/Connection.java
new file mode 100644
index 0000000000..91e8aa463b
--- /dev/null
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/Connection.java
@@ -0,0 +1,23 @@
+package com.github.wdn.coding2017.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/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/ConnectionException.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/ConnectionException.java
new file mode 100644
index 0000000000..5c90080401
--- /dev/null
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/ConnectionException.java
@@ -0,0 +1,5 @@
+package com.github.wdn.coding2017.coderising.download.api;
+
+public class ConnectionException extends Exception {
+
+}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/ConnectionManager.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/ConnectionManager.java
new file mode 100644
index 0000000000..f814016839
--- /dev/null
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/ConnectionManager.java
@@ -0,0 +1,10 @@
+package com.github.wdn.coding2017.coderising.download.api;
+
+public interface ConnectionManager {
+ /**
+ * 给定一个url , 打开一个连接
+ * @param url
+ * @return
+ */
+ public Connection open(String url) throws ConnectionException;
+}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/DownloadListener.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/DownloadListener.java
new file mode 100644
index 0000000000..078b14365d
--- /dev/null
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/DownloadListener.java
@@ -0,0 +1,5 @@
+package com.github.wdn.coding2017.coderising.download.api;
+
+public interface DownloadListener {
+ public void notifyFinished();
+}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/impl/ConnectionImpl.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/impl/ConnectionImpl.java
new file mode 100644
index 0000000000..e2bc4dcd10
--- /dev/null
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/impl/ConnectionImpl.java
@@ -0,0 +1,27 @@
+package com.github.wdn.coding2017.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/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/impl/ConnectionManagerImpl.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/impl/ConnectionManagerImpl.java
new file mode 100644
index 0000000000..082e2af8fd
--- /dev/null
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/impl/ConnectionManagerImpl.java
@@ -0,0 +1,15 @@
+package com.github.wdn.coding2017.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/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/LoginAction.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/LoginAction.java
new file mode 100644
index 0000000000..b342a51061
--- /dev/null
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/LoginAction.java
@@ -0,0 +1,39 @@
+package com.github.wdn.coding2017.coderising.litestruts;
+
+/**
+ * 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。
+ * @author liuxin
+ *
+ */
+public class LoginAction{
+ private String name ;
+ private String password;
+ private String message;
+
+ public String getName() {
+ return name;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String execute(){
+ if("test".equals(name) && "1234".equals(password)){
+ this.message = "login successful";
+ return "success";
+ }
+ this.message = "login failed,please check your user/pwd";
+ return "fail";
+ }
+
+ public void setName(String name){
+ this.name = name;
+ }
+ public void setPassword(String password){
+ this.password = password;
+ }
+ public String getMessage(){
+ return this.message;
+ }
+}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/Struts.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/Struts.java
new file mode 100644
index 0000000000..cf3d0564f1
--- /dev/null
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/Struts.java
@@ -0,0 +1,34 @@
+package com.github.wdn.coding2017.coderising.litestruts;
+
+import java.util.Map;
+
+
+
+public class Struts {
+
+ public static View runAction(String actionName, Map parameters) {
+
+ /*
+
+ 0. 读取配置文件struts.xml
+
+ 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
+ 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是
+ ("name"="test" , "password"="1234") ,
+ 那就应该调用 setName和setPassword方法
+
+ 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
+
+ 3. 通过反射找到对象的所有getter方法(例如 getMessage),
+ 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} ,
+ 放到View对象的parameters
+
+ 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
+ 放到View对象的jsp字段中。
+
+ */
+
+ return null;
+ }
+
+}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/StrutsTest.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/StrutsTest.java
new file mode 100644
index 0000000000..9fee464283
--- /dev/null
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/StrutsTest.java
@@ -0,0 +1,43 @@
+package com.github.wdn.coding2017.coderising.litestruts;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+
+
+
+
+public class StrutsTest {
+
+ @Test
+ public void testLoginActionSuccess() {
+
+ String actionName = "login";
+
+ Map params = new HashMap();
+ params.put("name","test");
+ params.put("password","1234");
+
+
+ View view = Struts.runAction(actionName,params);
+
+ Assert.assertEquals("/jsp/homepage.jsp", view.getJsp());
+ Assert.assertEquals("login successful", view.getParameters().get("message"));
+ }
+
+ @Test
+ public void testLoginActionFailed() {
+ String actionName = "login";
+ Map params = new HashMap();
+ params.put("name","test");
+ params.put("password","123456"); //密码和预设的不一致
+
+ View view = Struts.runAction(actionName,params);
+
+ Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp());
+ Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message"));
+ }
+}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/View.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/View.java
new file mode 100644
index 0000000000..31e1805dc7
--- /dev/null
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/View.java
@@ -0,0 +1,23 @@
+package com.github.wdn.coding2017.coderising.litestruts;
+
+import java.util.Map;
+
+public class View {
+ private String jsp;
+ private Map parameters;
+
+ public String getJsp() {
+ return jsp;
+ }
+ public View setJsp(String jsp) {
+ this.jsp = jsp;
+ return this;
+ }
+ public Map getParameters() {
+ return parameters;
+ }
+ public View setParameters(Map parameters) {
+ this.parameters = parameters;
+ return this;
+ }
+}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/struts.xml b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/struts.xml
new file mode 100644
index 0000000000..171848ecd1
--- /dev/null
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/struts.xml
@@ -0,0 +1,11 @@
+
+
+
+ /jsp/homepage.jsp
+ /jsp/showLogin.jsp
+
+
+ /jsp/welcome.jsp
+ /jsp/error.jsp
+
+
From b8c5dcec1d760d49f8e40708539d8b00c8aa6242 Mon Sep 17 00:00:00 2001
From: wdn <626451284@163.com>
Date: Sat, 11 Mar 2017 17:26:31 +0800
Subject: [PATCH 09/26] =?UTF-8?q?=E7=AE=80=E5=8D=95=E5=AE=9E=E7=8E=B0Array?=
=?UTF-8?q?List=E3=80=81Stack=E3=80=81Queue,LinkedList;?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../wdn/coding2017/basic/ArrayList.java | 84 ++++++++--
.../wdn/coding2017/basic/BinaryTreeNode.java | 3 +
.../github/wdn/coding2017/basic/Iterator.java | 3 +
.../wdn/coding2017/basic/LinkedList.java | 157 +++++++++++++++---
.../github/wdn/coding2017/basic/Queue.java | 15 +-
.../github/wdn/coding2017/basic/Stack.java | 15 +-
6 files changed, 229 insertions(+), 48 deletions(-)
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/ArrayList.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/ArrayList.java
index bfd96d3202..3b3ea048f3 100644
--- a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/ArrayList.java
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/ArrayList.java
@@ -1,32 +1,88 @@
package com.github.wdn.coding2017.basic;
+import java.util.Arrays;
+
public class ArrayList implements List {
-
+
private int size = 0;
-
- private Object[] elementData = new Object[100];
-
+
+ private Object[] elementData;
+ public ArrayList(){
+ elementData = new Object[10];
+ }
+ public ArrayList(int size){
+ elementData = new Object[size];
+ }
public void add(Object o){
-
+ if(size>=elementData.length){
+ elementData = Arrays.copyOf(elementData,elementData.length*2);
+ }
+ elementData[size]=o;
+ size++;
}
public void add(int index, Object o){
-
+ Object[] newElementData;
+ if(size()+1>=elementData.length){
+ newElementData=new Object[elementData.length*2];
+
+ }else{
+ newElementData=new Object[elementData.length];
+ }
+ for (int i = 0; i < elementData.length; i++) {
+ if(index==1){
+ newElementData[i]=o;
+ }else if(i>index) {
+ newElementData[i]=elementData[i-1];
+ }else{
+ newElementData[i]=elementData[i];
+ }
+ }
+ elementData = newElementData;
+ size++;
}
-
+
public Object get(int index){
- return null;
+ if(index>=size){
+ throw new IndexOutOfBoundsException();
+ }
+ return elementData[index];
}
-
- public Object remove(int index){
- return null;
+
+ public Object remove(int index) {
+ if(index>=size){
+ throw new IndexOutOfBoundsException();
+ }
+ Object returnO = elementData[index];
+ for (int i = index; i < size; i++) {
+ if(i==size-1){
+ elementData[i]=null;
+ }else {
+ elementData[i] = elementData[i + 1];
+ }
+ }
+ size--;
+ return returnO;
}
-
+
public int size(){
- return -1;
+ return size;
}
-
+
public Iterator iterator(){
return null;
}
+
+ public static void main(String[] args) {
+ ArrayList list = new ArrayList(2);
+ list.add("1");
+ list.add("2");
+ list.remove(1);
+ list.add("3");
+ for (int i = 0; i < list.size(); i++) {
+ System.out.println(list.get(i));
+ }
+ int[] i = {};
+ System.out.println(i[0]);
+ }
}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/BinaryTreeNode.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/BinaryTreeNode.java
index 39d4e62c93..b8b613d6f0 100644
--- a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/BinaryTreeNode.java
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/BinaryTreeNode.java
@@ -1,5 +1,8 @@
package com.github.wdn.coding2017.basic;
+/**
+ * TODO 代码在公司电脑里。。。后续提交
+ */
public class BinaryTreeNode {
private Object data;
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Iterator.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Iterator.java
index f601a50c7b..044ddf0993 100644
--- a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Iterator.java
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Iterator.java
@@ -1,5 +1,8 @@
package com.github.wdn.coding2017.basic;
+/**
+ * TODO 主要考虑遍历中安全删除元素的实现
+ */
public interface Iterator {
public boolean hasNext();
public Object next();
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/LinkedList.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/LinkedList.java
index ba5b32cb90..6040cb5a47 100644
--- a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/LinkedList.java
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/LinkedList.java
@@ -1,92 +1,201 @@
package com.github.wdn.coding2017.basic;
-
+/**
+ * TODO 只是简单实现 缺少对边界的处理
+ * 参考JDK源码改为更优雅的实现
+ */
public class LinkedList implements List {
private Node head;
-
+ private Node tail;
+ private int size;
+
+ public LinkedList(){
+ this.head=null;
+ this.tail=null;
+ }
public void add(Object o){
-
+ Node newNode = new Node(o);
+ if (head == null) {
+ head = newNode;
+ tail = newNode;
+ }else{
+ tail.setNext(newNode);
+ newNode.setPre(tail);
+ tail = newNode;
+ }
+ size++;
}
public void add(int index , Object o){
-
+ checkIndex(index);
+ Node indexNode = getNode(index);
+ Node newNode = new Node(o);
+ Node pre = indexNode.getPre();
+ if(pre!=null){
+ pre.setNext(newNode);
+ }else{
+ head = newNode;
+ }
+ newNode.setPre(pre);
+ newNode.setNext(indexNode);
+ indexNode.setPre(newNode);
+ }
+ private void checkIndex(int index){
+ if(index >= size || index <0){
+ throw new IndexOutOfBoundsException();
+ }
+ }
+ private Node getNode(int index){
+ checkIndex(index);
+ // TODO这里可以优化,先判断index在前半部还是后半部分 然后确定从头部或者尾部查找
+ Node result=null;
+ if(index==0){
+ return head;
+ }
+ if(index==size-1){
+ return tail;
+ }
+ for (int i = 0; i < index; i++) {
+ result = head.getNext();
+ }
+ return result;
}
public Object get(int index){
- return null;
+ return getNode(index).getData();
}
public Object remove(int index){
- return null;
+ checkIndex(index);
+ Node indexNode = getNode(index);
+ Node pre = indexNode.getPre();
+ Node next = indexNode.getNext();
+ if(pre!=null){
+ pre.setNext(next);
+ }else{
+ head = next;
+ }
+ if(next!=null){
+ next.setPre(pre);
+ }else{
+ tail = pre;
+ }
+ return indexNode.getData();
}
public int size(){
- return -1;
+ return size;
}
public void addFirst(Object o){
-
+ Node newNode = new Node(o);
+ head.setPre(newNode);
+ newNode.setNext(head);
+ head = newNode;
}
public void addLast(Object o){
-
+ Node newNode = new Node(o);
+ tail.setNext(newNode);
+ newNode.setPre(tail);
+ tail = newNode;
}
public Object removeFirst(){
- return null;
+ Node next = head.getNext();
+ Node oldHead = head;
+ head = next;
+ head.setPre(null);
+ return oldHead;
}
public Object removeLast(){
- return null;
+ Node oldTail = tail;
+ Node pre = tail.getPre();
+ tail = pre;
+ tail.setNext(null);
+ return oldTail;
}
public Iterator iterator(){
+
return null;
}
-
+ /**
+ * JDK 中使用构造方法的方式设置next和pre减少不必要的getset方法更优雅
+ */
private static class Node{
+
Object data;
Node next;
-
+ Node pre;
+ public Node(){
+
+ }
+ public Node(Object data){
+ this.data = data;
+ }
+ public Object getData() {
+ return data;
+ }
+
+ public void setData(Object data) {
+ this.data = data;
+ }
+
+ public Node getNext() {
+ return next;
+ }
+
+ public void setNext(Node next) {
+ this.next = next;
+ }
+
+ public Node getPre() {
+ return pre;
+ }
+
+ public void setPre(Node pre) {
+ this.pre = pre;
+ }
}
/**
* 把该链表逆置
* 例如链表为 3->7->10 , 逆置后变为 10->7->3
*/
- public void reverse(){
-
- }
-
- /**
+ 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]
+ * 返回的结果应该是[101,301,401,601]
* @param list
*/
public static int[] getElements(LinkedList list){
return null;
}
-
+
/**
* 已知链表中的元素以值递增有序排列,并以单链表作存储结构。
- * 从当前链表中中删除在list中出现的元素
+ * 从当前链表中中删除在list中出现的元素
* @param list
*/
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Queue.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Queue.java
index 627f2d3a87..59992f0cbd 100644
--- a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Queue.java
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Queue.java
@@ -1,19 +1,24 @@
package com.github.wdn.coding2017.basic;
+/**
+ * 队列使用链表实现比较简单理论上是无界队列
+ * 如果使用数组需要处理很多问题比如长度限制,元素的复制
+ */
public class Queue {
-
- public void enQueue(Object o){
+ private LinkedList queue = new LinkedList();
+ public void enQueue(Object o){
+ queue.add(o);
}
public Object deQueue(){
- return null;
+ return queue.remove(0);
}
public boolean isEmpty(){
- return false;
+ return queue.size()==0;
}
public int size(){
- return -1;
+ return queue.size();
}
}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Stack.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Stack.java
index a5970ed4c7..f0a0fe56e9 100644
--- a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Stack.java
+++ b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/basic/Stack.java
@@ -1,22 +1,27 @@
package com.github.wdn.coding2017.basic;
+/**
+ * 使用list实现比较简单
+ * 可以考虑使用其它结构
+ */
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(elementData.size()-1);
}
public Object peek(){
- return null;
+ return elementData.get(elementData.size()-1);
}
public boolean isEmpty(){
- return false;
+ return elementData.size()==0;
}
public int size(){
- return -1;
+ return elementData.size();
}
}
From dcf2f2d29a8aa24880f23f73b1b53169fa21c63e Mon Sep 17 00:00:00 2001
From: wdn <626451284@163.com>
Date: Sun, 12 Mar 2017 17:28:50 +0800
Subject: [PATCH 10/26] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E6=9C=AC=E5=91=A8?=
=?UTF-8?q?=E4=B8=8D=E7=9B=B8=E5=85=B3=E4=BD=9C=E4=B8=9A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../coderising/array/ArrayUtil.java | 96 -------------------
.../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 ---
.../coderising/litestruts/LoginAction.java | 39 --------
.../coderising/litestruts/Struts.java | 34 -------
.../coderising/litestruts/StrutsTest.java | 43 ---------
.../coderising/litestruts/View.java | 23 -----
.../coderising/litestruts/struts.xml | 11 ---
15 files changed, 483 deletions(-)
delete mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/array/ArrayUtil.java
delete mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/DownloadThread.java
delete mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/FileDownloader.java
delete mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/FileDownloaderTest.java
delete mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/Connection.java
delete mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/ConnectionException.java
delete mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/ConnectionManager.java
delete mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/DownloadListener.java
delete mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/impl/ConnectionImpl.java
delete mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/impl/ConnectionManagerImpl.java
delete mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/LoginAction.java
delete mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/Struts.java
delete mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/StrutsTest.java
delete mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/View.java
delete mode 100644 group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/struts.xml
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/array/ArrayUtil.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/array/ArrayUtil.java
deleted file mode 100644
index 45c32815f4..0000000000
--- a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/array/ArrayUtil.java
+++ /dev/null
@@ -1,96 +0,0 @@
-package com.github.wdn.coding2017.coderising.array;
-
-public class ArrayUtil {
-
- /**
- * 给定一个整形数组a , 对该数组的值进行置换
- 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7]
- 如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7]
- * @param origin
- * @return
- */
- public void reverseArray(int[] origin){
-
- }
-
- /**
- * 现在有如下的一个数组: 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){
- return null;
- }
-
- /**
- * 给定两个已经排序好的整形数组, a1和a2 , 创建一个新的数组a3, 使得a3 包含a1和a2 的所有元素, 并且仍然是有序的
- * 例如 a1 = [3, 5, 7,8] a2 = [4, 5, 6,7] 则 a3 为[3,4,5,6,7,8] , 注意: 已经消除了重复
- * @param array1
- * @param array2
- * @return
- */
-
- public int[] merge(int[] array1, int[] array2){
- return null;
- }
- /**
- * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size
- * 注意,老数组的元素在新数组中需要保持
- * 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为
- * [2,3,6,0,0,0]
- * @param oldArray
- * @param size
- * @return
- */
- public int[] grow(int [] oldArray, int size){
- return null;
- }
-
- /**
- * 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列
- * 例如, max = 15 , 则返回的数组应该为 [1,1,2,3,5,8,13]
- * max = 1, 则返回空数组 []
- * @param max
- * @return
- */
- public int[] fibonacci(int max){
- return null;
- }
-
- /**
- * 返回小于给定最大值max的所有素数数组
- * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19]
- * @param max
- * @return
- */
- public int[] getPrimes(int max){
- return null;
- }
-
- /**
- * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3
- * 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数
- * @param max
- * @return
- */
- public int[] getPerfectNumbers(int max){
- return null;
- }
-
- /**
- * 用seperator 把数组 array给连接起来
- * 例如array= [3,8,9], seperator = "-"
- * 则返回值为"3-8-9"
- * @param array
- * @param s
- * @return
- */
- public String join(int[] array, String seperator){
- return null;
- }
-
-
-}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/DownloadThread.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/DownloadThread.java
deleted file mode 100644
index cc0e750c98..0000000000
--- a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/DownloadThread.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.github.wdn.coding2017.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/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/FileDownloader.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/FileDownloader.java
deleted file mode 100644
index a5c19a7d77..0000000000
--- a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/FileDownloader.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package com.github.wdn.coding2017.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(){
- // 在这里实现你的代码, 注意: 需要用多线程实现下载
- // 这个类依赖于其他几个接口, 你需要写这几个接口的实现代码
- // (1) ConnectionManager , 可以打开一个连接,通过Connection可以读取其中的一段(用startPos, endPos来指定)
- // (2) DownloadListener, 由于是多线程下载, 调用这个类的客户端不知道什么时候结束,所以你需要实现当所有
- // 线程都执行完以后, 调用listener的notifiedFinished方法, 这样客户端就能收到通知。
- // 具体的实现思路:
- // 1. 需要调用ConnectionManager的open方法打开连接, 然后通过Connection.getContentLength方法获得文件的长度
- // 2. 至少启动3个线程下载, 注意每个线程需要先调用ConnectionManager的open方法
- // 然后调用read方法, read方法中有读取文件的开始位置和结束位置的参数, 返回值是byte[]数组
- // 3. 把byte数组写入到文件中
- // 4. 所有的线程都下载完成以后, 需要调用listener的notifiedFinished方法
-
- // 下面的代码是示例代码, 也就是说只有一个线程, 你需要改造成多线程的。
- 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/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/FileDownloaderTest.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/FileDownloaderTest.java
deleted file mode 100644
index 490db5c08b..0000000000
--- a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/FileDownloaderTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.github.wdn.coding2017.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/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/Connection.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/Connection.java
deleted file mode 100644
index 91e8aa463b..0000000000
--- a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/Connection.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.github.wdn.coding2017.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/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/ConnectionException.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/ConnectionException.java
deleted file mode 100644
index 5c90080401..0000000000
--- a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/ConnectionException.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.github.wdn.coding2017.coderising.download.api;
-
-public class ConnectionException extends Exception {
-
-}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/ConnectionManager.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/ConnectionManager.java
deleted file mode 100644
index f814016839..0000000000
--- a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/ConnectionManager.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.github.wdn.coding2017.coderising.download.api;
-
-public interface ConnectionManager {
- /**
- * 给定一个url , 打开一个连接
- * @param url
- * @return
- */
- public Connection open(String url) throws ConnectionException;
-}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/DownloadListener.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/DownloadListener.java
deleted file mode 100644
index 078b14365d..0000000000
--- a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/api/DownloadListener.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.github.wdn.coding2017.coderising.download.api;
-
-public interface DownloadListener {
- public void notifyFinished();
-}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/impl/ConnectionImpl.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/impl/ConnectionImpl.java
deleted file mode 100644
index e2bc4dcd10..0000000000
--- a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/impl/ConnectionImpl.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.github.wdn.coding2017.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/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/impl/ConnectionManagerImpl.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/impl/ConnectionManagerImpl.java
deleted file mode 100644
index 082e2af8fd..0000000000
--- a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/download/impl/ConnectionManagerImpl.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.github.wdn.coding2017.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/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/LoginAction.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/LoginAction.java
deleted file mode 100644
index b342a51061..0000000000
--- a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/LoginAction.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.github.wdn.coding2017.coderising.litestruts;
-
-/**
- * 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。
- * @author liuxin
- *
- */
-public class LoginAction{
- private String name ;
- private String password;
- private String message;
-
- public String getName() {
- return name;
- }
-
- public String getPassword() {
- return password;
- }
-
- public String execute(){
- if("test".equals(name) && "1234".equals(password)){
- this.message = "login successful";
- return "success";
- }
- this.message = "login failed,please check your user/pwd";
- return "fail";
- }
-
- public void setName(String name){
- this.name = name;
- }
- public void setPassword(String password){
- this.password = password;
- }
- public String getMessage(){
- return this.message;
- }
-}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/Struts.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/Struts.java
deleted file mode 100644
index cf3d0564f1..0000000000
--- a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/Struts.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.github.wdn.coding2017.coderising.litestruts;
-
-import java.util.Map;
-
-
-
-public class Struts {
-
- public static View runAction(String actionName, Map parameters) {
-
- /*
-
- 0. 读取配置文件struts.xml
-
- 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象)
- 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是
- ("name"="test" , "password"="1234") ,
- 那就应该调用 setName和setPassword方法
-
- 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success"
-
- 3. 通过反射找到对象的所有getter方法(例如 getMessage),
- 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} ,
- 放到View对象的parameters
-
- 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp,
- 放到View对象的jsp字段中。
-
- */
-
- return null;
- }
-
-}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/StrutsTest.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/StrutsTest.java
deleted file mode 100644
index 9fee464283..0000000000
--- a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/StrutsTest.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.github.wdn.coding2017.coderising.litestruts;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-
-
-
-
-public class StrutsTest {
-
- @Test
- public void testLoginActionSuccess() {
-
- String actionName = "login";
-
- Map params = new HashMap();
- params.put("name","test");
- params.put("password","1234");
-
-
- View view = Struts.runAction(actionName,params);
-
- Assert.assertEquals("/jsp/homepage.jsp", view.getJsp());
- Assert.assertEquals("login successful", view.getParameters().get("message"));
- }
-
- @Test
- public void testLoginActionFailed() {
- String actionName = "login";
- Map params = new HashMap();
- params.put("name","test");
- params.put("password","123456"); //密码和预设的不一致
-
- View view = Struts.runAction(actionName,params);
-
- Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp());
- Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message"));
- }
-}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/View.java b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/View.java
deleted file mode 100644
index 31e1805dc7..0000000000
--- a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/View.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.github.wdn.coding2017.coderising.litestruts;
-
-import java.util.Map;
-
-public class View {
- private String jsp;
- private Map parameters;
-
- public String getJsp() {
- return jsp;
- }
- public View setJsp(String jsp) {
- this.jsp = jsp;
- return this;
- }
- public Map getParameters() {
- return parameters;
- }
- public View setParameters(Map parameters) {
- this.parameters = parameters;
- return this;
- }
-}
diff --git a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/struts.xml b/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/struts.xml
deleted file mode 100644
index 171848ecd1..0000000000
--- a/group24/626451284Learning/src/main/java/com/github/wdn/coding2017/coderising/litestruts/struts.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
- /jsp/homepage.jsp
- /jsp/showLogin.jsp
-
-
- /jsp/welcome.jsp
- /jsp/error.jsp
-
-
From 751e08ba0bf457b9c125cb48d88fe2e5426db38b Mon Sep 17 00:00:00 2001
From: CJ-chen <120509419@qq.com>
Date: Sun, 12 Mar 2017 18:05:33 +0800
Subject: [PATCH 11/26] CJ-chen
---
.../CJ-chen/coding2017/basic/ArrayList.java | 123 +++++
.../coding2017/basic/BinaryTreeNode.java | 45 ++
.../CJ-chen/coding2017/basic/Iterator.java | 16 +
.../CJ-chen/coding2017/basic/LinkedList.java | 423 ++++++++++++++++++
.../github/CJ-chen/coding2017/basic/List.java | 18 +
.../CJ-chen/coding2017/basic/Queue.java | 58 +++
.../CJ-chen/coding2017/basic/Stack.java | 63 +++
7 files changed, 746 insertions(+)
create mode 100644 group24/com/github/CJ-chen/coding2017/basic/ArrayList.java
create mode 100644 group24/com/github/CJ-chen/coding2017/basic/BinaryTreeNode.java
create mode 100644 group24/com/github/CJ-chen/coding2017/basic/Iterator.java
create mode 100644 group24/com/github/CJ-chen/coding2017/basic/LinkedList.java
create mode 100644 group24/com/github/CJ-chen/coding2017/basic/List.java
create mode 100644 group24/com/github/CJ-chen/coding2017/basic/Queue.java
create mode 100644 group24/com/github/CJ-chen/coding2017/basic/Stack.java
diff --git a/group24/com/github/CJ-chen/coding2017/basic/ArrayList.java b/group24/com/github/CJ-chen/coding2017/basic/ArrayList.java
new file mode 100644
index 0000000000..cbb7084045
--- /dev/null
+++ b/group24/com/github/CJ-chen/coding2017/basic/ArrayList.java
@@ -0,0 +1,123 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package javaclass;
+
+import java.util.Arrays;
+
+/**
+ *
+ * @author CJ
+ */
+public class ArrayList implements List {
+
+ private int size = 0;
+
+ private Object[] elementData = new Object[100];
+
+ private final int defaultGrowSize = 100; // 每次增长 100 个元素
+
+// private int curIterIndex = 0; // 用于记录 Iterator的索引
+
+ private void CheckAndGrowUp() {
+ if (size+1 > elementData.length) {
+ elementData = Arrays.copyOf(elementData, elementData.length + defaultGrowSize);
+ }
+ }
+
+ // 添加一个方法,检测看,添加元素的话,是否需要增长,专门用于数组长度扩展的
+ public void add(Object o) {
+ CheckAndGrowUp();
+ elementData[size] = o;
+ size++;
+ }
+
+ @Override
+ public void add(int index, Object o) {
+ // 先探测是否添加数组大小
+ CheckAndGrowUp();
+ // 保留后半部分,然后 全部替换即可
+
+ Object[] tmpObjectArr = Arrays.copyOfRange(elementData, index, elementData.length);
+ elementData[index] = o;
+ for (int i = index+1; i < size+1; i++) {
+ elementData[i] = tmpObjectArr[i-index-1];
+ }
+ size++;
+
+ }
+
+ public Object get(int index) {
+ // 应该是 不需要跑出 下标越界异常的,因为数组越界会自动抛出
+ return elementData[index];
+ }
+
+ public Object remove(int index) {
+ for (int i = index; i < size; i++) {
+ elementData[i] = elementData[i + 1];
+ }
+ elementData[size] = null; // 后续后面是 数值?那么就不能为null了,而是零?
+ size--;
+ return null;
+ }
+
+ @Override
+ public int size() {
+ return size;
+ }
+
+ // 覆盖toString方法,方便测试
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("ArrayList: [");
+ for (int i = 0; i < size; i++) {
+ sb.append(elementData[i]).append(", ");
+ }
+// System.err.println(size);
+ sb.delete(sb.length()-2,sb.length()).append("]");
+ return sb.toString();
+ }
+
+ public Iterator iterator() {
+
+ return new Iterator() {
+ int curIterIndex = 0;
+ @Override
+ public boolean hasNext() {
+ // TODO Auto-generated method stub
+ return curIterIndex < size;
+ }
+
+ @Override
+ public Object next() {
+ // TODO Auto-generated method stub
+ return elementData[curIterIndex++];
+ }
+
+ };
+ }
+
+ public static void main(String[] args) {
+ ArrayList curArrList = new ArrayList();
+ for (int i = 0; i <= 101; i++) {
+ curArrList.add(i);
+ }
+ System.err.println("Test add Arr");
+ System.err.println(curArrList);
+ System.err.println("Test add in specific index");
+ curArrList.add(10, 1010);
+ System.err.println(curArrList);
+ System.err.println("Test remove");
+ curArrList.remove(10);
+ System.err.println(curArrList);
+ System.err.println("Test Iterator");
+ Iterator curIter = curArrList.iterator();
+ while(curIter.hasNext()){
+ System.err.println(curIter.next());
+ }
+ }
+
+}
diff --git a/group24/com/github/CJ-chen/coding2017/basic/BinaryTreeNode.java b/group24/com/github/CJ-chen/coding2017/basic/BinaryTreeNode.java
new file mode 100644
index 0000000000..3adcc7040b
--- /dev/null
+++ b/group24/com/github/CJ-chen/coding2017/basic/BinaryTreeNode.java
@@ -0,0 +1,45 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package javaclass;
+
+/**
+ *
+ * @author CJ
+ */
+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/group24/com/github/CJ-chen/coding2017/basic/Iterator.java b/group24/com/github/CJ-chen/coding2017/basic/Iterator.java
new file mode 100644
index 0000000000..29ab5ecaf0
--- /dev/null
+++ b/group24/com/github/CJ-chen/coding2017/basic/Iterator.java
@@ -0,0 +1,16 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package javaclass;
+
+/**
+ *
+ * @author CJ
+ */
+public interface Iterator {
+ public boolean hasNext();
+ public Object next();
+
+}
\ No newline at end of file
diff --git a/group24/com/github/CJ-chen/coding2017/basic/LinkedList.java b/group24/com/github/CJ-chen/coding2017/basic/LinkedList.java
new file mode 100644
index 0000000000..0364c16480
--- /dev/null
+++ b/group24/com/github/CJ-chen/coding2017/basic/LinkedList.java
@@ -0,0 +1,423 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package javaclass;
+
+import java.util.Arrays;
+
+/**
+ *
+ * @author CJ
+ */
+public class LinkedList implements List {
+
+ private Node head;
+
+ private int size;
+// private int curIterIndex;
+
+ public LinkedList() {
+ head = new Node();
+ size = 0;
+// curIterIndex = 0;
+ }
+
+ public void add(Object o) {
+ addLast(o);
+ }
+
+ private Node getNode(int index) {
+ if (index == -1) {
+ return head;
+ } else {
+ Node returnNode = head.next;
+ for (int i = 0; i < index; i++) {
+ returnNode = returnNode.next;
+ }
+ return returnNode;
+ }
+ }
+
+ public void add(int index, Object o) {
+ Node preNode = getNode(index - 1);
+ Node addNode = new Node();
+ addNode.data = o;
+ addNode.next = preNode.next;
+ preNode.next = addNode;
+ size++;
+ }
+
+ public Object get(int index) {
+ return getNode(index).data;
+ }
+
+ public Object remove(int index) {
+ Node preNode = getNode(index - 1);
+ Node delNode = preNode.next;
+ preNode.next = delNode.next;
+ // 返回被删除的Node... 可能是为了测试吧
+ size--;
+ return delNode;
+ }
+
+ public int size() {
+ return size;
+ }
+
+ public void addFirst(Object o) {
+ Node fNode = new Node();
+ fNode.data = o;
+ fNode.next = head.next;
+ head.next = fNode;
+ size++;
+ }
+
+ public void addLast(Object o) {
+// System.err.println("Curr add: "+ o);
+ Node lastNode = getNode(size - 1);
+// System.err.println(lastNode);
+ Node lNode = new Node();
+ lNode.data = o;
+ lastNode.next = lNode;
+ size++;
+ }
+
+ public Object removeFirst() {
+ return removeFirstNode().data;
+ }
+
+ private Node removeFirstNode() {
+ Node firstNode = head.next;
+ head.next = firstNode.next;
+ size--;
+ return firstNode;
+ }
+
+ public Object removeLast() {
+ return removeLastNode().data;
+ }
+
+ private Node removeLastNode() {
+ Node last2Node = getNode(size - 2);
+ Node lastNode = last2Node.next;
+ last2Node.next = null;
+ size--;
+ return lastNode;
+ }
+
+ public Iterator iterator() {
+ return new Iterator() {
+// int curIterIndex = 0;
+ Node curNode = head;
+
+ @Override
+ public boolean hasNext() {
+ return curNode.next != null;
+ }
+
+ @Override
+ public Object next() {
+ curNode = curNode.next;
+ return curNode.data;
+ }
+ };
+ }
+
+ private static class Node {
+
+ Object data;
+ Node next;
+ }
+
+ /**
+ * 把该链表逆置 例如链表为 3->7->10 , 逆置后变为 10->7->3
+ */
+ public void reverse() {
+
+ int oriSize = size;
+ Node newHead = new Node();
+ newHead.next = this.removeLastNode();
+ Node preNode = newHead.next;
+
+ while (size > 0) {
+ preNode.next = this.removeLastNode();
+ preNode = preNode.next;
+ }
+ // 不考虑线程安全的情况下,恢复size
+ size = oriSize;
+ head = newHead;
+ }
+
+ /**
+ * 删除一个单链表的前半部分 例如:list = 2->5->7->8 , 删除以后的值为 7->8 如果list = 2->5->7->8->10
+ * ,删除以后的值为7,8,10
+ */
+ public void removeFirstHalf() {
+ int reDirIndex = size / 2; // java会自动 取 0
+ size = size - reDirIndex;
+ System.err.println(reDirIndex);
+ Node jumpNode = getNode(reDirIndex);
+ head.next = jumpNode;
+ }
+
+ /**
+ * 从第i个元素开始, 删除length 个元素 , 注意i从0开始
+ *
+ * @param i
+ * @param length
+ */
+ public void remove(int i, int length) {
+ Node fromNode = getNode(i - 1);
+ for (int j = 0; j < length; j++) {
+ fromNode.next = fromNode.next.next;
+ size--;
+ }
+ }
+
+ /**
+ * 假定当前链表和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) {
+ // 这个似乎 不应该是 静态方法
+ public int[] getElements(LinkedList list) {
+ int[] returnIndex = new int[list.size];
+ int validCounts = 0;
+// Iterator curIter = list.iterator();
+// int curIndex = 0;
+// while(curIter.hasNext()){
+// returnIndex[curIndex++] =(Integer) this.get((Integer) curIter.next());
+// }
+
+ // 已知是内外都是玩去排序好的,所以是需要一个高效的算法
+ Iterator innerIter = this.iterator();
+ Iterator curIter = list.iterator();
+ int curCount = 0;
+ int curIndex;
+ int preIndex = 0;
+
+ while (curIter.hasNext()) {
+ curIndex = (Integer) curIter.next();
+ if (curIndex < preIndex) {
+ System.err.println("Warning: Skip index no in sorted order...");
+ continue;
+ }
+// int skipCounts = curIndex-preIndex;
+ for (int i = preIndex; i < curIndex; i++) {
+ innerIter.next();
+ }
+ validCounts++;
+ returnIndex[curCount++] = (Integer) innerIter.next();
+ preIndex = curIndex + 1;
+ }
+ return Arrays.copyOf(returnIndex, validCounts);
+ }
+
+ /**
+ * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 从当前链表中中删除在list中出现的元素
+ *
+ * @param list
+ */
+ public void subtract(LinkedList list) {
+ // 假定 当前 链表 和 待删除 链表 都是顺序排序的
+ Node preNode = head;
+ Node curNode;
+ Iterator element2rmIter = list.iterator();
+ while (element2rmIter.hasNext()) {
+ int curValue2rm = (Integer) element2rmIter.next();
+ while (preNode.next != null) {
+ curNode = preNode.next;
+ if ((Integer) curNode.data == curValue2rm) {
+ // 删除
+ preNode.next = curNode.next;
+ }else if((Integer) curNode.data > curValue2rm){
+ break; // 跳出内层循环,从而获取下一个待删除数据
+ }else {
+ // 更新
+ preNode = curNode;
+ }
+ }
+ }
+ }
+
+ /**
+ * 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同)
+ */
+ public void removeDuplicateValues() {
+ Node preNode = head;
+ Node curNode;
+ while (preNode.next != null) {
+ curNode = preNode.next;
+ if (curNode.data == preNode.data) {
+ preNode.next = curNode.next;
+ } else {
+ preNode = curNode;
+ }
+ }
+ }
+
+ /**
+ * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素)
+ *
+ * @param min
+ * @param max
+ */
+ public void removeRange(int min, int max) {
+ // 假定 当前链表 是 从小到大 排列的
+ Node preNode = head;
+ Node curNode;
+ while (preNode.next != null) {
+ curNode = preNode.next;
+ if (min < (Integer) curNode.data && max > (Integer) curNode.data) {
+ preNode.next = curNode.next;
+ } else {
+ preNode = curNode;
+ }
+ }
+ }
+
+ /**
+ * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同)
+ * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列
+ *
+ * @param list
+ */
+ public LinkedList intersection(LinkedList list) {
+
+
+ LinkedList newList = new LinkedList();
+
+ // 假定 当前 链表 和 待删除 链表 都是顺序排序的
+ Node preNode = head;
+ Node curNode;
+ Iterator element2rmIter = list.iterator();
+ while (element2rmIter.hasNext()) {
+ int curValue2rm = (Integer) element2rmIter.next();
+ while (preNode.next != null) {
+ curNode = preNode.next;
+ if ((Integer) curNode.data == curValue2rm) {
+ // 删除
+ preNode = curNode;
+ newList.add(curNode.data); // 添加data
+ }else if((Integer) curNode.data > curValue2rm){
+ break; // 跳出内层循环,从而获取下一个待删除数据
+ }else {
+ // 更新
+ preNode = curNode;
+ }
+ }
+ }
+
+
+ return newList;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("LinkdedList [");
+ Node curNode = head;
+ while (curNode.next != null) {
+ curNode = curNode.next;
+ sb.append(curNode.data).append(", ");
+ }
+ sb.delete(sb.length() - 2, sb.length()).append("]");
+ return sb.toString();
+ }
+
+ public void clear() {
+ head.next = null;
+ size = 0;
+ }
+
+ public static void main(String[] args) {
+ // 先写一些测试
+ LinkedList ll = new LinkedList();
+ System.err.println("Test Add");
+ for (int i = 0; i < 10; i++) {
+ ll.add(i);
+ }
+ System.err.println("Size: " + ll.size);
+ System.err.println(ll);
+ System.err.println("Test Add last");
+ ll.addLast(10);
+ System.err.println(ll);
+ System.err.println("Test Add First");
+ ll.addFirst(-1);
+ System.err.println(ll);
+ System.err.println("Test remove ");
+ ll.remove(0);
+ System.err.println(ll);
+// ll.remove(11);
+// System.err.println(ll);
+ ll.removeFirst();
+ System.err.println(ll);
+ ll.removeLast();
+ System.err.println(ll);
+ System.err.println("Test reverse()");
+ ll.reverse();
+ System.err.println(ll);
+ System.err.println("Test removeFirstHalf()");
+ ll.removeFirstHalf();
+ System.err.println(ll);
+// System.err.println(9/2);
+ System.err.println("Test remove()");
+ ll.remove(1, 2);
+ System.err.println(ll);
+// System.err.println(ll.);
+ LinkedList newList = new LinkedList();
+ newList.add(3);
+ newList.add(4);
+ newList.add(6);
+ newList.add(5);
+// System.err.println();
+ ll.clear();
+ System.err.println("Re Init");
+ for (int i = 0; i < 10; i++) {
+ ll.add(i);
+ }
+ System.err.println(ll);
+ for (int curI : ll.getElements(newList)) {
+ System.err.println(curI);
+ }
+ ll.clear();
+ for (int i = 0; i < 10; i++) {
+ ll.add(i);
+ ll.add(i);
+ ll.add(i);
+ }
+ System.err.println(ll);
+ ll.removeDuplicateValues();
+ System.err.println(ll);
+ System.err.println("Test Remove removeRange(3, 6)");
+ ll.removeRange(3, 6);
+ System.err.println(ll);
+
+ LinkedList rmList = new LinkedList();
+ rmList.add(3);
+ rmList.add(4);
+ rmList.add(7);
+ rmList.add(8);
+ ll.subtract(rmList);
+ System.err.println("Test subtract(3,4,7,8)");
+ System.err.println(ll);
+ ll.clear();
+ for (int i = 0; i < 10; i++) {
+ ll.add(i);
+ }
+ rmList.add(11);
+ System.err.println(ll);
+ System.err.println(rmList);
+ System.err.println(ll.intersection(rmList));
+// System.err.println("Test substract");
+// ll.subtract(newList);
+// System.err.println(ll);
+
+ }
+
+}
diff --git a/group24/com/github/CJ-chen/coding2017/basic/List.java b/group24/com/github/CJ-chen/coding2017/basic/List.java
new file mode 100644
index 0000000000..d347e59c47
--- /dev/null
+++ b/group24/com/github/CJ-chen/coding2017/basic/List.java
@@ -0,0 +1,18 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package javaclass;
+
+/**
+ *
+ * @author CJ
+ */
+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/group24/com/github/CJ-chen/coding2017/basic/Queue.java b/group24/com/github/CJ-chen/coding2017/basic/Queue.java
new file mode 100644
index 0000000000..4cbc45e065
--- /dev/null
+++ b/group24/com/github/CJ-chen/coding2017/basic/Queue.java
@@ -0,0 +1,58 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package javaclass;
+
+/**
+ *
+ * @author CJ
+ */
+public class Queue {
+
+ private final LinkedList innerList;
+
+ public Queue(){
+ innerList = new LinkedList();
+ }
+
+ public void enQueue(Object o) {
+ innerList.addLast(o);
+ }
+
+ public Object deQueue() {
+ return innerList.removeFirst();
+ }
+
+ public boolean isEmpty() {
+ return innerList.size()==0;
+ }
+
+ public int size() {
+ return innerList.size();
+ }
+
+ public String toString(){
+ StringBuilder sb = new StringBuilder();
+ sb.append("ArrayList: [");
+ for (int i = 0; i < innerList.size(); i++) {
+ sb.append(innerList.get(i)).append(", ");
+ }
+// System.err.println(size);
+ sb.delete(sb.length()-2,sb.length()).append("]");
+ return sb.toString();
+ }
+
+ public static void main(String[] args) {
+ Queue newQ = new Queue();
+ for(int i=0;i<10;i++){
+ newQ.enQueue(i);
+ }
+ System.err.println(newQ);
+ newQ.deQueue();
+ System.err.println(newQ);
+ }
+
+
+}
diff --git a/group24/com/github/CJ-chen/coding2017/basic/Stack.java b/group24/com/github/CJ-chen/coding2017/basic/Stack.java
new file mode 100644
index 0000000000..3ba85c6bcf
--- /dev/null
+++ b/group24/com/github/CJ-chen/coding2017/basic/Stack.java
@@ -0,0 +1,63 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package javaclass;
+
+/**
+ *
+ * @author CJ
+ */
+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();
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("ArrayList: [");
+ for (int i = 0; i < elementData.size(); i++) {
+ sb.append(elementData.get(i)).append(", ");
+ }
+// System.err.println(size);
+ sb.delete(sb.length()-2,sb.length()).append("]");
+ return sb.toString();
+ }
+ public static void main(String[] args) {
+ Stack newS = new Stack();
+ for(int i=0;i<10;i++){
+ newS.push(i);
+ }
+ System.err.println("Test push()");
+ System.err.println(newS);
+ newS.pop();
+ System.err.println("Test pop()");
+ System.err.println(newS);
+ System.err.println("Test peek()");
+ System.err.println(newS.peek());
+ System.err.println(newS);
+
+ }
+
+}
From af38e398a7884ec24ca03b42f622294153ec4224 Mon Sep 17 00:00:00 2001
From: LF
Date: Sun, 12 Mar 2017 18:28:59 +0800
Subject: [PATCH 12/26] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E4=BB=A3?=
=?UTF-8?q?=E7=A0=81=E6=8F=90=E4=BA=A4=EF=BC=9Alist=EF=BC=8Cstack,queue?=
=?UTF-8?q?=EF=BC=8C=E4=BA=8C=E5=8F=89=E6=A0=91=E7=9A=84=E5=AE=9E=E7=8E=B0?=
=?UTF-8?q?=E5=8F=8A=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ipk2015/coding2017/basic/ArrayList.java | 77 ++++++
.../coding2017/basic/BinaryTreeNode.java | 61 +++++
.../ipk2015/coding2017/basic/Iterator.java | 6 +
.../ipk2015/coding2017/basic/LinkedList.java | 244 ++++++++++++++++++
.../github/ipk2015/coding2017/basic/List.java | 8 +
.../ipk2015/coding2017/basic/ListUtils.java | 14 +
.../ipk2015/coding2017/basic/Queue.java | 19 ++
.../ipk2015/coding2017/basic/Stack.java | 32 +++
.../coding2017/basic/test/ArrayListTest.java | 53 ++++
.../basic/test/BinaryTreeNodeTest.java | 29 +++
.../coding2017/basic/test/LinkedListTest.java | 92 +++++++
.../coding2017/basic/test/QueueTest.java | 49 ++++
.../coding2017/basic/test/StackTest.java | 57 ++++
13 files changed, 741 insertions(+)
create mode 100644 group24/121111914/src/com/github/ipk2015/coding2017/basic/ArrayList.java
create mode 100644 group24/121111914/src/com/github/ipk2015/coding2017/basic/BinaryTreeNode.java
create mode 100644 group24/121111914/src/com/github/ipk2015/coding2017/basic/Iterator.java
create mode 100644 group24/121111914/src/com/github/ipk2015/coding2017/basic/LinkedList.java
create mode 100644 group24/121111914/src/com/github/ipk2015/coding2017/basic/List.java
create mode 100644 group24/121111914/src/com/github/ipk2015/coding2017/basic/ListUtils.java
create mode 100644 group24/121111914/src/com/github/ipk2015/coding2017/basic/Queue.java
create mode 100644 group24/121111914/src/com/github/ipk2015/coding2017/basic/Stack.java
create mode 100644 group24/121111914/src/com/github/ipk2015/coding2017/basic/test/ArrayListTest.java
create mode 100644 group24/121111914/src/com/github/ipk2015/coding2017/basic/test/BinaryTreeNodeTest.java
create mode 100644 group24/121111914/src/com/github/ipk2015/coding2017/basic/test/LinkedListTest.java
create mode 100644 group24/121111914/src/com/github/ipk2015/coding2017/basic/test/QueueTest.java
create mode 100644 group24/121111914/src/com/github/ipk2015/coding2017/basic/test/StackTest.java
diff --git a/group24/121111914/src/com/github/ipk2015/coding2017/basic/ArrayList.java b/group24/121111914/src/com/github/ipk2015/coding2017/basic/ArrayList.java
new file mode 100644
index 0000000000..e9c2a390fb
--- /dev/null
+++ b/group24/121111914/src/com/github/ipk2015/coding2017/basic/ArrayList.java
@@ -0,0 +1,77 @@
+package com.github.ipk2015.coding2017.basic;
+
+import java.util.Arrays;
+
+public class ArrayList implements List {
+
+ private int size = 0;
+
+ private Object[] elementData = new Object[100];
+
+ public void add(Object o){
+ add(size,o);
+ }
+ /*
+ * 分两种情况,index的范围为0到size,超出则抛出异常
+ * */
+ public void add(int index, Object o){
+ ListUtils.checkIndexInRange(index,size);
+ if(size==elementData.length){
+ elementData=Arrays.copyOf(elementData, size+1);
+ }
+ if(indexindex;i--){
+ elementData[i]=elementData[i-1];
+ }
+ }
+ elementData[index]=o;
+ size++;
+ }
+
+ public Object get(int index){
+ ListUtils.checkIndexInRange(index,size-1);
+ return elementData[index];
+ }
+
+ public Object remove(int index){
+ ListUtils.checkIndexInRange(index,size-1);
+ Object object=elementData[index];
+ for(int i=index;i0){
+ if(null==compareNode.getLeft()){
+ compareNode.setLeft(insertNode);
+ break;
+ }
+ compareNode=compareNode.getLeft();
+ }else if(result<0){
+ if(null==compareNode.getRight()){
+ compareNode.setRight(insertNode);
+ break;
+ }
+ compareNode=compareNode.getRight();
+ }
+ }
+ }
+
+ return insertNode;
+ }
+
+}
diff --git a/group24/121111914/src/com/github/ipk2015/coding2017/basic/Iterator.java b/group24/121111914/src/com/github/ipk2015/coding2017/basic/Iterator.java
new file mode 100644
index 0000000000..145acc5ef7
--- /dev/null
+++ b/group24/121111914/src/com/github/ipk2015/coding2017/basic/Iterator.java
@@ -0,0 +1,6 @@
+package com.github.ipk2015.coding2017.basic;
+
+public interface Iterator {
+ public boolean hasNext();
+ public Object next();
+}
diff --git a/group24/121111914/src/com/github/ipk2015/coding2017/basic/LinkedList.java b/group24/121111914/src/com/github/ipk2015/coding2017/basic/LinkedList.java
new file mode 100644
index 0000000000..d10c40a563
--- /dev/null
+++ b/group24/121111914/src/com/github/ipk2015/coding2017/basic/LinkedList.java
@@ -0,0 +1,244 @@
+package com.github.ipk2015.coding2017.basic;
+
+import java.util.NoSuchElementException;
+
+public class LinkedList implements List {
+
+ private Node head;
+
+ public void add(Object o){
+ if(null==head){
+ head=new Node();
+ head.data=o;
+ }else{
+ Node node=head;
+ while(null!=node.next){
+ node=node.next;
+ }
+ Node addNode=new Node();
+ addNode.data=o;
+ node.next=addNode;
+ }
+ }
+ public void add(int index , Object o){
+ int size=size();
+ ListUtils.checkIndexInRange(index, size);
+ if(index==size){
+ add(o);
+ }else{
+ if(size==0){
+ head=new Node();
+ head.data=o;
+ }else{
+ Node node=head;
+ Node addNode=new Node();
+ addNode.data=o;
+ for(int i=0;i7->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 rsection( LinkedList list){
+ return null;
+ }
+}
diff --git a/group24/121111914/src/com/github/ipk2015/coding2017/basic/List.java b/group24/121111914/src/com/github/ipk2015/coding2017/basic/List.java
new file mode 100644
index 0000000000..4e2f4036c0
--- /dev/null
+++ b/group24/121111914/src/com/github/ipk2015/coding2017/basic/List.java
@@ -0,0 +1,8 @@
+package com.github.ipk2015.coding2017.basic;
+public interface List {
+ public void add(Object o);
+ public void add(int index, Object o);
+ public Object get(int index);
+ public Object remove(int index);
+ public int size();
+}
diff --git a/group24/121111914/src/com/github/ipk2015/coding2017/basic/ListUtils.java b/group24/121111914/src/com/github/ipk2015/coding2017/basic/ListUtils.java
new file mode 100644
index 0000000000..4d73d7eec6
--- /dev/null
+++ b/group24/121111914/src/com/github/ipk2015/coding2017/basic/ListUtils.java
@@ -0,0 +1,14 @@
+package com.github.ipk2015.coding2017.basic;
+
+public class ListUtils {
+ public static boolean checkIndexInRange(int index,int range){
+ if(index>=0 && index<=range){
+ return true;
+ }
+ throw new IndexOutOfBoundsException();
+ }
+
+ public static void log(String msg){
+ System.out.println(msg);
+ }
+}
diff --git a/group24/121111914/src/com/github/ipk2015/coding2017/basic/Queue.java b/group24/121111914/src/com/github/ipk2015/coding2017/basic/Queue.java
new file mode 100644
index 0000000000..6342314df6
--- /dev/null
+++ b/group24/121111914/src/com/github/ipk2015/coding2017/basic/Queue.java
@@ -0,0 +1,19 @@
+package com.github.ipk2015.coding2017.basic;
+
+public class Queue {
+ private LinkedList elementDatas=new LinkedList();
+ public void enQueue(Object o){
+ elementDatas.add(o);
+ }
+ public Object deQueue(){
+ return elementDatas.removeFirst();
+ }
+
+ public boolean isEmpty(){
+ return size()==0;
+ }
+
+ public int size(){
+ return elementDatas.size();
+ }
+}
diff --git a/group24/121111914/src/com/github/ipk2015/coding2017/basic/Stack.java b/group24/121111914/src/com/github/ipk2015/coding2017/basic/Stack.java
new file mode 100644
index 0000000000..4dae60e12b
--- /dev/null
+++ b/group24/121111914/src/com/github/ipk2015/coding2017/basic/Stack.java
@@ -0,0 +1,32 @@
+package com.github.ipk2015.coding2017.basic;
+
+import java.util.EmptyStackException;
+
+public class Stack {
+ private ArrayList elementData = new ArrayList();
+
+ public void push(Object o){
+ elementData.add(o);
+ }
+
+ public Object pop(){
+ if(isEmpty()){
+ throw new EmptyStackException();
+ }
+ Object data=elementData.remove(size()-1);
+ return data;
+ }
+
+ public Object peek(){
+ if(isEmpty()){
+ throw new EmptyStackException();
+ }
+ return elementData.get(size()-1);
+ }
+ public boolean isEmpty(){
+ return size()==0;
+ }
+ public int size(){
+ return elementData.size();
+ }
+}
diff --git a/group24/121111914/src/com/github/ipk2015/coding2017/basic/test/ArrayListTest.java b/group24/121111914/src/com/github/ipk2015/coding2017/basic/test/ArrayListTest.java
new file mode 100644
index 0000000000..72a9a84b66
--- /dev/null
+++ b/group24/121111914/src/com/github/ipk2015/coding2017/basic/test/ArrayListTest.java
@@ -0,0 +1,53 @@
+package com.github.ipk2015.coding2017.basic.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.github.ipk2015.coding2017.basic.ArrayList;
+
+public class ArrayListTest {
+ ArrayList list;
+ @Before
+ public void setUp() throws Exception {
+ list=new ArrayList();
+
+ }
+ @Test
+ public void testAddObject() {
+ list.add("hehe1");
+ assertEquals("hehe1", list.get(0));
+ }
+
+ @Test
+ public void testAddIntObject() {
+ list.add("hehe1");
+ list.add("hehe2");
+ list.add("hehe3");
+ list.add(1, "arm");
+ assertEquals("arm", list.get(1));
+ }
+
+ @Test
+ public void testGet() {
+ list.add("hehe1");
+ assertEquals("hehe1", list.get(0));
+ }
+
+ @Test
+ public void testRemove() {
+ list.add("hehe1");
+ assertEquals("hehe1", list.remove(0));
+ }
+
+ @Test
+ public void testSize() {
+ list.add("hehe1");
+ list.add("hehe2");
+ list.add("hehe3");
+
+ assertEquals(3, list.size());
+ }
+
+}
diff --git a/group24/121111914/src/com/github/ipk2015/coding2017/basic/test/BinaryTreeNodeTest.java b/group24/121111914/src/com/github/ipk2015/coding2017/basic/test/BinaryTreeNodeTest.java
new file mode 100644
index 0000000000..4b2fe88ee0
--- /dev/null
+++ b/group24/121111914/src/com/github/ipk2015/coding2017/basic/test/BinaryTreeNodeTest.java
@@ -0,0 +1,29 @@
+package com.github.ipk2015.coding2017.basic.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.github.ipk2015.coding2017.basic.BinaryTreeNode;
+
+public class BinaryTreeNodeTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @Test
+ public void testInsert() {
+ BinaryTreeNode node=new BinaryTreeNode();
+
+ node.setData(5);
+ node.insert(2);
+ node.insert(7);
+ node.insert(1);
+ node.insert(4);
+ node.insert(3);
+ assertEquals(3,node.getLeft().getRight().getLeft().getData());
+ }
+
+}
diff --git a/group24/121111914/src/com/github/ipk2015/coding2017/basic/test/LinkedListTest.java b/group24/121111914/src/com/github/ipk2015/coding2017/basic/test/LinkedListTest.java
new file mode 100644
index 0000000000..57fed394d6
--- /dev/null
+++ b/group24/121111914/src/com/github/ipk2015/coding2017/basic/test/LinkedListTest.java
@@ -0,0 +1,92 @@
+package com.github.ipk2015.coding2017.basic.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.github.ipk2015.coding2017.basic.LinkedList;
+
+public class LinkedListTest {
+ LinkedList list;
+ @Before
+ public void setUp() throws Exception {
+ list=new LinkedList();
+ }
+
+ @Test
+ public void testAddObject() {
+ list.add("hehe1");
+ list.add("hehe2");
+ assertEquals("hehe2", list.get(1));
+ }
+
+ @Test
+ public void testAddIntObject() {
+ list.add("hehe1");
+ list.add("hehe2");
+ list.add("hehe3");
+ list.add(1,"arm");
+ assertEquals("arm", list.get(1));
+ }
+
+ @Test
+ public void testGet() {
+ list.add("hehe1");
+ list.add("hehe2");
+ assertEquals("hehe2", list.get(1));
+ }
+
+ @Test
+ public void testRemoveInt() {
+ list.add("hehe1");
+ list.add("hehe2");
+ list.add("hehe3");
+ list.remove(1);
+ assertEquals(2, list.size());
+ }
+
+ @Test
+ public void testSize() {
+ list.add("hehe1");
+ list.add("hehe2");
+ list.add("hehe3");
+ assertEquals(3, list.size());
+ }
+
+ @Test
+ public void testAddFirst() {
+ list.add("hehe1");
+ list.add("hehe2");
+ list.add("hehe3");
+ list.addFirst("arm");
+ assertEquals("arm", list.get(0));
+ }
+
+ @Test
+ public void testAddLast() {
+ list.add("hehe1");
+ list.add("hehe2");
+ list.add("hehe3");
+ list.addLast("arm");
+ assertEquals("arm", list.get(list.size()-1));
+ }
+
+ @Test
+ public void testRemoveFirst() {
+ list.add("hehe1");
+ list.add("hehe2");
+ list.add("hehe3");
+ list.removeFirst();
+ assertEquals("hehe2", list.get(0));
+ }
+ @Test
+ public void testRemoveLast() {
+ list.add("hehe1");
+ list.add("hehe2");
+ list.add("hehe3");
+ list.removeLast();
+ assertEquals("hehe2", list.get(list.size()-1));
+ }
+
+}
diff --git a/group24/121111914/src/com/github/ipk2015/coding2017/basic/test/QueueTest.java b/group24/121111914/src/com/github/ipk2015/coding2017/basic/test/QueueTest.java
new file mode 100644
index 0000000000..53c63d8564
--- /dev/null
+++ b/group24/121111914/src/com/github/ipk2015/coding2017/basic/test/QueueTest.java
@@ -0,0 +1,49 @@
+package com.github.ipk2015.coding2017.basic.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.github.ipk2015.coding2017.basic.Queue;
+
+public class QueueTest {
+ Queue queue;
+ @Before
+ public void setUp() throws Exception {
+ queue=new Queue();
+ }
+
+ @Test
+ public void testEnQueue() {
+ queue.enQueue("hehe1");
+ queue.enQueue("hehe2");
+ assertEquals(2, queue.size());
+ }
+
+ @Test
+ public void testDeQueue() {
+ queue.enQueue("hehe1");
+ queue.enQueue("hehe2");
+ queue.deQueue();
+ assertEquals(1, queue.size());
+ }
+
+ @Test
+ public void testIsEmpty() {
+ queue.enQueue("hehe1");
+ queue.enQueue("hehe2");
+ queue.deQueue();
+ queue.deQueue();
+ assertEquals(true, queue.isEmpty());
+ }
+
+ @Test
+ public void testSize() {
+ queue.enQueue("hehe1");
+ queue.enQueue("hehe2");
+ queue.deQueue();
+ assertEquals(1, queue.size());
+ }
+
+}
diff --git a/group24/121111914/src/com/github/ipk2015/coding2017/basic/test/StackTest.java b/group24/121111914/src/com/github/ipk2015/coding2017/basic/test/StackTest.java
new file mode 100644
index 0000000000..7cc10b77df
--- /dev/null
+++ b/group24/121111914/src/com/github/ipk2015/coding2017/basic/test/StackTest.java
@@ -0,0 +1,57 @@
+package com.github.ipk2015.coding2017.basic.test;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.github.ipk2015.coding2017.basic.Stack;
+
+public class StackTest {
+ Stack stack;
+ @Before
+ public void setUp() throws Exception {
+ stack=new Stack();
+ }
+
+ @Test
+ public void testPush() {
+ stack.push("hehe1");
+ stack.push("hehe2");
+ assertEquals(2,stack.size());
+ }
+
+ @Test
+ public void testPop() {
+ stack.push("hehe1");
+ stack.push("hehe2");
+ stack.push("hehe3");
+ assertEquals(true,stack.pop()=="hehe3" && stack.size()==2);
+ }
+
+ @Test
+ public void testPeek() {
+ stack.push("hehe1");
+ stack.push("hehe2");
+ stack.push("hehe3");
+ assertEquals(true,stack.peek()=="hehe3" && stack.size()==3);
+ }
+
+ @Test
+ public void testIsEmpty() {
+ stack.push("hehe1");
+ stack.push("hehe2");
+ stack.pop();
+ stack.pop();
+ assertEquals(true,stack.isEmpty());
+ }
+
+ @Test
+ public void testSize() {
+ stack.push("hehe1");
+ stack.push("hehe2");
+ stack.pop();
+ assertEquals(1,stack.size());
+ }
+
+}
From 9df1dd327d35716eacaaad14295e95fc6afea015 Mon Sep 17 00:00:00 2001
From: CJ-chen <120509419@qq.com>
Date: Sun, 12 Mar 2017 18:51:43 +0800
Subject: [PATCH 13/26] add Btree
---
.../coding2017/basic/BinaryTreeNode.java | 44 ++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)
diff --git a/group24/com/github/CJ-chen/coding2017/basic/BinaryTreeNode.java b/group24/com/github/CJ-chen/coding2017/basic/BinaryTreeNode.java
index 3adcc7040b..ff40538e64 100644
--- a/group24/com/github/CJ-chen/coding2017/basic/BinaryTreeNode.java
+++ b/group24/com/github/CJ-chen/coding2017/basic/BinaryTreeNode.java
@@ -40,6 +40,48 @@ public void setRight(BinaryTreeNode right) {
}
public BinaryTreeNode insert(Object o) {
- return null;
+ // 应该只需要实现这个就可以了
+ int curValue = (Integer) this.getData();
+ int insertValue = (Integer) o;
+
+ BinaryTreeNode newNode = new BinaryTreeNode();
+ newNode.setData(o);
+
+ if (curValue > insertValue) {
+ if (this.getLeft() != null) {
+ return this.getLeft().insert(o);
+ } else {
+ this.setLeft(newNode);
+ return this;
+ }
+ } else{
+ if (this.getRight() != null) {
+ return this.getRight().insert(o);
+ } else {
+ this.setRight(newNode);
+ return this;
+ }
+ }
+ }
+
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(this.getData()).append("\n");
+ sb.append(this.getLeft()).append("<--").append(this.getData()).append("\n");
+ sb.append(this.getData()).append("-->").append(this.getRight()).append("\n");
+ return sb.toString();
}
+
+ public static void main(String[] args) {
+ BinaryTreeNode btn = new BinaryTreeNode();
+ btn.setData(5);
+// btn.insert(5);
+ btn.insert(7);
+ btn.insert(8);
+ btn.insert(9);
+ btn.insert(4);
+
+ System.err.println(btn);
+ }
+
}
From 104bd9b3dc35590ec0bb7110ccd926e113f3944d Mon Sep 17 00:00:00 2001
From: likeleaf <893022254@qq.com>
Date: Sun, 12 Mar 2017 19:39:57 +0800
Subject: [PATCH 14/26] first commit
---
group24/893022254/task1-list/.gitignore | 5 +
.../src/com/oneflyingleaf/util/ArrayList.java | 106 +++++
.../oneflyingleaf/util/BinaryTreeNode.java | 57 +++
.../src/com/oneflyingleaf/util/Iterator.java | 7 +
.../com/oneflyingleaf/util/LinkedList.java | 380 ++++++++++++++++++
.../src/com/oneflyingleaf/util/List.java | 9 +
.../src/com/oneflyingleaf/util/Queue.java | 26 ++
.../src/com/oneflyingleaf/util/Stack.java | 23 ++
.../src/com/oneflyingleaf/util/TestClass.java | 115 ++++++
9 files changed, 728 insertions(+)
create mode 100644 group24/893022254/task1-list/.gitignore
create mode 100644 group24/893022254/task1-list/src/com/oneflyingleaf/util/ArrayList.java
create mode 100644 group24/893022254/task1-list/src/com/oneflyingleaf/util/BinaryTreeNode.java
create mode 100644 group24/893022254/task1-list/src/com/oneflyingleaf/util/Iterator.java
create mode 100644 group24/893022254/task1-list/src/com/oneflyingleaf/util/LinkedList.java
create mode 100644 group24/893022254/task1-list/src/com/oneflyingleaf/util/List.java
create mode 100644 group24/893022254/task1-list/src/com/oneflyingleaf/util/Queue.java
create mode 100644 group24/893022254/task1-list/src/com/oneflyingleaf/util/Stack.java
create mode 100644 group24/893022254/task1-list/src/com/oneflyingleaf/util/TestClass.java
diff --git a/group24/893022254/task1-list/.gitignore b/group24/893022254/task1-list/.gitignore
new file mode 100644
index 0000000000..166a44c4db
--- /dev/null
+++ b/group24/893022254/task1-list/.gitignore
@@ -0,0 +1,5 @@
+/.settings/
+/bin/
+.classpath
+.project
+
diff --git a/group24/893022254/task1-list/src/com/oneflyingleaf/util/ArrayList.java b/group24/893022254/task1-list/src/com/oneflyingleaf/util/ArrayList.java
new file mode 100644
index 0000000000..b584ffb99b
--- /dev/null
+++ b/group24/893022254/task1-list/src/com/oneflyingleaf/util/ArrayList.java
@@ -0,0 +1,106 @@
+package com.oneflyingleaf.util;
+
+import java.util.Arrays;
+
+public class ArrayList implements List {
+
+ //非线程安全
+ private int size = 0;
+
+ private Object[] elementData = new Object[100];
+
+ public void add(Object o){
+
+ checkLength(1);
+
+ elementData[ size ++] = o;
+ }
+
+
+ public void add(int index, Object o){
+ checkBound(index);
+
+ if(index != size){
+ checkLength(1);
+ }
+
+ int temp = index;
+
+ //index == size 不移动,直接放
+ while(index < size){
+ elementData[ ++ index ] = elementData[index];
+ }
+
+ size ++ ;
+ elementData[temp] = o;
+ }
+
+ public Object get(int index){
+ checkBound(index);
+
+ return elementData [index];
+ }
+
+ public Object remove(int index){
+ checkBound(index);
+
+ Object ret = elementData[index];
+ while(index < size){
+ elementData[index] = elementData[ ++ index];
+ }
+
+ -- size ;
+
+ return ret;
+ }
+
+ public int size(){
+ return size;
+ }
+
+ public Iterator iterator(){
+ return new ArrayListIterator();
+ }
+
+ /**
+ * 判断扩容
+ * @param length
+ */
+ private void checkLength(int length){
+ if( (size + length) > elementData.length){
+ //默认扩大一倍
+ Arrays.copyOf(elementData, elementData.length << 1);
+ }
+ }
+
+ /**
+ * 校验是否超出
+ * @param index
+ */
+ private void checkBound(int index){
+ if(index < 0 || index > size){
+ throw new IndexOutOfBoundsException("size : " + size +" , index : " + index);
+ }
+ }
+
+
+ private class ArrayListIterator implements Iterator{
+
+ private int count = -1;
+
+ private ArrayListIterator(){
+ }
+
+ @Override
+ public boolean hasNext() {
+ return (count+1) < size?true:false;
+ }
+
+ @Override
+ public Object next() {
+ count ++ ;
+ return elementData[count];
+ }
+
+ }
+}
diff --git a/group24/893022254/task1-list/src/com/oneflyingleaf/util/BinaryTreeNode.java b/group24/893022254/task1-list/src/com/oneflyingleaf/util/BinaryTreeNode.java
new file mode 100644
index 0000000000..4b1a92b1fb
--- /dev/null
+++ b/group24/893022254/task1-list/src/com/oneflyingleaf/util/BinaryTreeNode.java
@@ -0,0 +1,57 @@
+package com.oneflyingleaf.util;
+
+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){
+ if(! (o instanceof Comparable)){
+ throw new RuntimeException("未实现Comparable接口");
+ }
+ Comparable