From f73d49c80426482c72d60cc558e8ebae5a682941 Mon Sep 17 00:00:00 2001 From: Administrator Date: Thu, 23 Feb 2017 14:25:16 +0800 Subject: [PATCH 001/335] =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group20/423184723/src/{com/coding => }/basic/ArrayList.java | 0 group20/423184723/src/{com/coding => }/basic/BinaryTreeNode.java | 0 group20/423184723/src/{com/coding => }/basic/Iterator.java | 0 group20/423184723/src/{com/coding => }/basic/LinkedList.java | 0 group20/423184723/src/{com/coding => }/basic/List.java | 0 group20/423184723/src/{com/coding => }/basic/Queue.java | 0 group20/423184723/src/{com/coding => }/basic/Stack.java | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename group20/423184723/src/{com/coding => }/basic/ArrayList.java (100%) rename group20/423184723/src/{com/coding => }/basic/BinaryTreeNode.java (100%) rename group20/423184723/src/{com/coding => }/basic/Iterator.java (100%) rename group20/423184723/src/{com/coding => }/basic/LinkedList.java (100%) rename group20/423184723/src/{com/coding => }/basic/List.java (100%) rename group20/423184723/src/{com/coding => }/basic/Queue.java (100%) rename group20/423184723/src/{com/coding => }/basic/Stack.java (100%) diff --git a/group20/423184723/src/com/coding/basic/ArrayList.java b/group20/423184723/src/basic/ArrayList.java similarity index 100% rename from group20/423184723/src/com/coding/basic/ArrayList.java rename to group20/423184723/src/basic/ArrayList.java diff --git a/group20/423184723/src/com/coding/basic/BinaryTreeNode.java b/group20/423184723/src/basic/BinaryTreeNode.java similarity index 100% rename from group20/423184723/src/com/coding/basic/BinaryTreeNode.java rename to group20/423184723/src/basic/BinaryTreeNode.java diff --git a/group20/423184723/src/com/coding/basic/Iterator.java b/group20/423184723/src/basic/Iterator.java similarity index 100% rename from group20/423184723/src/com/coding/basic/Iterator.java rename to group20/423184723/src/basic/Iterator.java diff --git a/group20/423184723/src/com/coding/basic/LinkedList.java b/group20/423184723/src/basic/LinkedList.java similarity index 100% rename from group20/423184723/src/com/coding/basic/LinkedList.java rename to group20/423184723/src/basic/LinkedList.java diff --git a/group20/423184723/src/com/coding/basic/List.java b/group20/423184723/src/basic/List.java similarity index 100% rename from group20/423184723/src/com/coding/basic/List.java rename to group20/423184723/src/basic/List.java diff --git a/group20/423184723/src/com/coding/basic/Queue.java b/group20/423184723/src/basic/Queue.java similarity index 100% rename from group20/423184723/src/com/coding/basic/Queue.java rename to group20/423184723/src/basic/Queue.java diff --git a/group20/423184723/src/com/coding/basic/Stack.java b/group20/423184723/src/basic/Stack.java similarity index 100% rename from group20/423184723/src/com/coding/basic/Stack.java rename to group20/423184723/src/basic/Stack.java From d9e9ba4fb9eb1c70785e05efd8de02afe43783cd Mon Sep 17 00:00:00 2001 From: livenQiang Date: Thu, 23 Feb 2017 15:24:46 +0800 Subject: [PATCH 002/335] =?UTF-8?q?=E5=AE=8C=E6=88=90=E5=8D=95=E5=90=91?= =?UTF-8?q?=E9=93=BE=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liven/code/dataStructures/ArrayList.java | 16 ++- .../liven/code/dataStructures/LinkedList.java | 97 +++++++++++++++++-- 2 files changed, 102 insertions(+), 11 deletions(-) diff --git a/group20/286166752/src/wiki/liven/code/dataStructures/ArrayList.java b/group20/286166752/src/wiki/liven/code/dataStructures/ArrayList.java index 68444b87a9..1f5f07697f 100644 --- a/group20/286166752/src/wiki/liven/code/dataStructures/ArrayList.java +++ b/group20/286166752/src/wiki/liven/code/dataStructures/ArrayList.java @@ -9,7 +9,7 @@ public class ArrayList implements List{ * 列表中元素的个数 */ private int size = 0; - private int maxSize = 100; + private int maxSize = 10; /** * 初始数组 */ @@ -27,7 +27,9 @@ public class ArrayList implements List{ */ @Override public void add(int index, Object o) { - if (size>=maxSize){ + if(index<0||index>size-1) + throw new IndexOutOfBoundsException("数组下标越界异常。"); + if (size==maxSize){ Object[] targt = new Object[++maxSize]; System.arraycopy(elementData,0,targt,0,maxSize); for (int j = targt.length;j>=index;j--){ @@ -50,7 +52,7 @@ public void add(int index, Object o) { */ @Override public void add(Object o) { - if (size>=maxSize){ + if (size==maxSize){ Object[] targt = new Object[++maxSize]; System.arraycopy(elementData,0,targt,0,maxSize); targt[maxSize-1] = o; @@ -63,15 +65,21 @@ public void add(Object o) { @Override public Object get(int index) { - return elementData[index]; + if(index<0||index>size-1) + throw new IndexOutOfBoundsException("数组下标越界异常"); + Object o= elementData[index]; + return o; } @Override public Object remove(int index) { + if (index<0||index>size-1) + throw new IndexOutOfBoundsException("数组下表越界异常"); Object temp = elementData[index]; for (int i = index;i>size-1;i++){ elementData[i] = elementData[i+1]; } + size--; return temp; } diff --git a/group20/286166752/src/wiki/liven/code/dataStructures/LinkedList.java b/group20/286166752/src/wiki/liven/code/dataStructures/LinkedList.java index b2cc5f8668..52695305fb 100644 --- a/group20/286166752/src/wiki/liven/code/dataStructures/LinkedList.java +++ b/group20/286166752/src/wiki/liven/code/dataStructures/LinkedList.java @@ -5,36 +5,119 @@ */ public class LinkedList implements List{ - private Node head; + private Node head;//链表的头节点 + private Node tail;//链接的尾节点 + private int size;//定义了链表中的元素的个数 + /** + * 定义了NODE节点的数据结构 + */ private static class Node{ Object data; Node next; - } + private Node(){ + } + private Node(Object o,Node node){ + this.data = o; + this.next = node; + } + } + /** + * 在指定的索引写入新的节点 + * 1.找到给位置上的节点node0 + * 2.修改node0的next指向新的节点node + * 3.新节点node指向原先node0的后继节点node1 + * 4.长度++ + * 5.完结 + * @param index 索引 从0开始 + * @param o + */ @Override public void add(int index, Object o) { - + if (index<0||index>size-1) + throw new IndexOutOfBoundsException("单链表越界异常。"); + Node node = new Node(); + node.data = o; + Node nodeIndex = findNodeByIndex(index); + if(node==null) + throw new NullPointerException("空指针异常。"); + Node temp = nodeIndex.next; + nodeIndex.next = node; + node.next = temp; + size++; + } + + /** + * 根据索引号查询节点 + * @param index 索引 + * @return + */ + private Node findNodeByIndex(int index) { + if (index<0||index>size-1) + throw new IndexOutOfBoundsException("单链表越界异常。"); + Node current = head; + if (1<=index&&index<=size-1){//索引检查 + for (int i = 0;i>=size-1&¤t!=null;i++,current = current.next) + if (i==index){ + return current; + } + } + return null; } @Override public void add(Object o) { - + Node node = new Node(); + node.data = o; + if(head==null){ + head = node; + node.next = tail; + size++; + }else{ + Node temp = tail; + node.next = temp; + temp.next = node; + size++; + } } @Override public Object get(int index) { - return null; + if(index<0||index>size-1) + throw new IndexOutOfBoundsException("单链表越界。"); + Node node = findNodeByIndex(index); + if(node==null) + throw new NullPointerException("空指针异常。"); + return node.data; } + /** + * 删除指定索引的元素 + * @param index + * @return + */ @Override public Object remove(int index) { - return null; + if(index<0||index>size-1) + throw new IndexOutOfBoundsException("单链表越界。"); + Node node = findNodeByIndex(index); + if(node==null) + throw new NullPointerException("空指针异常。"); + Node prvNode = findNodeByIndex(index-1); + if(prvNode==null) + throw new NullPointerException("空指针异常。"); + Node nextNode = node.next; + node.next = null; + prvNode.next = nextNode; + size--; + return node.data; + } @Override public int size() { - return 0; + return size; } } From 7a73a9203c94017d5869e0503de530f97a08f143 Mon Sep 17 00:00:00 2001 From: mengxz <82427129@qq.com> Date: Thu, 23 Feb 2017 15:51:06 +0800 Subject: [PATCH 003/335] eclipse --- .../JavaUtil/src/main/java/com/coding/basic/LinkedList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/group17/82427129/JavaUtil/src/main/java/com/coding/basic/LinkedList.java b/group17/82427129/JavaUtil/src/main/java/com/coding/basic/LinkedList.java index f651ddabe0..5ea63d1903 100644 --- a/group17/82427129/JavaUtil/src/main/java/com/coding/basic/LinkedList.java +++ b/group17/82427129/JavaUtil/src/main/java/com/coding/basic/LinkedList.java @@ -12,7 +12,7 @@ public static int getFirst(LinkedList l){ } public void add(Object o){ - + add(size,o); } public void add(int index , Object o){ rangeCheck(index); From 795b2f7dd72da48d25eef9f2fb3070eeff97c820 Mon Sep 17 00:00:00 2001 From: SarahhLee <1059156023@qq.com> Date: Sat, 25 Feb 2017 12:16:28 +0800 Subject: [PATCH 004/335] a test --- group11/1059156023/.classpath | 6 ++++++ group11/1059156023/.gitignore | 1 + group11/1059156023/.project | 17 +++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 group11/1059156023/.classpath create mode 100644 group11/1059156023/.gitignore create mode 100644 group11/1059156023/.project diff --git a/group11/1059156023/.classpath b/group11/1059156023/.classpath new file mode 100644 index 0000000000..fb5011632c --- /dev/null +++ b/group11/1059156023/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/group11/1059156023/.gitignore b/group11/1059156023/.gitignore new file mode 100644 index 0000000000..ae3c172604 --- /dev/null +++ b/group11/1059156023/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/group11/1059156023/.project b/group11/1059156023/.project new file mode 100644 index 0000000000..6565014ef5 --- /dev/null +++ b/group11/1059156023/.project @@ -0,0 +1,17 @@ + + + 1059156023Learning + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + From 21e34d7f7c522c58d4872bfcb855f292059747a5 Mon Sep 17 00:00:00 2001 From: 2keaibsz <137845093@qq.com> Date: Sat, 25 Feb 2017 23:17:56 +0800 Subject: [PATCH 005/335] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=5F1519=5F137845093?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group15/1519_137845093/.classpath | 6 + group15/1519_137845093/.gitignore | 1 + group15/1519_137845093/.project | 17 ++ .../ArrayList.java | 117 ++++++++++++ .../BinaryTreeNode.java | 32 ++++ .../Iterator.java | 8 + .../LinkedList.java | 180 ++++++++++++++++++ .../src_1st_homework_1519_137845093/List.java | 9 + .../Queue.java | 29 +++ .../Stack.java | 39 ++++ 10 files changed, 438 insertions(+) create mode 100644 group15/1519_137845093/.classpath create mode 100644 group15/1519_137845093/.gitignore create mode 100644 group15/1519_137845093/.project create mode 100644 group15/1519_137845093/src_1st_homework_1519_137845093/ArrayList.java create mode 100644 group15/1519_137845093/src_1st_homework_1519_137845093/BinaryTreeNode.java create mode 100644 group15/1519_137845093/src_1st_homework_1519_137845093/Iterator.java create mode 100644 group15/1519_137845093/src_1st_homework_1519_137845093/LinkedList.java create mode 100644 group15/1519_137845093/src_1st_homework_1519_137845093/List.java create mode 100644 group15/1519_137845093/src_1st_homework_1519_137845093/Queue.java create mode 100644 group15/1519_137845093/src_1st_homework_1519_137845093/Stack.java diff --git a/group15/1519_137845093/.classpath b/group15/1519_137845093/.classpath new file mode 100644 index 0000000000..fceb4801b5 --- /dev/null +++ b/group15/1519_137845093/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/group15/1519_137845093/.gitignore b/group15/1519_137845093/.gitignore new file mode 100644 index 0000000000..ae3c172604 --- /dev/null +++ b/group15/1519_137845093/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/group15/1519_137845093/.project b/group15/1519_137845093/.project new file mode 100644 index 0000000000..7371704aff --- /dev/null +++ b/group15/1519_137845093/.project @@ -0,0 +1,17 @@ + + + helloworld + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/group15/1519_137845093/src_1st_homework_1519_137845093/ArrayList.java b/group15/1519_137845093/src_1st_homework_1519_137845093/ArrayList.java new file mode 100644 index 0000000000..e0ef246f9b --- /dev/null +++ b/group15/1519_137845093/src_1st_homework_1519_137845093/ArrayList.java @@ -0,0 +1,117 @@ +package com.coding.basic; + +import java.util.NoSuchElementException; + +public class ArrayList implements List { + //Ԫظ + private int size = 0; + //ʼΪ10 + private Object[] elementData = new Object[10]; + + public void add(Object o) { + int len = size + 1; + // жlistijǷ鳤 + if (len > elementData.length) { + // + Object[] newElemData = new Object[elementData.length + 1]; + // ƾԪص + System.arraycopy(elementData, 0, newElemData, 0, elementData.length); + elementData = newElemData; + } + elementData[size] = o; + size++; + } + + public void add(int index, Object o) { + // ±ǷԽ + if (index < 0 || index > size) { + throw new IndexOutOfBoundsException("index:" + index + "Խ磻" ); + } + // Ԫصĩβֱӵadd + if (index == size) { + add(o); + } else { + // + Object[] newElemData = new Object[elementData.length + 1]; + // indexǰԪص + System.arraycopy(elementData, 0, newElemData, 0, index); + newElemData[index] = o; + // index ԺԪص + System.arraycopy(elementData, index, newElemData, index + 1, size - index); + + elementData = newElemData; + size++; + } + } + + public Object get(int index) { + if (index < 0 || index >= size) { + throw new IndexOutOfBoundsException("index:" + index + "Խ磻"); + } + return elementData[index]; + } + + public Object remove(int index) { + //±鳤ȵģ׳쳣 + if (index >= size) { + throw new IndexOutOfBoundsException("index:" + index + "Խ磻"); + } + //indexһԪصֵҪɾ + if(index != (size-1)){ + // + Object[] newElemData = new Object[elementData.length]; + // indexǰԪص + System.arraycopy(elementData, 0, newElemData, 0, index); + // index ԺԪص + System.arraycopy(elementData, index+1, newElemData, index, size - index -1); + } + Object removeElement = elementData[index]; + //Сij + size--; + return removeElement; + } + + public int size() { + return size; + } + + public Iterator iterator() { + return new MyItr(this); + } + + private class MyItr implements Iterator { + private int l = -1; + private ArrayList array = null; + + private MyItr(ArrayList array) { + this.array = array; + } + + @Override + public boolean hasNext() { + return (l + 1) < array.size; + } + + @Override + public Object next() { + l++; + if (l >= array.size) { + l = array.size - 1 ; + throw new IndexOutOfBoundsException(); + } + + return array.get(l); + } + + @Override + public Object remove() { + if (l < 0) { + throw new NoSuchElementException(); + } + Object val = array.remove(l); + l--; + return val; + } + + } +} \ No newline at end of file diff --git a/group15/1519_137845093/src_1st_homework_1519_137845093/BinaryTreeNode.java b/group15/1519_137845093/src_1st_homework_1519_137845093/BinaryTreeNode.java new file mode 100644 index 0000000000..d7ac820192 --- /dev/null +++ b/group15/1519_137845093/src_1st_homework_1519_137845093/BinaryTreeNode.java @@ -0,0 +1,32 @@ +package com.coding.basic; + +public class BinaryTreeNode { + + private Object data; + private BinaryTreeNode left; + private BinaryTreeNode right; + + public Object getData() { + return data; + } + public void setData(Object data) { + this.data = data; + } + public BinaryTreeNode getLeft() { + return left; + } + public void setLeft(BinaryTreeNode left) { + this.left = left; + } + public BinaryTreeNode getRight() { + return right; + } + public void setRight(BinaryTreeNode right) { + this.right = right; + } + + public BinaryTreeNode insert(Object o){ + return null; + } + +} diff --git a/group15/1519_137845093/src_1st_homework_1519_137845093/Iterator.java b/group15/1519_137845093/src_1st_homework_1519_137845093/Iterator.java new file mode 100644 index 0000000000..2d4150183f --- /dev/null +++ b/group15/1519_137845093/src_1st_homework_1519_137845093/Iterator.java @@ -0,0 +1,8 @@ +package com.coding.basic; + +public interface Iterator { + public boolean hasNext(); + public Object next(); + public Object remove(); + +} diff --git a/group15/1519_137845093/src_1st_homework_1519_137845093/LinkedList.java b/group15/1519_137845093/src_1st_homework_1519_137845093/LinkedList.java new file mode 100644 index 0000000000..7f06138ec1 --- /dev/null +++ b/group15/1519_137845093/src_1st_homework_1519_137845093/LinkedList.java @@ -0,0 +1,180 @@ +package com.coding.basic; + +import java.util.NoSuchElementException; + +public class LinkedList implements List { + + private Node head; + private int size; + + public void add(Object o){ + //жûͷ + if(head == null) + head = new Node(o,null); + else { + Node newNode = head; + while(newNode.next != null){ + newNode = newNode.next; + } + newNode.next = new Node(o,null); + + } + + } + public void add(int index , Object o){ + //±ǷԽ + if(index < 0 || index > size){ + throw new IndexOutOfBoundsException("index:" + index + "Խ磻"); + } + Node node = head; + //ǵһͷ + if(index == 0){ + Node newNode = new Node(o,head); + head = newNode; + size ++; + } + else{ + for(int i = 1; i < index; i++){ + node = node.next; + } + //indexoҽonextڵΪnode.next + Node newNode = new Node(o, node.next); + node.next = newNode; + size++; + } +} + + public Object get(int index){ + //±ǷԽ + if(index < 0 || index > size){ + throw new IndexOutOfBoundsException("index:" + index + "Խ磻"); + } + Node node = head; + for (int i = 1; i <= index; i++) { + node = node.next; + } + return node.data; + } + + public Object remove(int index){ + //±ǷԽ + if(index < 0 || index > size){ + throw new IndexOutOfBoundsException("index:" + index + "Խ磻"); + } + Node node = head; + Node removeNode; + if (index == 0) { + //һڵֱӽͷڵָһڵ + removeNode = head; + head = head.next; + } + else { + //ҵֵǰһڵ + for (int i = 1; i < index; i++) { + node = node.next; + } + removeNode = node.next; + //ǰһڵָ룬ָɾڵָĽڵ + node.next = removeNode.next; + } + size--; + return removeNode.data; + } + + + public int size(){ + return size; + } + + public void addFirst(Object o){ + Node newNode = new Node(o, head.next); + head.next = newNode; + size++; + } + + public void addLast(Object o){ + add(o); + } + + public Object removeFirst(){ + if(size <= 0){ + throw new IndexOutOfBoundsException("ûԪأ"); + } + Node node = head; + head = head.next; + size--; + return node.data; + } + + public Object removeLast(){ + if(size <= 0){ + throw new IndexOutOfBoundsException("ûԪأ"); + } + Node node = head; + while(node.next != null){ + node = node.next; + } + Object val = node.data; + node = null; + size--; + return val; + } + private static class Node{ + Object data; + Node next; + + Node(Object data, Node next) { + this.data = data; + this.next = next; + + } + } + + + + + public Iterator iterator(){ + return new Itr(this); + } + + private class Itr implements Iterator{ + private int l = -1; + private LinkedList list; + private Itr(LinkedList linkedList) { + // TODO Auto-generated constructor stub + this.list = list; + + } + + @Override + public boolean hasNext() { + // TODO Auto-generated method stub + return l < list.size - 1; + } + + @Override + public Object next() { + // TODO Auto-generated method stub + l++; + if (l >= list.size) { + l--; + throw new IndexOutOfBoundsException(); + } + + return list.get(l); + } + + @Override + public Object remove() { + // TODO Auto-generated method stub + if (l < 0) { + throw new NoSuchElementException(); + } + Object val = list.removeLast(); + l--; + return val; + } + + } + + } diff --git a/group15/1519_137845093/src_1st_homework_1519_137845093/List.java b/group15/1519_137845093/src_1st_homework_1519_137845093/List.java new file mode 100644 index 0000000000..10d13b5832 --- /dev/null +++ b/group15/1519_137845093/src_1st_homework_1519_137845093/List.java @@ -0,0 +1,9 @@ +package com.coding.basic; + +public interface List { + public void add(Object o); + public void add(int index, Object o); + public Object get(int index); + public Object remove(int index); + public int size(); +} diff --git a/group15/1519_137845093/src_1st_homework_1519_137845093/Queue.java b/group15/1519_137845093/src_1st_homework_1519_137845093/Queue.java new file mode 100644 index 0000000000..3433125a8b --- /dev/null +++ b/group15/1519_137845093/src_1st_homework_1519_137845093/Queue.java @@ -0,0 +1,29 @@ +package com.coding.basic; +import java.util.NoSuchElementException; + +public class Queue { + private int size; + private LinkedList list = new LinkedList(); + + public void enQueue(Object o){ + list.addLast(o); + size++; + } + + public Object deQueue(){ + if(size<=0){ + throw new NoSuchElementException(); + } + Object deQueue = list.removeLast(); + size--; + return deQueue; + } + + public boolean isEmpty(){ + return (size>=0); + } + + public int size(){ + return size; + } +} diff --git a/group15/1519_137845093/src_1st_homework_1519_137845093/Stack.java b/group15/1519_137845093/src_1st_homework_1519_137845093/Stack.java new file mode 100644 index 0000000000..036baafc73 --- /dev/null +++ b/group15/1519_137845093/src_1st_homework_1519_137845093/Stack.java @@ -0,0 +1,39 @@ +package com.coding.basic; + +import java.util.NoSuchElementException; + +public class Stack { + private ArrayList elementData = new ArrayList(); + private int size; + private Object removeElement; + public void push(Object o){ + elementData.add(o); + size++; + } + + public Object pop(){ + if(size<=0){ + throw new NoSuchElementException(); + } + int l = size - 1; + removeElement = elementData.remove(l); + size--; + return removeElement; + } + + public Object peek(){ + if(size<=0){ + throw new NoSuchElementException(); + } + int len = size-1; + return elementData.get(len); + } + + public boolean isEmpty(){ + return (size>=0); + } + + public int size(){ + return size; + } +} From 18720d0e92169627c97fbe48704c6c58046cfb12 Mon Sep 17 00:00:00 2001 From: pwenhua Date: Sat, 25 Feb 2017 17:08:19 -0500 Subject: [PATCH 006/335] =?UTF-8?q?=E4=BA=8C=E5=8F=89=E6=A0=91=E6=9C=89?= =?UTF-8?q?=E5=BE=85=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataStructure/coding/basic/ArrayList.java | 71 ++++++++ .../coding/basic/BinaryTreeNode.java | 32 ++++ .../DataStructure/coding/basic/Iterator.java | 8 + .../coding/basic/LinkedList.java | 165 ++++++++++++++++++ .../DataStructure/coding/basic/List.java | 10 ++ .../DataStructure/coding/basic/Queue.java | 5 + .../DataStructure/coding/basic/Stack.java | 5 + 7 files changed, 296 insertions(+) create mode 100644 group20/2421586846/DataStructure/coding/basic/ArrayList.java create mode 100644 group20/2421586846/DataStructure/coding/basic/BinaryTreeNode.java create mode 100644 group20/2421586846/DataStructure/coding/basic/Iterator.java create mode 100644 group20/2421586846/DataStructure/coding/basic/LinkedList.java create mode 100644 group20/2421586846/DataStructure/coding/basic/List.java create mode 100644 group20/2421586846/DataStructure/coding/basic/Queue.java create mode 100644 group20/2421586846/DataStructure/coding/basic/Stack.java diff --git a/group20/2421586846/DataStructure/coding/basic/ArrayList.java b/group20/2421586846/DataStructure/coding/basic/ArrayList.java new file mode 100644 index 0000000000..e1ebaa2dc1 --- /dev/null +++ b/group20/2421586846/DataStructure/coding/basic/ArrayList.java @@ -0,0 +1,71 @@ +package basic; + +import java.util.Arrays; + +public class ArrayList implements List { + + private int size = 0; + + private Object[] elementData = new Object[100]; + + public void add(Object o){ + if (size< elementData.length) { + + } + else{ + Arrays.copyOf(elementData, elementData.length +1); + + } + size++; + elementData[size]=o; + + } + public void add(int index, Object o){ + if (index >= size || index < 0){ + return; + } + + if (size >= elementData.length) { + Arrays.copyOf(elementData, elementData.length +1); + } + + size++; + for (int i = elementData.length-1; i>index;i ++){ + elementData[i]=elementData[i-1]; + } + elementData[index]=o; + } + + public Object get(int index){ + if (index >= size || index < 0){ + return null; + } + else { + return elementData[index]; + } + + } + + public Object remove(int index){ + if (index >= size || index < 0){ + return null; + } + else { + Object o = elementData[index]; + for (int i =index; i< size-1; i++){ + elementData[i]= elementData[i+1]; + } + size--; + return o; + } + } + + public int size(){ + return size; + } + + public Iterator iterator(){ + return null; + } + +} diff --git a/group20/2421586846/DataStructure/coding/basic/BinaryTreeNode.java b/group20/2421586846/DataStructure/coding/basic/BinaryTreeNode.java new file mode 100644 index 0000000000..eac9e03e69 --- /dev/null +++ b/group20/2421586846/DataStructure/coding/basic/BinaryTreeNode.java @@ -0,0 +1,32 @@ +package 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/group20/2421586846/DataStructure/coding/basic/Iterator.java b/group20/2421586846/DataStructure/coding/basic/Iterator.java new file mode 100644 index 0000000000..223e2c3c41 --- /dev/null +++ b/group20/2421586846/DataStructure/coding/basic/Iterator.java @@ -0,0 +1,8 @@ +package basic; + + +public interface Iterator { + public boolean hasNext(); + public Object next(); + +} diff --git a/group20/2421586846/DataStructure/coding/basic/LinkedList.java b/group20/2421586846/DataStructure/coding/basic/LinkedList.java new file mode 100644 index 0000000000..bbb46917f9 --- /dev/null +++ b/group20/2421586846/DataStructure/coding/basic/LinkedList.java @@ -0,0 +1,165 @@ +package basic; + + +public class LinkedList implements List { + + private Node head; + + public void add(Object o){ + Node newNode= new Node(); + newNode.data = o; + newNode.next = null; + + if (head == null ){ + head= newNode; + } + + Node currentNode = head; + while (currentNode.next != null ){ + currentNode = currentNode.next ; + } + + + currentNode.next =newNode; + + } + public void add(int index , Object o){ + int oldSize = size(); + if (index >= oldSize ||index < 0) { + return; + } + + Node newNode= new Node(); + newNode.data = o; + Node PrevNode =null; + + if (index ==0 ){ + + Node tempNode = head ; + head = newNode; + newNode.next = tempNode; + + } + else { + Node currentNode = head; + for (int i=0; i = oldSize ||index < 0) { + return null; + } + Node currentNode = head; + for (int i=0; i = size ||index < 0) { + return null; + } + + Node currentNode = head; + if (index ==0 ){ + head =head.next; + return currentNode.data; + } + Node PrevNode = null; + for (int i=0; i Date: Sat, 25 Feb 2017 21:52:03 -0500 Subject: [PATCH 007/335] stack over --- .../DataStructure/coding/basic/Queue.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/group20/2421586846/DataStructure/coding/basic/Queue.java b/group20/2421586846/DataStructure/coding/basic/Queue.java index b3905f77de..1d003b75f2 100644 --- a/group20/2421586846/DataStructure/coding/basic/Queue.java +++ b/group20/2421586846/DataStructure/coding/basic/Queue.java @@ -1,5 +1,20 @@ package basic; public class Queue { - + private LinkedList elementData = new LinkedList(); + + public void enQueue(Object o){ + } + + public Object deQueue(){ + return null; + } + + public boolean isEmpty(){ + return false; + } + + public int size(){ + return -1; + } } From b791afcf167982af46a692e280326b69de6d2dc0 Mon Sep 17 00:00:00 2001 From: "pwh-PC\\pwh" Date: Sat, 25 Feb 2017 21:54:25 -0500 Subject: [PATCH 008/335] stack over --- .../DataStructure/coding/basic/Queue.java | 2 + .../DataStructure/coding/basic/Stack.java | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/group20/2421586846/DataStructure/coding/basic/Queue.java b/group20/2421586846/DataStructure/coding/basic/Queue.java index 1d003b75f2..f0e6741494 100644 --- a/group20/2421586846/DataStructure/coding/basic/Queue.java +++ b/group20/2421586846/DataStructure/coding/basic/Queue.java @@ -4,8 +4,10 @@ public class Queue { private LinkedList elementData = new LinkedList(); public void enQueue(Object o){ + elementData.add } + public Object deQueue(){ return null; } diff --git a/group20/2421586846/DataStructure/coding/basic/Stack.java b/group20/2421586846/DataStructure/coding/basic/Stack.java index 66436d0cd6..1b517aa3e8 100644 --- a/group20/2421586846/DataStructure/coding/basic/Stack.java +++ b/group20/2421586846/DataStructure/coding/basic/Stack.java @@ -1,5 +1,42 @@ package basic; + public class Stack { + private ArrayList elementData = new ArrayList(); + + public void push(Object o){ + elementData.add(o); + } + + public Object pop(){ + if (elementData.size()==0 ) + { + return null; + } + Object tempObj = elementData.remove(elementData.size()-1); + + return tempObj; + } + + public Object peek(){ + if (elementData.size()==0 ) + { + return null; + } + Object tempObj = elementData.get(elementData.size()-1); + return tempObj; + } + public boolean isEmpty(){ + if (elementData.size()==0 ) + { + return true; + } + else { + return false; + } + } + public int size(){ + return elementData.size(); + } } From d60807a981e100e496b649c0d2a8456e7429f331 Mon Sep 17 00:00:00 2001 From: "pwh-PC\\pwh" Date: Sat, 25 Feb 2017 22:08:45 -0500 Subject: [PATCH 009/335] stack over --- .../DataStructure/coding/basic/Queue.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/group20/2421586846/DataStructure/coding/basic/Queue.java b/group20/2421586846/DataStructure/coding/basic/Queue.java index f0e6741494..ce88d4712a 100644 --- a/group20/2421586846/DataStructure/coding/basic/Queue.java +++ b/group20/2421586846/DataStructure/coding/basic/Queue.java @@ -4,19 +4,26 @@ public class Queue { private LinkedList elementData = new LinkedList(); public void enQueue(Object o){ - elementData.add + elementData.addLast(o); } public Object deQueue(){ - return null; + Object tempObj =elementData.removeFirst(); + return tempObj; } public boolean isEmpty(){ - return false; + if (elementData.size()==0){ + + return true; + } + else { + return false; + } } public int size(){ - return -1; + return elementData.size(); } } From ec1d08774ec09bfdf651c25f5b491dc5af18f4da Mon Sep 17 00:00:00 2001 From: QQ-ing <932886072@qq.com> Date: Sun, 26 Feb 2017 14:03:51 +0800 Subject: [PATCH 010/335] Create 932886072 just for test --- group16/932886072 | 1 + 1 file changed, 1 insertion(+) create mode 100644 group16/932886072 diff --git a/group16/932886072 b/group16/932886072 new file mode 100644 index 0000000000..9daeafb986 --- /dev/null +++ b/group16/932886072 @@ -0,0 +1 @@ +test From 758fb4c72ec90d6fc9edb453ef29b2e8115fb323 Mon Sep 17 00:00:00 2001 From: Administrator Date: Sun, 26 Feb 2017 15:05:05 +0800 Subject: [PATCH 011/335] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group20/423184723/src/basic/ArrayList.java | 72 ++++++++++++++++++---- group20/423184723/src/basic/Queue.java | 18 ++++-- group20/423184723/src/basic/Stack.java | 21 +++++-- 3 files changed, 90 insertions(+), 21 deletions(-) diff --git a/group20/423184723/src/basic/ArrayList.java b/group20/423184723/src/basic/ArrayList.java index 1f185736f9..64a19bea8e 100644 --- a/group20/423184723/src/basic/ArrayList.java +++ b/group20/423184723/src/basic/ArrayList.java @@ -1,32 +1,78 @@ package com.coding.basic; +import com.sun.media.sound.EmergencySoundbank; + public class ArrayList implements List { - + /** + * 列表中元素的个数 + */ private int size = 0; - private Object[] elementData = new Object[100]; + /** + * 初始化数组大小 + */ + private int arraySize = 100; + /** + * 初始化数组 + */ + private Object[] elementData = new Object[arraySize]; + /** + * 添加方法 + */ public void add(Object o){ - + if(size>=(arraySize*0.75)){ + Object [] target = new Object[(int) (arraySize*1.5)]; + System.arraycopy(elementData,0,target,0,arraySize); + target[size-1] = o; + size++; + }else if(size<(arraySize*0.75)){ + elementData[size-1]=o; + size++; + } } + /** + * 根据索引添加方法 + */ public void add(int index, Object o){ - + if(size >= arraySize*0.75){ + Object [] target = new Object[(int) (arraySize*1.5)]; + System.arraycopy(elementData,0,target,0,arraySize); + for (int j = target.length;j>=index;j--){ + target[j-1] = target[j-2]; + } + target[index] = o; + size++; + }else if(size < arraySize*0.75){ + for (int j = elementData.length;j>=index;j--){ + elementData[j-1] = elementData[j-2]; + } + elementData[index] = o; + size++; + } } - + /** + * 根据索引获取对象 + */ public Object get(int index){ - return null; + return elementData[index]; } - + /** + * 根据索引移除对象 + */ public Object remove(int index){ - return null; + for (int i = index; i < elementData.length; i++) { + elementData[i]=elementData[i+1]; + size++; + } + return elementData[index]; } - + /** + * 获取数组大小 + */ public int size(){ - return -1; + return this.size; } - public Iterator iterator(){ - return null; - } } diff --git a/group20/423184723/src/basic/Queue.java b/group20/423184723/src/basic/Queue.java index 36e516e266..bb4e6bef5c 100644 --- a/group20/423184723/src/basic/Queue.java +++ b/group20/423184723/src/basic/Queue.java @@ -2,18 +2,28 @@ public class Queue { - public void enQueue(Object o){ + private LinkedList list = new LinkedList(); + public void enQueue(Object o){ + list.add(o); } public Object deQueue(){ - return null; + int length = list.size(); + if (length == 0) { + return null; + } + return list.removeFirst(); } public boolean isEmpty(){ - return false; + if (list.size() == 0) { + return true; + } else { + return false; + } } public int size(){ - return -1; + return list.size; } } diff --git a/group20/423184723/src/basic/Stack.java b/group20/423184723/src/basic/Stack.java index a5a04de76d..6f3def6f0f 100644 --- a/group20/423184723/src/basic/Stack.java +++ b/group20/423184723/src/basic/Stack.java @@ -4,19 +4,32 @@ public class Stack { private ArrayList elementData = new ArrayList(); public void push(Object o){ + elementData.add(o); } public Object pop(){ - return null; + int length = elementData.size(); + if (length == 0) { + return null; + } + return elementData.remove(length - 1); } public Object peek(){ - return null; + int length = elementData.size(); + if (length == 0) { + return null; + } + return elementData.get(length - 1); } public boolean isEmpty(){ - return false; + if (elementData.size() != 0) { + return false; + } else { + return true; + } } public int size(){ - return -1; + return elementData.size(); } } From fe6ccfb10acbd6347679a8074054e1600958250e Mon Sep 17 00:00:00 2001 From: Administrator Date: Sun, 26 Feb 2017 15:05:32 +0800 Subject: [PATCH 012/335] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Test/\345\215\232\345\256\242\345\234\260\345\235\200" | 1 + 1 file changed, 1 insertion(+) create mode 100644 "group20/423184723/Test/\345\215\232\345\256\242\345\234\260\345\235\200" diff --git "a/group20/423184723/Test/\345\215\232\345\256\242\345\234\260\345\235\200" "b/group20/423184723/Test/\345\215\232\345\256\242\345\234\260\345\235\200" new file mode 100644 index 0000000000..b5457af5b6 --- /dev/null +++ "b/group20/423184723/Test/\345\215\232\345\256\242\345\234\260\345\235\200" @@ -0,0 +1 @@ +http://www.cnblogs.com/yyssyh213/p/6442285.html \ No newline at end of file From 8bbd61959637dd284d08a44e1bf511f435dae029 Mon Sep 17 00:00:00 2001 From: Administrator Date: Sun, 26 Feb 2017 15:08:13 +0800 Subject: [PATCH 013/335] 123 --- .project | 11 ++ .settings/org.eclipse.core.resources.prefs | 2 + group20/423184723/src/basic/LinkedList.java | 118 ++++++++++++++++++-- 3 files changed, 122 insertions(+), 9 deletions(-) create mode 100644 .project create mode 100644 .settings/org.eclipse.core.resources.prefs diff --git a/.project b/.project new file mode 100644 index 0000000000..6b4d50ed9a --- /dev/null +++ b/.project @@ -0,0 +1,11 @@ + + + coding2017 + + + + + + + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000000..4824b80263 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/group20/423184723/src/basic/LinkedList.java b/group20/423184723/src/basic/LinkedList.java index e2c4e5e795..9caf065304 100644 --- a/group20/423184723/src/basic/LinkedList.java +++ b/group20/423184723/src/basic/LinkedList.java @@ -1,37 +1,131 @@ package com.coding.basic; +import com.coding.basic.LinkedList.Node; + public class LinkedList implements List { private Node head; + private int size; public void add(Object o){ - + if (head.data == null) { + head.data = o; + head.next = null; + size++; + return; + } + Node node = new Node(o); + Node curr = head; + while (curr.next != null) { + curr = curr.next; + } + curr.next = node; + size++; } public void add(int index , Object o){ - + if (index < 0 || index > size) { + System.out.println(index + "无效指数"); + return; + } + if (head.data == null) { + if (index == 0) { + head.data = o; + head.next = null; + size++; + return; + } else { + System.out.println("无效指数"); + return; + } + } + Node node = new Node(o); + Node curr = head; + for (int i = 0; i < index - 1; i++) { + curr = curr.next; + } + Node temp = curr.next; + curr.next = node; + node.next = temp; + size++; } public Object get(int index){ - return null; + if (index < 0 || index > size) { + System.out.println(index + " is invalid index!"); + return null; + } + Node result = head; + for (int i = 0; i < index; i++) { + result = result.next; + } + return result; } public Object remove(int index){ - return null; + if (index < 0 || index > size) { + System.out.println(index + " is invalid index!"); + return null; + } + Node curr = head; + for (int i = 0; i < index - 1; i++) { + curr = curr.next; + } + Node result = curr.next; + curr.next = curr.next.next; + size--; + return result; } public int size(){ - return -1; + return this.size; } public void addFirst(Object o){ - + if (head.data == null) { + head.data = o; + head.next = null; + size++; + return; + } + Node temp = head; + head = new Node(o); + head.next = temp; + size++; } public void addLast(Object o){ - + if (head.data == null) { + head.data = o; + head.next = null; + size++; + return; + } + Node node = new Node(o); + Node curr = head; + while (curr.next != null) { + curr = curr.next; + } + curr.next = node; + size++; } public Object removeFirst(){ - return null; + if (head.data == null) { + return null; + } + Node result = head; + head = head.next; + size--; + return result; } public Object removeLast(){ - return null; + if (head.data == null) { + return null; + } + Node curr = head; + for (int i = 0; i < size - 1; i++) { + curr = curr.next; + } + Node result = curr.next; + curr.next = null; + size--; + return result; } public Iterator iterator(){ return null; @@ -41,6 +135,12 @@ public Iterator iterator(){ private static class Node{ Object data; Node next; + public Node(Object o) { + data = o; + next = null; + } + + } } From a8dd0846b77eeeb0b5592318071b4ffe33355d83 Mon Sep 17 00:00:00 2001 From: shaofriend <452472201@qq.com> Date: Sun, 26 Feb 2017 15:43:00 +0800 Subject: [PATCH 014/335] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/SinglyLinkedList/LinkedList0.java | 75 ------ .../src/SinglyLinkedList2/LinkedList1.java | 242 ------------------ group20/286166752/.gitignore | 4 - .../liven/code/dataStructures/ArrayList.java | 86 ------- .../liven/code/dataStructures/LinkedList.java | 40 --- .../wiki/liven/code/dataStructures/List.java | 14 - .../wiki/liven/code/dataStructures/Queue.java | 7 - .../wiki/liven/code/dataStructures/Stack.java | 7 - .../src/wiki/liven/code/test/SomeDemos.java | 15 -- .../src/com/coding/basic/ArrayList.java | 32 --- .../src/com/coding/basic/BinaryTreeNode.java | 32 --- .../src/com/coding/basic/Iterator.java | 7 - .../src/com/coding/basic/LinkedList.java | 46 ---- .../423184723/src/com/coding/basic/List.java | 9 - .../423184723/src/com/coding/basic/Queue.java | 19 -- .../423184723/src/com/coding/basic/Stack.java | 22 -- .../src/com/coding/basic/ArrayList.java | 34 ++- .../src/com/coding/basic/LinkedList.java | 32 ++- .../452472201/src/com/coding/basic/Queue.java | 3 +- .../452472201/src/com/coding/basic/Stack.java | 27 +- ...2\345\256\242\351\223\276\346\216\245.txt" | 1 + 21 files changed, 70 insertions(+), 684 deletions(-) delete mode 100644 group20/1040154728/1040154728Learning/src/SinglyLinkedList/LinkedList0.java delete mode 100644 group20/1040154728/1040154728Learning/src/SinglyLinkedList2/LinkedList1.java delete mode 100644 group20/286166752/.gitignore delete mode 100644 group20/286166752/src/wiki/liven/code/dataStructures/ArrayList.java delete mode 100644 group20/286166752/src/wiki/liven/code/dataStructures/LinkedList.java delete mode 100644 group20/286166752/src/wiki/liven/code/dataStructures/List.java delete mode 100644 group20/286166752/src/wiki/liven/code/dataStructures/Queue.java delete mode 100644 group20/286166752/src/wiki/liven/code/dataStructures/Stack.java delete mode 100644 group20/286166752/src/wiki/liven/code/test/SomeDemos.java delete mode 100644 group20/423184723/src/com/coding/basic/ArrayList.java delete mode 100644 group20/423184723/src/com/coding/basic/BinaryTreeNode.java delete mode 100644 group20/423184723/src/com/coding/basic/Iterator.java delete mode 100644 group20/423184723/src/com/coding/basic/LinkedList.java delete mode 100644 group20/423184723/src/com/coding/basic/List.java delete mode 100644 group20/423184723/src/com/coding/basic/Queue.java delete mode 100644 group20/423184723/src/com/coding/basic/Stack.java create mode 100644 "group20/452472201/src/com/coding/basic/\345\215\232\345\256\242\351\223\276\346\216\245.txt" diff --git a/group20/1040154728/1040154728Learning/src/SinglyLinkedList/LinkedList0.java b/group20/1040154728/1040154728Learning/src/SinglyLinkedList/LinkedList0.java deleted file mode 100644 index 7cdf1e7f26..0000000000 --- a/group20/1040154728/1040154728Learning/src/SinglyLinkedList/LinkedList0.java +++ /dev/null @@ -1,75 +0,0 @@ -package SinglyLinkedList; - -/** - * Created by Honoka on 2/16/2017. - */ -public class LinkedList0 { - //Node class represents a list node - private class Node - { - String value; - Node next; - /** - * Constructor - * @param val The element to store in this node. - * @param n The reference to the next node. - */ - Node (String val, Node n) - { - value = val; - next = n; - } - - /** - * Constructor - * @param val The element to store in this node. - */ - Node(String val) - { - value = val; - next = null; - } - } - //Reference to the first node in the list - private Node first = null; - /** - * Constructor - * Builds a linked list - */ - public LinkedList0() - { - //test - first = new Node("Apple"); - first.next = new Node("Peach"); - first.next.next = new Node("Kiwi"); - first = new Node("Blueberry",first); - - //Using an array to add elements into list - String[] fruits = {"Banana", "Cherry"}; - for (String f : fruits) - { - first = new Node(f, first); - } - } - /** - * print method - * traverses the list and prints all elements - */ - public void print() - { - Node reference = first; - while(reference != null) - { - System.out.println(reference.value + " "); - reference = reference.next; - } - } - - //Main test method - public static void main(String [] args) - { - LinkedList0 list = new LinkedList0(); - System.out.println("The elements inside this list are "); - list.print(); - } -} diff --git a/group20/1040154728/1040154728Learning/src/SinglyLinkedList2/LinkedList1.java b/group20/1040154728/1040154728Learning/src/SinglyLinkedList2/LinkedList1.java deleted file mode 100644 index 8c93bbc640..0000000000 --- a/group20/1040154728/1040154728Learning/src/SinglyLinkedList2/LinkedList1.java +++ /dev/null @@ -1,242 +0,0 @@ -package SinglyLinkedList2; -/** - * Created by Honoka on 2/16/2017. - */ -public class LinkedList1 { - private class Node - { - String value; - Node next; - - Node(String val, Node n) - { - value = val; - next = n; - } - Node(String val) - { - //Call the other(daddy(or sister(whatever))) constructor. - this(val, null); - } - } - - private Node first; // head - private Node last; //the last element in list - - public LinkedList1() - { - first = null; - last = null; - } - - /**This method checks to see - * if the list is empty - * @return true if list is empty - */ - public boolean isEmpty() - { - return first == null; - } - - /** - * size method returns the length of the list - * @return The number of the elements in the list - */ - public int size() - { - int counter = 0; - Node p = first; - while (p != null) - { - counter ++; - p = p.next; - } - return counter; - } - - /** - * add method add an element to the end of the list - * @param element the value to add - */ - public void add(String element) - { - if (isEmpty()) - { - //Obviously, add the element to the first position in the list - first = new Node(element); - last = first; - } - else - { - //add to the end of existing list - last.next = new Node(element); - last = last.next; - } - } - - /** - * add method, or you might call it insert method since it can - * add element to a specific position - * @param index The position at which to add the element - * @param element you should know what is this - */ - public void add (int index, String element) - { - if (index < 0 || index > size()) - { - String message = String.valueOf(index); - throw new IndexOutOfBoundsException(message); - } - - //index is at least 0 - if(index == 0) - { - //new element add to the head - first = new Node(element, first); - if (last == null) - { - last = first; - } - return; - } - //set a reference predecessor to point to the node that - //will be the predecessor of the new node - Node predecessor = first; - for (int k = 1; k <= index - 1; k++) - { - predecessor = predecessor.next; - } - //Splice in a node containing the new element - predecessor.next = new Node(element, predecessor.next); - - //if there is a new last element - if(predecessor.next.next == null) - last = predecessor.next; - } - - /** - * toString method, like print method, hopefully it will display the contents of the list - * @return say something I'm giving up on you( - */ - public String toString() - { - StringBuffer strBuilder = new StringBuffer(); - //Use p to walk down the list - Node p = first; - while (p != null) - { - strBuilder.append(p.value + "\n"); - p = p.next; - } - return strBuilder.toString(); - } - - /** - * remove method removes the element with the position you want - * @param index the position of the element that you want to remove - * @return the removed element - */ - public String remove (int index) - { - /* Index out of bounds */ - if (index < 0 || index >= size()) - { - String message = String.valueOf(index); - throw new IndexOutOfBoundsException(message); - } - String element = null; - if(index == 0) - { - //Removal of first item in the list - element = first.value; - first = first.next; - if (first == null) - { - last = null; - } - } - else - { - /* find the predecessor of the element to be removed */ - Node predecessor = first; - - /* Move predecessor forward index - 1 times */ - for (int k = 1; k <= index - 1; k++) - { - predecessor = predecessor.next; - /* Store the value to return */ - element = predecessor.next.value; - /* Route link around the node to be removed */ - predecessor.next = predecessor.next.next; - /* Check if predecessor is now last */ - if(predecessor.next == null) - { - last = predecessor; - } - } - } - return element; - } - - /** - * The remove method removes an element - * @param element the element to remove - * @return true if the remove succeeded - */ - public boolean remove(String element) - { - if (isEmpty()) - { - return false; - } - - if (element.equals(first.value)) - { - //Removal of first element in the list - first = first.next; - if(first == null) - { - last = null; - } - return true; - } - - /* Find the predecessor of the element to remove */ - Node predecessor = first; - while (predecessor.next != null && - !predecessor.next.value.equals(element)) - { - predecessor = predecessor.next; - } - /* predecessor.next == null OR predecessor.next.value is element */ - if(predecessor.next == null) - { - return false; - } - /* predecessor.next.value is element */ - predecessor.next = predecessor.next.next; - - /* check if predecessor is now last */ - if (predecessor.next == null) - { - last = predecessor; - } - return true; - } - - public static void main (String [] args) - { - LinkedList1 testList = new LinkedList1(); - testList.add("Apple"); - testList.add("Banana"); - testList.add(0,"Blueberry"); - testList.add(2,"Cherry"); - testList.add(4,"Peach"); - System.out.println("The list has : "); - System.out.println(testList); - testList.remove("Cherry"); - testList.remove(2); - System.out.println("The list has : "); - System.out.println(testList); - } -} diff --git a/group20/286166752/.gitignore b/group20/286166752/.gitignore deleted file mode 100644 index d120d1749d..0000000000 --- a/group20/286166752/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.idea/ -286166752.iml -out/ - diff --git a/group20/286166752/src/wiki/liven/code/dataStructures/ArrayList.java b/group20/286166752/src/wiki/liven/code/dataStructures/ArrayList.java deleted file mode 100644 index 68444b87a9..0000000000 --- a/group20/286166752/src/wiki/liven/code/dataStructures/ArrayList.java +++ /dev/null @@ -1,86 +0,0 @@ -package wiki.liven.code.dataStructures; - -/** - * Created by leven on 2017/2/21. - */ -public class ArrayList implements List{ - - /** - * 列表中元素的个数 - */ - private int size = 0; - private int maxSize = 100; - /** - * 初始数组 - */ - private Object[] elementData = new Object[maxSize]; - - /** - * 在指定的位置i插入元素O - * 插入元素,判断当前列表中元素的个数, - * 当size==100,则需要扩张数组 - * 当size<100,则使用初始数组完成插入操作 - * 插入操作: - * 从最后一个元素开始,往后移动一位,直到到index为止. - * @param index - * @param o - */ - @Override - public void add(int index, Object o) { - if (size>=maxSize){ - Object[] targt = new Object[++maxSize]; - System.arraycopy(elementData,0,targt,0,maxSize); - for (int j = targt.length;j>=index;j--){ - targt[j-1] = targt[j-2]; - } - targt[index] = o; - size++; - }else if(size=index;j--){ - elementData[j-1] = elementData[j-2]; - } - elementData[index] = o; - size++; - } - } - - /** - * 追加元素 - * @param o - */ - @Override - public void add(Object o) { - if (size>=maxSize){ - Object[] targt = new Object[++maxSize]; - System.arraycopy(elementData,0,targt,0,maxSize); - targt[maxSize-1] = o; - size++; - }else if(sizesize-1;i++){ - elementData[i] = elementData[i+1]; - } - return temp; - } - - @Override - public int size() { - return size; - } - - - - -} diff --git a/group20/286166752/src/wiki/liven/code/dataStructures/LinkedList.java b/group20/286166752/src/wiki/liven/code/dataStructures/LinkedList.java deleted file mode 100644 index b2cc5f8668..0000000000 --- a/group20/286166752/src/wiki/liven/code/dataStructures/LinkedList.java +++ /dev/null @@ -1,40 +0,0 @@ -package wiki.liven.code.dataStructures; - -/** - * Created by leven on 2017/2/21. - */ -public class LinkedList implements List{ - - private Node head; - - private static class Node{ - Object data; - Node next; - } - - - @Override - public void add(int index, Object o) { - - } - - @Override - public void add(Object o) { - - } - - @Override - public Object get(int index) { - return null; - } - - @Override - public Object remove(int index) { - return null; - } - - @Override - public int size() { - return 0; - } -} diff --git a/group20/286166752/src/wiki/liven/code/dataStructures/List.java b/group20/286166752/src/wiki/liven/code/dataStructures/List.java deleted file mode 100644 index 2d1840ef0f..0000000000 --- a/group20/286166752/src/wiki/liven/code/dataStructures/List.java +++ /dev/null @@ -1,14 +0,0 @@ -package wiki.liven.code.dataStructures; - -/** - * Created by leven on 2017/2/21. - */ -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/group20/286166752/src/wiki/liven/code/dataStructures/Queue.java b/group20/286166752/src/wiki/liven/code/dataStructures/Queue.java deleted file mode 100644 index b8c8430daa..0000000000 --- a/group20/286166752/src/wiki/liven/code/dataStructures/Queue.java +++ /dev/null @@ -1,7 +0,0 @@ -package wiki.liven.code.dataStructures; - -/** - * Created by leven on 2017/2/21. - */ -public class Queue { -} diff --git a/group20/286166752/src/wiki/liven/code/dataStructures/Stack.java b/group20/286166752/src/wiki/liven/code/dataStructures/Stack.java deleted file mode 100644 index 59cb18c416..0000000000 --- a/group20/286166752/src/wiki/liven/code/dataStructures/Stack.java +++ /dev/null @@ -1,7 +0,0 @@ -package wiki.liven.code.dataStructures; - -/** - * Created by leven on 2017/2/21. - */ -public class Stack { -} diff --git a/group20/286166752/src/wiki/liven/code/test/SomeDemos.java b/group20/286166752/src/wiki/liven/code/test/SomeDemos.java deleted file mode 100644 index 90a74edc35..0000000000 --- a/group20/286166752/src/wiki/liven/code/test/SomeDemos.java +++ /dev/null @@ -1,15 +0,0 @@ -package wiki.liven.code.test; - -/** - * Created by leven on 2017/2/21. - */ -public class SomeDemos { - - public static void main(String[] args){ - int[] a = new int[10]; - a[0] = 4; - System.out.println(a.length); - - } - -} diff --git a/group20/423184723/src/com/coding/basic/ArrayList.java b/group20/423184723/src/com/coding/basic/ArrayList.java deleted file mode 100644 index 1f185736f9..0000000000 --- a/group20/423184723/src/com/coding/basic/ArrayList.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.coding.basic; - -public class ArrayList implements List { - - private int size = 0; - - private Object[] elementData = new Object[100]; - - public void add(Object o){ - - } - public void add(int index, Object o){ - - } - - public Object get(int index){ - return null; - } - - public Object remove(int index){ - return null; - } - - public int size(){ - return -1; - } - - public Iterator iterator(){ - return null; - } - -} diff --git a/group20/423184723/src/com/coding/basic/BinaryTreeNode.java b/group20/423184723/src/com/coding/basic/BinaryTreeNode.java deleted file mode 100644 index d7ac820192..0000000000 --- a/group20/423184723/src/com/coding/basic/BinaryTreeNode.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.coding.basic; - -public class BinaryTreeNode { - - private Object data; - private BinaryTreeNode left; - private BinaryTreeNode right; - - public Object getData() { - return data; - } - public void setData(Object data) { - this.data = data; - } - public BinaryTreeNode getLeft() { - return left; - } - public void setLeft(BinaryTreeNode left) { - this.left = left; - } - public BinaryTreeNode getRight() { - return right; - } - public void setRight(BinaryTreeNode right) { - this.right = right; - } - - public BinaryTreeNode insert(Object o){ - return null; - } - -} diff --git a/group20/423184723/src/com/coding/basic/Iterator.java b/group20/423184723/src/com/coding/basic/Iterator.java deleted file mode 100644 index 06ef6311b2..0000000000 --- a/group20/423184723/src/com/coding/basic/Iterator.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.coding.basic; - -public interface Iterator { - public boolean hasNext(); - public Object next(); - -} diff --git a/group20/423184723/src/com/coding/basic/LinkedList.java b/group20/423184723/src/com/coding/basic/LinkedList.java deleted file mode 100644 index e2c4e5e795..0000000000 --- a/group20/423184723/src/com/coding/basic/LinkedList.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.coding.basic; - -public class LinkedList implements List { - - private Node head; - - public void add(Object o){ - - } - public void add(int index , Object o){ - - } - public Object get(int index){ - return null; - } - public Object remove(int index){ - return null; - } - - public int size(){ - return -1; - } - - public void addFirst(Object o){ - - } - public void addLast(Object o){ - - } - public Object removeFirst(){ - return null; - } - public Object removeLast(){ - return null; - } - public Iterator iterator(){ - return null; - } - - - private static class Node{ - Object data; - Node next; - - } -} diff --git a/group20/423184723/src/com/coding/basic/List.java b/group20/423184723/src/com/coding/basic/List.java deleted file mode 100644 index 10d13b5832..0000000000 --- a/group20/423184723/src/com/coding/basic/List.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.coding.basic; - -public interface List { - public void add(Object o); - public void add(int index, Object o); - public Object get(int index); - public Object remove(int index); - public int size(); -} diff --git a/group20/423184723/src/com/coding/basic/Queue.java b/group20/423184723/src/com/coding/basic/Queue.java deleted file mode 100644 index 36e516e266..0000000000 --- a/group20/423184723/src/com/coding/basic/Queue.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.coding.basic; - -public class Queue { - - public void enQueue(Object o){ - } - - public Object deQueue(){ - return null; - } - - public boolean isEmpty(){ - return false; - } - - public int size(){ - return -1; - } -} diff --git a/group20/423184723/src/com/coding/basic/Stack.java b/group20/423184723/src/com/coding/basic/Stack.java deleted file mode 100644 index a5a04de76d..0000000000 --- a/group20/423184723/src/com/coding/basic/Stack.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.coding.basic; - -public class Stack { - private ArrayList elementData = new ArrayList(); - - public void push(Object o){ - } - - public Object pop(){ - return null; - } - - public Object peek(){ - return null; - } - public boolean isEmpty(){ - return false; - } - public int size(){ - return -1; - } -} diff --git a/group20/452472201/src/com/coding/basic/ArrayList.java b/group20/452472201/src/com/coding/basic/ArrayList.java index 1af26ce934..80746f1675 100644 --- a/group20/452472201/src/com/coding/basic/ArrayList.java +++ b/group20/452472201/src/com/coding/basic/ArrayList.java @@ -4,10 +4,9 @@ public class ArrayList implements List { private int size=0; - private Object[] elementData =new Object[10]; + private Object[] elementData =new Object[5]; - //数组扩容 private void ensureCapacityInternal(){ if(size==elementData.length){ Object[] newArray = new Object[size*2]; @@ -33,8 +32,8 @@ public void add(int index, Object o){ } System.arraycopy(elementData, index, elementData, index+1,size-index ); - elementData[index]=o; - size++; + elementData[index]=o; + size++; } public Object get(int index){ @@ -75,24 +74,41 @@ public int size(){ private class Iter implements Iterator { - //计数器 + private int coursor=-1; - //判断是否存在下一个 + public boolean hasNext(){ return coursor+1 Date: Sun, 26 Feb 2017 19:56:05 +0800 Subject: [PATCH 015/335] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 第一次作业提交 --- group17/516886559/ArrayList.java | 103 ++++++++++++++++++ group17/516886559/BinaryTreeNode.java | 68 ++++++++++++ group17/516886559/Iterator.java | 7 ++ group17/516886559/LinkedList.java | 150 ++++++++++++++++++++++++++ group17/516886559/List.java | 9 ++ group17/516886559/Queue.java | 30 ++++++ group17/516886559/Stack.java | 52 +++++++++ 7 files changed, 419 insertions(+) create mode 100644 group17/516886559/ArrayList.java create mode 100644 group17/516886559/BinaryTreeNode.java create mode 100644 group17/516886559/Iterator.java create mode 100644 group17/516886559/LinkedList.java create mode 100644 group17/516886559/List.java create mode 100644 group17/516886559/Queue.java create mode 100644 group17/516886559/Stack.java diff --git a/group17/516886559/ArrayList.java b/group17/516886559/ArrayList.java new file mode 100644 index 0000000000..75222aecce --- /dev/null +++ b/group17/516886559/ArrayList.java @@ -0,0 +1,103 @@ +package com.rd.p2p.common.util.liuxin; + +import java.util.Arrays; + +public class ArrayList implements List { + + private int size = 0; + + private Object[] elementData = new Object[10]; + + public void add(E o){ + if(size >= elementData.length){ + elementData = Arrays.copyOf(elementData, elementData.length * 2); + } + elementData[size++] = o; + size++; + } + + public void add(int index, E o){ + if(index > size){ + throw new ArrayIndexOutOfBoundsException("插入索引数不能大于数列总长度 " + index + ">" + size); + } + if(size >= elementData.length){ + elementData = Arrays.copyOf(elementData, elementData.length * 2); + } + Object[] tempData = Arrays.copyOfRange(elementData, index, size); + elementData[index] = o; + for(int i = 1; i <= tempData.length; i++){ + elementData[i+index] = tempData[i-1]; + } + size++; + + } + + public Object get(int index){ + if(index >= size){ + throw new ArrayIndexOutOfBoundsException("取出数组索引不能大于等于数组总长度 " + index + ">=" + size); + } + return elementData[index]; + } + + public Object remove(int index){ + if(index >= size){ + throw new ArrayIndexOutOfBoundsException("移除索引数不能大于等于数列总长度 " + index + ">=" + size); + } + Object data = get(index); + Object[] tempData = Arrays.copyOfRange(elementData, index+1, size); + for(int i = 0; i < tempData.length; i++){ + elementData[index+i] = tempData[i]; + } + elementData[size - 1] = null; + size--; + return data; + } + + public int size(){ + return size; + } + + @Override + public String toString() { + for (Object object : elementData) { + System.out.println(object); + } + return null; + } + + //迭代器 + public Iterator iterator(){ + return new Iterator() { + + private int index = 0; + + @Override + public Object next() { + if(index >= size){ + throw new ArrayIndexOutOfBoundsException("取出数组索引不能大于等于数组总长度 " + index + ">=" + size); + } + return get(index++); + } + + @Override + public boolean hasNext() { + if(size > index){ + return true; + }else{ + return false; + } + } + }; + } + + public static void main(String[] args) { + ArrayList list = new ArrayList(); + list.add(1); + list.add(2); + list.add(3,3); + Iterator in = list.iterator(); + while(in.hasNext()){ + System.out.println(in.next()); + } + } +} \ No newline at end of file diff --git a/group17/516886559/BinaryTreeNode.java b/group17/516886559/BinaryTreeNode.java new file mode 100644 index 0000000000..75c17d1198 --- /dev/null +++ b/group17/516886559/BinaryTreeNode.java @@ -0,0 +1,68 @@ +package com.rd.p2p.common.util.liuxin; + +/** + * 用Integer易于比较和插入 + * @author jhn + * time:2017年2月24日 + */ +public class BinaryTreeNode { + + private Integer data; + private BinaryTreeNode left; + private BinaryTreeNode right; + + public BinaryTreeNode(){ + + } + + public BinaryTreeNode(Integer integer){ + this.data = integer; + } + + public Integer getData() { + return data; + } + public void setData(Integer data) { + this.data = data; + } + public BinaryTreeNode getLeft() { + return left; + } + public void setLeft(BinaryTreeNode left) { + this.left = left; + } + public BinaryTreeNode getRight() { + return right; + } + public void setRight(BinaryTreeNode right) { + this.right = right; + } + + public BinaryTreeNode insert(Integer o){ + if(data == null){ + data = o; + return this; + } + BinaryTreeNode node = new BinaryTreeNode(o); + BinaryTreeNode tempBinaryTreeNode = this; + boolean begin = true; + while(begin){ + if(o < data){ + tempBinaryTreeNode = tempBinaryTreeNode.getLeft(); + if(tempBinaryTreeNode.getLeft() == null){ + tempBinaryTreeNode.setLeft(node); + begin = false;; + } + }else{ + tempBinaryTreeNode = tempBinaryTreeNode.getRight(); + if(tempBinaryTreeNode.getRight() == null){ + tempBinaryTreeNode.setRight(node); + begin = false;; + } + } + + } + return node; + } + +} diff --git a/group17/516886559/Iterator.java b/group17/516886559/Iterator.java new file mode 100644 index 0000000000..d29475ed43 --- /dev/null +++ b/group17/516886559/Iterator.java @@ -0,0 +1,7 @@ +package com.rd.p2p.common.util.liuxin; + +public interface Iterator { + public boolean hasNext(); + public Object next(); + +} diff --git a/group17/516886559/LinkedList.java b/group17/516886559/LinkedList.java new file mode 100644 index 0000000000..1b0345de7d --- /dev/null +++ b/group17/516886559/LinkedList.java @@ -0,0 +1,150 @@ +package com.rd.p2p.common.util.liuxin; + +public class LinkedList implements List { + + private Node head; + + private int size; + + public void add(E o){ + if(size == 0){ + head = new Node(); + head.data = o; + }else{ + Node node = new Node(); + node.data = o; + getNode(size-1).next = node; + } + size ++; + } + + public void add(int index , E o){ + Node node = new Node(); + node.data = o; + if(index == 0){ + node.next = head; + head = node; + }else{ + Node indexNode = getNode(index - 1); + indexNode.next = node; + if(index < size){ + node.next = getNode(index); + } + } + size ++; + } + + public Object get(int index){ + return getNode(index).data; + } + + public Object remove(int index){ + if(index > size - 1){ + throw new ArrayIndexOutOfBoundsException("移除索引超出数组索引边界 " + index + ">" + (size - 1)); + } + if(index < 0){ + throw new ArrayIndexOutOfBoundsException("索引不能为负数"); + } + Node returnNode = null; + if(index == 0){ + returnNode = head; + if(head.next != null){ + head = head.next; + }else{ + head = null; + } + }else{ + returnNode = getNode(index); + if(returnNode.next != null){ + Node preNode = getNode(index-1); + Node nextNode = getNode(index+1); + preNode.next = nextNode; + } + } + size--; + return returnNode.data; + } + + public int size(){ + return size; + } + + public void addFirst(E o){ + add(0,o); + } + + public void addLast(E o){ + add(size-1,o); + } + + public Object removeFirst(){ + return remove(0); + } + + public Object removeLast(){ + return remove(size - 1); + } + + private Node getNode(int index){ + if(index > size - 1){ + throw new ArrayIndexOutOfBoundsException("查询索引超出数组索引边界 " + index + ">" + (size - 1)); + } + if(index < 0){ + throw new ArrayIndexOutOfBoundsException("索引不能为负数"); + } + Node tempNode = head; + if(index == 0){ + tempNode = head; + }else{ + for(int i = 0; i < index; i++){ + tempNode = tempNode.next; + } + } + return tempNode; + } + + private static class Node{ + Object data; + Node next; + } + + @Override + public String toString() { + for (int i = 0; i < size; i++) { + System.out.println(get(i)); + } + return null; + } + + //迭代器 + public Iterator iterator(){ + return new Iterator() { + private int index = 0; + + @Override + public Object next() { + if(index >= size){ + throw new ArrayIndexOutOfBoundsException("取出数组索引不能大于等于数组总长度 " + index + ">=" + size); + } + return get(index++); + } + + @Override + public boolean hasNext() { + if(size > index){ + return true; + }else{ + return false; + } + } + }; + } + + public static void main(String[] args) { + LinkedList list = new LinkedList(); + list.add(1); + list.add(2); + list.add(3); + list.toString(); + } +} diff --git a/group17/516886559/List.java b/group17/516886559/List.java new file mode 100644 index 0000000000..fd6e7883ba --- /dev/null +++ b/group17/516886559/List.java @@ -0,0 +1,9 @@ +package com.rd.p2p.common.util.liuxin; + +public interface List { + public void add(E o); + public void add(int index, E o); + public Object get(int index); + public Object remove(int index); + public int size(); +} diff --git a/group17/516886559/Queue.java b/group17/516886559/Queue.java new file mode 100644 index 0000000000..d077a71a32 --- /dev/null +++ b/group17/516886559/Queue.java @@ -0,0 +1,30 @@ +package com.rd.p2p.common.util.liuxin; + +public class Queue { + + ArrayList arrayList = new ArrayList(); + + public void enQueue(T o){ + arrayList.add(o); + } + + public T deQueue(){ + if(arrayList.size() > 0){ + @SuppressWarnings("unchecked") + T t = (T) arrayList.get(0); + arrayList.remove(0); + return t; + }else{ + return null; + } + } + + public boolean isEmpty(){ + return arrayList.size() == 0 ? true : false; + } + + public int size(){ + return arrayList.size(); + } +} + diff --git a/group17/516886559/Stack.java b/group17/516886559/Stack.java new file mode 100644 index 0000000000..53ffc21e09 --- /dev/null +++ b/group17/516886559/Stack.java @@ -0,0 +1,52 @@ +package com.rd.p2p.common.util.liuxin; + +public class Stack { + + private ArrayList elementData = new ArrayList(); + + public void push(T o){ + elementData.add(o); + } + + public T pop(){ + if(elementData.size() > 0){ + @SuppressWarnings("unchecked") + T obj = (T)elementData.get(elementData.size()-1); + elementData.remove(elementData.size()-1); + return obj; + }else{ + return null; + } + } + + @SuppressWarnings("unchecked") + public T peek(){ + if(elementData.size() > 0){ + return (T)elementData.get(elementData.size()-1); + }else{ + return null; + } + } + public boolean isEmpty(){ + return elementData.size() == 0 ? true : false; + } + public int size(){ + return elementData.size(); + } + + public static void main(String[] args) { + Stack stack = new Stack(); + stack.push(1); + stack.push(2); + stack.push(3); + + System.out.println(stack.pop()); + System.out.println(stack.peek()); + System.out.println(stack.peek()); + System.out.println(stack.pop()); + System.out.println(stack.pop()); + System.out.println(stack.pop()); + System.out.println(stack.peek()); + } +} + From 44c0f95aab8cc674dfe61e961c5e55557202ba9c Mon Sep 17 00:00:00 2001 From: livenQiang Date: Sun, 26 Feb 2017 21:15:37 +0800 Subject: [PATCH 016/335] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=EF=BC=8C=E5=AE=8C=E6=88=90ArrayList=E7=9A=84=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../code/dataStructures/ArrayListTest.java | 89 +++++++++++++++++++ .../code/dataStructures/LinkedListTest.java | 35 ++++++++ .../liven/code/dataStructures/QueueTest.java | 24 +++++ .../liven/code/dataStructures/StackTest.java | 29 ++++++ .../liven/code/dataStructures/ArrayList.java | 28 +++--- .../wiki/liven/code/dataStructures/Queue.java | 57 ++++++++++++ .../wiki/liven/code/dataStructures/Stack.java | 55 ++++++++++++ .../src/wiki/liven/code/test/SomeDemos.java | 15 ---- 8 files changed, 307 insertions(+), 25 deletions(-) create mode 100644 group20/286166752/src/tests/wiki/liven/code/dataStructures/ArrayListTest.java create mode 100644 group20/286166752/src/tests/wiki/liven/code/dataStructures/LinkedListTest.java create mode 100644 group20/286166752/src/tests/wiki/liven/code/dataStructures/QueueTest.java create mode 100644 group20/286166752/src/tests/wiki/liven/code/dataStructures/StackTest.java delete mode 100644 group20/286166752/src/wiki/liven/code/test/SomeDemos.java diff --git a/group20/286166752/src/tests/wiki/liven/code/dataStructures/ArrayListTest.java b/group20/286166752/src/tests/wiki/liven/code/dataStructures/ArrayListTest.java new file mode 100644 index 0000000000..05df91c901 --- /dev/null +++ b/group20/286166752/src/tests/wiki/liven/code/dataStructures/ArrayListTest.java @@ -0,0 +1,89 @@ +package wiki.liven.code.dataStructures; + +import org.junit.Before; +import org.junit.Test; + + +/** + * Created by leven on 2017/2/26. + */ +public class ArrayListTest { + + private ArrayList arrayList; + + + @Before + public void init(){ + arrayList = new ArrayList(); + } + + + @Test + public void add() throws Exception { + arrayList.add("梅子黄时雨"); + arrayList.add("行下一首歌"); + arrayList.add("AmberTseng"); + arrayList.add("梅子黄时雨"); + arrayList.add("行下一首歌"); + arrayList.add("AmberTseng"); + arrayList.add("梅子黄时雨"); + arrayList.add("行下一首歌"); + arrayList.add("AmberTseng"); + arrayList.add("梅子黄时雨"); + arrayList.add("行下一首歌"); + arrayList.add("AmberTseng"); + System.out.println(arrayList.toString()); + } + + @Test + public void add1() throws Exception { + arrayList.add("梅子黄时雨"); + arrayList.add("行下一首歌"); + System.out.println(arrayList.size()); + arrayList.add(1,"星际游侠"); + System.out.println(arrayList.toString()); + } + + @Test + public void get() throws Exception { + arrayList.add("梅子黄时雨"); + arrayList.add("行下一首歌"); + arrayList.add("AmberTseng"); + arrayList.add("梅子黄时雨"); + arrayList.add("行下一首歌"); + arrayList.add("AmberTseng"); + arrayList.add("梅子黄时雨"); + arrayList.add("行下一首歌"); + arrayList.add("AmberTseng"); + arrayList.add("梅子黄时雨"); + arrayList.add("行下一首歌"); + arrayList.add("AmberTseng"); + System.out.println(arrayList.get(1)); + } + + @Test + public void remove() throws Exception { + arrayList.add("梅子黄时雨"); + arrayList.add("行下一首歌"); + System.out.println(arrayList.remove(1)); + System.out.println(arrayList.toString()); + } + + @Test + public void size() throws Exception { + arrayList.add("梅子黄时雨"); + arrayList.add("行下一首歌"); + arrayList.add("AmberTseng"); + arrayList.add("梅子黄时雨"); + arrayList.add("行下一首歌"); + arrayList.add("AmberTseng"); + arrayList.add("梅子黄时雨"); + arrayList.add("行下一首歌"); + arrayList.add("AmberTseng"); + arrayList.add("梅子黄时雨"); + arrayList.add("行下一首歌"); + arrayList.add("AmberTseng"); + System.out.println(arrayList.size()); + } + +} \ No newline at end of file diff --git a/group20/286166752/src/tests/wiki/liven/code/dataStructures/LinkedListTest.java b/group20/286166752/src/tests/wiki/liven/code/dataStructures/LinkedListTest.java new file mode 100644 index 0000000000..546929b64c --- /dev/null +++ b/group20/286166752/src/tests/wiki/liven/code/dataStructures/LinkedListTest.java @@ -0,0 +1,35 @@ +package wiki.liven.code.dataStructures; + +import org.junit.Test; + + +/** + * Created by leven on 2017/2/26. + */ +public class LinkedListTest { + @Test + public void add() throws Exception { + + } + + @Test + public void add1() throws Exception { + + } + + @Test + public void get() throws Exception { + + } + + @Test + public void remove() throws Exception { + + } + + @Test + public void size() throws Exception { + + } + +} \ No newline at end of file diff --git a/group20/286166752/src/tests/wiki/liven/code/dataStructures/QueueTest.java b/group20/286166752/src/tests/wiki/liven/code/dataStructures/QueueTest.java new file mode 100644 index 0000000000..464cd87205 --- /dev/null +++ b/group20/286166752/src/tests/wiki/liven/code/dataStructures/QueueTest.java @@ -0,0 +1,24 @@ +package wiki.liven.code.dataStructures; + +import org.junit.Test; + +/** + * Created by leven on 2017/2/26. + */ +public class QueueTest { + @Test + public void queueEmpty() throws Exception { + + } + + @Test + public void enQueue() throws Exception { + + } + + @Test + public void deQueue() throws Exception { + + } + +} \ No newline at end of file diff --git a/group20/286166752/src/tests/wiki/liven/code/dataStructures/StackTest.java b/group20/286166752/src/tests/wiki/liven/code/dataStructures/StackTest.java new file mode 100644 index 0000000000..ce4eb6e94f --- /dev/null +++ b/group20/286166752/src/tests/wiki/liven/code/dataStructures/StackTest.java @@ -0,0 +1,29 @@ +package wiki.liven.code.dataStructures; + +import org.junit.Test; + +/** + * Created by leven on 2017/2/26. + */ +public class StackTest { + @Test + public void push() throws Exception { + + } + + @Test + public void pop() throws Exception { + + } + + @Test + public void getTop() throws Exception { + + } + + @Test + public void stackEmpty() throws Exception { + + } + +} \ No newline at end of file diff --git a/group20/286166752/src/wiki/liven/code/dataStructures/ArrayList.java b/group20/286166752/src/wiki/liven/code/dataStructures/ArrayList.java index 1f5f07697f..c98c5b43a2 100644 --- a/group20/286166752/src/wiki/liven/code/dataStructures/ArrayList.java +++ b/group20/286166752/src/wiki/liven/code/dataStructures/ArrayList.java @@ -1,5 +1,7 @@ package wiki.liven.code.dataStructures; +import java.util.Arrays; + /** * Created by leven on 2017/2/21. */ @@ -31,15 +33,16 @@ public void add(int index, Object o) { throw new IndexOutOfBoundsException("数组下标越界异常。"); if (size==maxSize){ Object[] targt = new Object[++maxSize]; - System.arraycopy(elementData,0,targt,0,maxSize); - for (int j = targt.length;j>=index;j--){ - targt[j-1] = targt[j-2]; + System.arraycopy(elementData,0,targt,0,elementData.length); + for (int j = targt.length-2;j>=index;j--){ + targt[j+1] = targt[j]; } targt[index] = o; size++; + elementData = targt; }else if(size=index;j--){ - elementData[j-1] = elementData[j-2]; + for (int j = size-1;j>=index;j--){ + elementData[j+1] = elementData[j]; } elementData[index] = o; size++; @@ -54,11 +57,12 @@ public void add(int index, Object o) { public void add(Object o) { if (size==maxSize){ Object[] targt = new Object[++maxSize]; - System.arraycopy(elementData,0,targt,0,maxSize); + System.arraycopy(elementData,0,targt,0,elementData.length); targt[maxSize-1] = o; size++; + elementData = targt; }else if(sizesize-1) throw new IndexOutOfBoundsException("数组下表越界异常"); Object temp = elementData[index]; - for (int i = index;i>size-1;i++){ + for (int i = index;i<=size-1;i++){ elementData[i] = elementData[i+1]; } size--; @@ -89,6 +93,10 @@ public int size() { } - - + @Override + public String toString() { + return "ArrayList{" + + "elementData=" + Arrays.toString(elementData) + + '}'; + } } diff --git a/group20/286166752/src/wiki/liven/code/dataStructures/Queue.java b/group20/286166752/src/wiki/liven/code/dataStructures/Queue.java index b8c8430daa..d52c0de6f5 100644 --- a/group20/286166752/src/wiki/liven/code/dataStructures/Queue.java +++ b/group20/286166752/src/wiki/liven/code/dataStructures/Queue.java @@ -2,6 +2,63 @@ /** * Created by leven on 2017/2/21. + * 队列 + * 只允许一端进行出队操作,另一端进行入队操作。 + * 特性是:先进先出 + * 本质上是一种操作受限制的线性表 + * 本实现线性表采用自己实现的ArrayList, + * ArrayList理论上会受到JVM分配的内存大小,从而其空间会有上限。 + * 但是,该错误,将有JVM抛出。 + * 所以,本实现,队列忽略执行判断满队操作。 */ public class Queue { + + private ArrayList list; + private int head;//队头指针 + private int foot;//队尾指针 + + + public Queue(){ + head = foot = 0; + } + + /** + * 判空 + * @return + */ + public boolean queueEmpty(){ + if (head==0&&foot==0){ + return true; + }else { + return false; + } + } + + /** + * 入队列 + * 1.先把元素放置到队列中 + * 2.将队尾指针加1 + * @param o + */ + public void enQueue(Object o){ + list.add(foot,o); + foot++; + } + + /** + * 删除队头元素 + * 0.先判断队列是否为空 + * 1.先取出队头的元素 + * 2.然后将队头的指针加1 + * @return + */ + public int deQueue(){ + if (queueEmpty()==true) + throw new IndexOutOfBoundsException("队列为空,无法执行该操作。"); + list.remove(head); + return head++; + } + + + } diff --git a/group20/286166752/src/wiki/liven/code/dataStructures/Stack.java b/group20/286166752/src/wiki/liven/code/dataStructures/Stack.java index 59cb18c416..cc33ed2985 100644 --- a/group20/286166752/src/wiki/liven/code/dataStructures/Stack.java +++ b/group20/286166752/src/wiki/liven/code/dataStructures/Stack.java @@ -2,6 +2,61 @@ /** * Created by leven on 2017/2/21. + * 栈:只允许在一端进行删除或者增加操作的线性表。 + * 本实现,采用ArrayList。 */ public class Stack { + + + private ArrayList list;//线性表 + private int top = -1;//栈顶指针,默认指向栈低 + + + /** + * 元素进栈 + * @param o + * 1.指针先加1 + * 2.将元素放入栈中 + * + */ + public void push(Object o){ + top++; + list.add(o); + } + + /** + * 栈顶元素出栈,返回栈顶指针的值 + * @return + */ + public int pop(){ + if (top==-1) + throw new IndexOutOfBoundsException("栈为空,无法执行出栈操作。"); + list.remove(top); + top--; + return top; + } + + /** + * 获取栈顶元素的值 + * @return + */ + public Object getTop() { + if (top==-1) + throw new IndexOutOfBoundsException("栈为空,无法执行出栈操作。"); + Object o = list.get(top); + return o; + } + + /** + * 判空 + * @return + */ + public boolean stackEmpty(){ + if (top==-1){ + return true; + }else { + return false; + } + } + } diff --git a/group20/286166752/src/wiki/liven/code/test/SomeDemos.java b/group20/286166752/src/wiki/liven/code/test/SomeDemos.java deleted file mode 100644 index 90a74edc35..0000000000 --- a/group20/286166752/src/wiki/liven/code/test/SomeDemos.java +++ /dev/null @@ -1,15 +0,0 @@ -package wiki.liven.code.test; - -/** - * Created by leven on 2017/2/21. - */ -public class SomeDemos { - - public static void main(String[] args){ - int[] a = new int[10]; - a[0] = 4; - System.out.println(a.length); - - } - -} From 1a56267749758db44c0eb90e0d17b735103bc034 Mon Sep 17 00:00:00 2001 From: shane Date: Sun, 26 Feb 2017 22:16:47 +0800 Subject: [PATCH 017/335] add BinaryTreeNode, update all Test --- .../src/com/coding/basic/BinaryTreeNode.java | 60 ++++++++++++++++++- .../src/test/coding/basic/AbstractTest.java | 5 ++ .../test/coding/basic/BinaryTreeNodeTest.java | 32 ++++++++++ 3 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 group16/214074094/src/test/coding/basic/BinaryTreeNodeTest.java diff --git a/group16/214074094/src/com/coding/basic/BinaryTreeNode.java b/group16/214074094/src/com/coding/basic/BinaryTreeNode.java index b40066ebe1..32417cb157 100644 --- a/group16/214074094/src/com/coding/basic/BinaryTreeNode.java +++ b/group16/214074094/src/com/coding/basic/BinaryTreeNode.java @@ -1,5 +1,11 @@ package coding.basic; +/** + * @Author shane + * @Time 2017/2/26 19:30 + * @Email stevenchenguang@gmail.com + * @Desc Own BinaryTreeNode + */ public class BinaryTreeNode { private Object data; @@ -8,6 +14,31 @@ public class BinaryTreeNode { private BinaryTreeNode right; + public BinaryTreeNode insert(Object o) { + if (null == data) { + data = o; + } else { + if (bigger(data, o)) { + if (null == left) { + left = new BinaryTreeNode(); + left.data = o; + } else { + left.insert(o); + } + } else if (smaller(data, o)) { + if (null == right) { + right = new BinaryTreeNode(); + right.data = o; + } else { + right.insert(o); + } + } else { + throw new RuntimeException("The value has exists"); + } + } + return this; + } + public Object getData() { return data; } @@ -32,8 +63,33 @@ public void setRight(BinaryTreeNode right) { this.right = right; } - public BinaryTreeNode insert(Object o) { - return null; + private boolean bigger(Object data1, Object data2) { + return data1.toString().compareTo(data2.toString()) > 0; + } + + private boolean smaller(Object data1, Object data2) { + return data1.toString().compareTo(data2.toString()) < 0; } + private ArrayList list = new ArrayList(); + + /** + * 对二叉树进行遍历 结果存储到list中 + */ + private void sort(BinaryTreeNode node) { + + list.add(node.data); + if(null != node.left){ + sort(node.left); + } + if(null != node.right){ + sort(node.right); + } + } + + @Override + public String toString() { + sort(this); + return list.toString(); + } } diff --git a/group16/214074094/src/test/coding/basic/AbstractTest.java b/group16/214074094/src/test/coding/basic/AbstractTest.java index 80eaaa6fe5..c0a7089660 100644 --- a/group16/214074094/src/test/coding/basic/AbstractTest.java +++ b/group16/214074094/src/test/coding/basic/AbstractTest.java @@ -1,5 +1,7 @@ package coding.basic; +import com.alibaba.fastjson.JSON; + /** * @Author shane * @Time 2017/2/25 13:06 @@ -16,4 +18,7 @@ protected void printHyphen() { System.out.println("--------------------------------------------"); } + protected void printJson(Object obj) { + System.out.println(JSON.toJSONString(obj)); + } } diff --git a/group16/214074094/src/test/coding/basic/BinaryTreeNodeTest.java b/group16/214074094/src/test/coding/basic/BinaryTreeNodeTest.java new file mode 100644 index 0000000000..bd0f152820 --- /dev/null +++ b/group16/214074094/src/test/coding/basic/BinaryTreeNodeTest.java @@ -0,0 +1,32 @@ +package coding.basic; + +import org.junit.Test; + +/** + * @Author shane + * @Time 2017/2/26 19:57 + * @Email shanbaohua@lxfintech.com + * @Desc ... + */ +public class BinaryTreeNodeTest extends AbstractTest { + + @Test + public void test(){ + BinaryTreeNode node = new BinaryTreeNode(); + node.insert(8); + node.insert(5); + node.insert(9); + node.insert(1); + node.insert(6); + node.insert(11); + node.insert(10); + node.insert(15); + node.insert(13); + node.insert(19); + + printStar(); + System.out.println(node.getData()); + System.out.println(node); + printStar(); + } +} From 00b592b921c5e59f699802f5dcdcd53a699ee187 Mon Sep 17 00:00:00 2001 From: greenhills <63912401@qq.com> Date: Sun, 26 Feb 2017 22:34:15 +0800 Subject: [PATCH 018/335] 63912401 --- group16/63912401/.classpath | 6 + group16/63912401/.gitignore | 1 + group16/63912401/.project | 17 + .../src/com/coding/basic/ArrayList.java | 192 +++++++++++ .../src/com/coding/basic/BinaryTreeNode.java | 99 ++++++ .../src/com/coding/basic/Iterator.java | 8 + .../src/com/coding/basic/LinkedList.java | 320 ++++++++++++++++++ .../63912401/src/com/coding/basic/List.java | 16 + .../63912401/src/com/coding/basic/Queue.java | 43 +++ .../63912401/src/com/coding/basic/Stack.java | 51 +++ 10 files changed, 753 insertions(+) create mode 100644 group16/63912401/.classpath create mode 100644 group16/63912401/.gitignore create mode 100644 group16/63912401/.project create mode 100644 group16/63912401/src/com/coding/basic/ArrayList.java create mode 100644 group16/63912401/src/com/coding/basic/BinaryTreeNode.java create mode 100644 group16/63912401/src/com/coding/basic/Iterator.java create mode 100644 group16/63912401/src/com/coding/basic/LinkedList.java create mode 100644 group16/63912401/src/com/coding/basic/List.java create mode 100644 group16/63912401/src/com/coding/basic/Queue.java create mode 100644 group16/63912401/src/com/coding/basic/Stack.java diff --git a/group16/63912401/.classpath b/group16/63912401/.classpath new file mode 100644 index 0000000000..10c33642b2 --- /dev/null +++ b/group16/63912401/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/group16/63912401/.gitignore b/group16/63912401/.gitignore new file mode 100644 index 0000000000..ae3c172604 --- /dev/null +++ b/group16/63912401/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/group16/63912401/.project b/group16/63912401/.project new file mode 100644 index 0000000000..b6d8ce6204 --- /dev/null +++ b/group16/63912401/.project @@ -0,0 +1,17 @@ + + + coding2017 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/group16/63912401/src/com/coding/basic/ArrayList.java b/group16/63912401/src/com/coding/basic/ArrayList.java new file mode 100644 index 0000000000..a8d16b49a5 --- /dev/null +++ b/group16/63912401/src/com/coding/basic/ArrayList.java @@ -0,0 +1,192 @@ +package com.coding.basic; + +import java.util.Arrays; + +/** + * ArrayList + * @author greenhills + * @version 创建时间:2017年2月19日 下午10:54:02 + * @param + * + */ +public class ArrayList implements List { + /** + * 默认容量 + */ + private static final int DEFAULT_CAPACITY = 10; + + /** + * 数据存放区 + */ + private Object[] elementData; + + /** + * 真实的数据数量 + */ + private int size = 0; + + /** + * 无参构造函数 + */ + public ArrayList(){ + this.elementData=new Object[DEFAULT_CAPACITY]; + } + + /** + * 带初始大小的构造函数 + * @param beginSize + */ + public ArrayList(int beginSize){ + if(beginSize<0) + this.elementData=new Object[DEFAULT_CAPACITY]; + else + this.elementData=new Object[beginSize]; + } + + /** + * 在后面追加数据 + */ + @Override + public void add(Object o){ + autoGrow(size+1); + this.elementData[size++] = o; //在尾部追加数据 + } + + /** + * 把数据加入指定索引处 + */ + @Override + public void add(int index, Object o){ + rangeCheck(index); + autoGrow(size+1); + //把index处的所有数据往后移 + //System.arraycopy(elementData, index, elementData, index+1, size-index); + + for(int i=size;i>index;i--){ + elementData[i] = elementData[i-1]; + } + + this.elementData[index] = o; //使数据连续加入 + size++; + } + + /** + * 获取指定索引处的数据 + */ + @Override + public Object get(int index){ + rangeCheck(index); + return elementData[index]; + } + + /** + * 移除索引处数据 + */ + @Override + public Object remove(int index){ + rangeCheck(index); + + Object removed = elementData[index]; + int num=size - index - 1; //移动数量 + if(num>0) { + System.arraycopy(elementData, index+1, elementData, index,num); + } + elementData[--size] = null; //清除最后一个数据位 + return removed; + } + + /** + * 获取数据量 + */ + @Override + public int size(){ + return this.size; + } + + /** + * 获取存储数据的容量大小 + */ + @Override + public int capacity() { + return this.elementData.length; + } + + /** + * 判断是否为空 + */ + @Override + public boolean isEmpty() { + return this.size==0; + } + + /** + * 空间容量自增长 + * @param minCapacity 增长后最小容量 + */ + private void autoGrow(int minCapacity){ + int oldCapacity = elementData.length; + if (minCapacity >= oldCapacity) { + int newCapacity = oldCapacity<<1; //空间翻倍 + if (newCapacity < minCapacity){ + newCapacity = minCapacity; + } + elementData = Arrays.copyOf(elementData, newCapacity); + } + } + + /** + * 判断是否为有效索引 + * @param @param index + * @param @return + */ + private void rangeCheck(int index) { + if (!isEffectiveIndex(index)) + throw new IndexOutOfBoundsException("Index: "+index+" Out Of Bounds, 有效数据索引范围:0~"+(this.size-1)); + } + + /** + * 判断是否为有效索引 + * @param @param index + * @param @return + */ + private boolean isEffectiveIndex(int index){ + return index >-1 && index < this.size; + } + + /** + * 返回遍历数据对象 + * @param @return + * @author greenhills + * 2017年2月25日 下午9:55:31 + */ + public Iterator iterator(){ + return new Its(); + } + + /** + * 实现Iterator的内部实现类 + * Its + * @author greenhills + * 2017年2月25日 下午9:54:54 + */ + private class Its implements Iterator { + private int index=0; + + public Its(){ + //this.len = size; //逆向遍历 + } + + @Override + public boolean hasNext() { +// return this.len > 0; //逆向遍历 + return this.index < size; //正向遍历 + } + + @Override + public Object next() { +// return get(--this.len); //逆向遍历 +// return elementData[--this.len];//逆向遍历 + return get(this.index++); //正向遍历 + } + } +} diff --git a/group16/63912401/src/com/coding/basic/BinaryTreeNode.java b/group16/63912401/src/com/coding/basic/BinaryTreeNode.java new file mode 100644 index 0000000000..3ab1e431c0 --- /dev/null +++ b/group16/63912401/src/com/coding/basic/BinaryTreeNode.java @@ -0,0 +1,99 @@ +package com.coding.basic; + +/** + * 二叉树数据结构 + * BinaryTreeNode + * @author greenhills + * 2017年2月25日 下午9:51:05 + */ +public class BinaryTreeNode implements Comparable{ + + private int height=0; //当前树高度 + private Object data; //当前节点数据 + private BinaryTreeNode left; //小于当前节点数据data的节点 + private BinaryTreeNode right; //大于当前节点数据data的节点 + + public BinaryTreeNode() { + } + + public BinaryTreeNode(Object data) { + this.data = data; + } + + public BinaryTreeNode insert(Object o){ + BinaryTreeNode newNode=new BinaryTreeNode(o); + BinaryTreeNode that = findNode(o); + int result=that.compareTo(o); + + if(result<0){//节点数据小于插入数据,进右树 + that.setRight(newNode); + }else if(result>0){ //当前节点数据大于插入数据,进左树 + that.setLeft(newNode); + }else{ + return null; + } + newNode.height++; //树高度加1 + return newNode; + } + + private BinaryTreeNode findNode(Object data){ + int result=this.compareTo(data); + BinaryTreeNode that = new BinaryTreeNode(); //空节点 + if(result<0){ //当前节点数据小于插入数据,进右树 + if(this.right==null){ + that = this; + }else{ + that = findNode(this.getRight()); + } + }else if(result>0){ //当前节点数据大于插入数据,进左树 + if(this.left==null){ + that = this; + }else{ + that = findNode(this.getLeft()); + } + }else{ + System.out.println("无效数据"); + } + return that; + } + + public int getTreeMaxHeight(){ + int h=0; + //TODO + + return h; + } + + public int getHeight() { + return height; + } + + public void setHeight(int height) { + this.height = height; + } + + 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; + } + + @Override + public int compareTo(Object o) { + if(this.data==null || o==null) return 0; + return Double.valueOf(this.data.toString()).compareTo(Double.valueOf(o.toString())); + } +} diff --git a/group16/63912401/src/com/coding/basic/Iterator.java b/group16/63912401/src/com/coding/basic/Iterator.java new file mode 100644 index 0000000000..fa815258c1 --- /dev/null +++ b/group16/63912401/src/com/coding/basic/Iterator.java @@ -0,0 +1,8 @@ +package com.coding.basic; + + +public interface Iterator { + public boolean hasNext(); + public Object next(); + +} diff --git a/group16/63912401/src/com/coding/basic/LinkedList.java b/group16/63912401/src/com/coding/basic/LinkedList.java new file mode 100644 index 0000000000..2120a5a4b8 --- /dev/null +++ b/group16/63912401/src/com/coding/basic/LinkedList.java @@ -0,0 +1,320 @@ +package com.coding.basic; + +import java.util.NoSuchElementException; + +/** + * 链表数据结构 + * LinkedList + * @author greenhills + * 2017年2月22日 下午11:52:41 + */ +public class LinkedList implements List { + /** + * 链表数据量 + */ + private int size=0; + /** + * 链表头节点 + */ + private Node head; + /** + * 链表尾节点 + */ + private Node tail; + + + /** + * 在数据链尾部添加数据 + */ + @Override + public void add(Object o) { + addLast(o); + } + + /** + * 在数据链指定位置添加数据 + */ + @Override + public void add(int index, Object data) { + checkIndex(index); + Node old=getNode(index); + link2Before(old,data); + } + + /** + * 获取指定索引处数据 + */ + @Override + public Object get(int index) { + checkIndex(index); + return getNode(index).data; + } + + /** + * 移除指定索引位置的节点 + */ + @Override + public Object remove(int index) { + checkIndex(index); + return unlink(getNode(index)); + } + + /** + * 获取数据链的数据量 + */ + @Override + public int size() { + return this.size; + } + + /** + * 获取数据链的数据量 + */ + @Override + @Deprecated + public int capacity() { + return size(); + } + + /** + * 判断是否为空 + */ + @Override + public boolean isEmpty() { + return this.size==0; + } + + /** + * 在数据链头部追加数据 + * @param data + */ + public void addFirst(Object data){ + final Node oldNode=this.head; + final Node newNode=new Node(null,data,oldNode);//形成新节点,并指向第一个节点 + this.head = newNode; //变更集合保存的首节点 + + if(oldNode == null){ //没有数据 + this.tail = newNode; //变更集合保存的尾节点 + }else{ + oldNode.prev = newNode; //原首节点指向新的首节点 + } + this.size++;//数据量加1 + } + + /** + * 在数据链尾部追加数据 + * @param data + */ + public void addLast(Object data){ + final Node oldNode=this.tail; + final Node newNode=new Node(oldNode,data,null);//形成新节点,并指向最后一个节点 + this.tail = newNode; //变更集合保存的尾节点 + + if(oldNode == null){ //没有数据 + this.head = newNode; //变更集合保存的首节点 + }else{ + oldNode.next = newNode;//原尾节点指向新的尾节点 + } + this.size++;//数据量加1 + } + + /** + * 把指定数据链接到指定节点前面 + */ + void link2Before(Node node,Object data){ + //传进来的node就是后节点 + final Node prev=node.prev; //指定节点的上一个节点(前节点) + //生成新节点,并指向前后的节点 + final Node newNode=new Node(prev,data,node);//生成新节点 + //后节点指向新节点 + node.prev = newNode; + //前节点指向新节点 + if(prev == null){//没有前节点了(当前节点已是首节点) + this.head = newNode;//把新的节点作为首节点 + }else{ + prev.next = newNode; + } + this.size++;//数据量加1 + } + + /** + * 把指定数据链接到指定节点后面 + */ + void link2Last(Node node,Object data){ + //传进来的node就是前节点 + final Node next=node.next; //指定节点的下一个节点(后节点) + //生成新节点,并指向前后的节点 + final Node newNode=new Node(node,data,next); + //前节点指向新节点 + node.next = newNode; + //后节点指向新节点 + if(next == null){//没有后节点了(当前节点已是尾节点) + this.tail = newNode;//把新的节点作为尾节点 + }else{ + next.prev = newNode; + } + this.size++;//数据量加1 + } + + /** + * 移除首节点 + * @return + */ + public Object removeFirst(){ + return unlink(getNode(0)); + } + + /** + * 移除尾节点 + * @return + */ + public Object removeLast(){ + return unlink(getNode(this.size-1)); + } + + /** + * 移除节点 + * @return + */ + Object unlink(Node node){ + final Object element = node.data; + final Node next = node.next; //下一个节点 + final Node prev = node.prev;//前一个节点 + + if (prev == null) {//待删除节点是首节点 + head = next; + } else { + prev.next = next; + node.prev = null;//解除待删除节点的引用关系 + } + + if (next == null) {//待删除节点是尾节点 + tail = prev; + } else { + next.prev = prev; + node.next = null;//解除待删除节点的引用关系 + } + + node.data = null;//清除节点数据 + size--; + return element;//返回清除节点数据 + } + + /** + * 在中间位置创建Iterator遍历 + * @return + */ + public Iterator iterator() { + return new Its(this.size>>1); + } + + /** + * 在指定位置创建Iterator遍历 + * @return + */ + public Iterator iterator(int index) { + checkIndex(index); + return new Its(index); + } + + /** + * 获取指定索引的节点对象 + * @param @param index + * @param @return + */ + private Node getNode(int index){ + if (index < (this.size >> 1)) { //在前半部分 + Node node = this.head; + for (int i = 0; i < index; i++){ + node = node.next; //向后查找 + } + return node; + } else { //在后半部分 + Node node = this.tail; + for (int i = this.size - 1; i > index; i--){ + node = node.prev; //向前查找 + } + return node; + } + } + + /** + * 判断是否为有效索引 + * @param @param index + * @param @return + */ + private boolean isEffectiveIndex(int index){ + return (index>=0 && index < size); + } + + /** + * 检测索引有效性,无效时抛出异常 + * @param index + */ + private void checkIndex(int index) { + if (!isEffectiveIndex(index)) + throw new IndexOutOfBoundsException("Index: "+index+" Out Of Bounds, 最大索引: "+(size-1)); + } + + + /** + * 实现Iterator的内部实现类 + */ + private class Its implements Iterator { + private Node lastReturned = null; + private Node node;//当前节点 + private int index;//当前节点索引 + + public Its(int index){ + node = isEffectiveIndex(index) ? getNode(index) : null; + this.index = index; + } + + @Override + public boolean hasNext() { + return index < size; + } + + @Override + public Object next() { + if (!hasNext()) + throw new NoSuchElementException(); + + lastReturned = node; + node = node.next; + index++; + return lastReturned.data; + + } + + public boolean hasPrevious() { + return index >= 0; + } + + public Object previous() { + if (!hasPrevious()) + throw new NoSuchElementException(); + + lastReturned = node; + node = node.prev; + index--; + return lastReturned.data; + } + } + + /** + * 节点数据 + * Node + */ + private static class Node{ + Object data; + Node prev; + Node next; + + Node(Node prev,Object data,Node next){ + this.prev=prev; + this.data=data; + this.next=next; + } + } +} diff --git a/group16/63912401/src/com/coding/basic/List.java b/group16/63912401/src/com/coding/basic/List.java new file mode 100644 index 0000000000..7fe012ccab --- /dev/null +++ b/group16/63912401/src/com/coding/basic/List.java @@ -0,0 +1,16 @@ +package com.coding.basic; +/** + * 集合接口 + * @author greenhills + * @version 创建时间:2017年2月19日 下午10:49:40 + * + */ +public interface List { + public void add(Object o); + public void add(int index, Object o); + public Object get(int index); + public Object remove(int index); + public int size(); + public int capacity(); + boolean isEmpty(); +} diff --git a/group16/63912401/src/com/coding/basic/Queue.java b/group16/63912401/src/com/coding/basic/Queue.java new file mode 100644 index 0000000000..c6007c9e99 --- /dev/null +++ b/group16/63912401/src/com/coding/basic/Queue.java @@ -0,0 +1,43 @@ +package com.coding.basic; + +/** + * 队列数据结构 + * Queue + * @author greenhills + * 2017年2月25日 下午9:50:04 + */ +public class Queue { + private LinkedList elementData = new LinkedList(); + + /** + * 入队 + * @param o + */ + public void enQueue(Object o){ + elementData.addLast(o); + } + + /** + * 出队 + * @return + */ + public Object deQueue(){ + return elementData.removeFirst(); + } + + /** + * 判断是否为空 + * @return + */ + public boolean isEmpty(){ + return elementData.size()==0; + } + + /** + * 获取栈内数据量 + * @return + */ + public int size(){ + return elementData.size(); + } +} diff --git a/group16/63912401/src/com/coding/basic/Stack.java b/group16/63912401/src/com/coding/basic/Stack.java new file mode 100644 index 0000000000..8e1865f722 --- /dev/null +++ b/group16/63912401/src/com/coding/basic/Stack.java @@ -0,0 +1,51 @@ +package com.coding.basic; + +/** + * 栈数据结构 + * Stack + * @author greenhills + * 2017年2月25日 下午9:49:41 + */ +public class Stack { + private LinkedList elementData = new LinkedList(); + + /** + * 入栈 + * @param o + */ + public void push(Object o){ + elementData.addFirst(o); + } + + /** + * 出栈 + * @return + */ + public Object pop(){ + return elementData.removeFirst(); + } + + /** + * 获取栈顶数据 + * @return + */ + public Object peek(){ + return elementData.get(0); + } + + /** + * 判断是否为空 + * @return + */ + public boolean isEmpty(){ + return elementData.size()==0; + } + + /** + * 获取栈内数据量 + * @return + */ + public int size(){ + return elementData.size(); + } +} From 3a8239ae33d5973e05be7ae338687bb8c223c9be Mon Sep 17 00:00:00 2001 From: QQ-ing <932886072@qq.com> Date: Sun, 26 Feb 2017 22:43:23 +0800 Subject: [PATCH 019/335] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group16/932886072 | 1 - group16/932886072/djj/ArrayList.java | 64 +++++++++++++++ group16/932886072/djj/BinaryTreeNode.java | 34 ++++++++ group16/932886072/djj/Iterator.java | 9 +++ group16/932886072/djj/LinkedList.java | 96 +++++++++++++++++++++++ group16/932886072/djj/List.java | 12 +++ group16/932886072/djj/Queue.java | 27 +++++++ group16/932886072/djj/Stack.java | 27 +++++++ 8 files changed, 269 insertions(+), 1 deletion(-) delete mode 100644 group16/932886072 create mode 100644 group16/932886072/djj/ArrayList.java create mode 100644 group16/932886072/djj/BinaryTreeNode.java create mode 100644 group16/932886072/djj/Iterator.java create mode 100644 group16/932886072/djj/LinkedList.java create mode 100644 group16/932886072/djj/List.java create mode 100644 group16/932886072/djj/Queue.java create mode 100644 group16/932886072/djj/Stack.java diff --git a/group16/932886072 b/group16/932886072 deleted file mode 100644 index 9daeafb986..0000000000 --- a/group16/932886072 +++ /dev/null @@ -1 +0,0 @@ -test diff --git a/group16/932886072/djj/ArrayList.java b/group16/932886072/djj/ArrayList.java new file mode 100644 index 0000000000..df3a11c386 --- /dev/null +++ b/group16/932886072/djj/ArrayList.java @@ -0,0 +1,64 @@ +package djj; + + +import java.util.Arrays; + +/** + * Created by jerry on 2017/2/26. + */ +public class ArrayList implements List { + + private int size = 0; + + private Object[] elementData = new Object[100]; + + public void add(Object o){ + if(size>elementData.length*0.8){ + Arrays.copyOf(elementData,elementData.length*2); + } + elementData[size]=o; + size++; + } + public void add(int index, Object o){ + if (size>=index){ + Object[] temp=new Object[elementData.length]; + System.arraycopy(elementData,0,temp,0,index); + temp[index]=o; + System.arraycopy(elementData,index,temp,index+1,size-index); + elementData=temp; + }else if(sizesize){ + throw new RuntimeException("越界"); + }else{ + return elementData[index]; + } + } + + public Object remove(int index){ + Object tempObj=null; + if(index<=size){ + Object[] temp=new Object[elementData.length]; + System.arraycopy(elementData,0,temp,0,index); + tempObj=elementData[index]; + System.arraycopy(elementData,index+1,temp,index,size-index-1); + elementData=temp; + } + size--; + return tempObj; + } + + public int size(){ + return size; + } + + public Iterator iterator(){ + return null; + } + +} diff --git a/group16/932886072/djj/BinaryTreeNode.java b/group16/932886072/djj/BinaryTreeNode.java new file mode 100644 index 0000000000..d697be6ffc --- /dev/null +++ b/group16/932886072/djj/BinaryTreeNode.java @@ -0,0 +1,34 @@ +package djj; + +public class BinaryTreeNode { + + private BinaryTreeNode root; + private Object data; + private BinaryTreeNode left; + private BinaryTreeNode right; + + public BinaryTreeNode insert(Object o){ + + return null; + } + + + public Object getData() { + return data; + } + public void setData(Object data) { + this.data = data; + } + public BinaryTreeNode getLeft() { + return left; + } + public void setLeft(BinaryTreeNode left) { + this.left = left; + } + public BinaryTreeNode getRight() { + return right; + } + public void setRight(BinaryTreeNode right) { + this.right = right; + } +} diff --git a/group16/932886072/djj/Iterator.java b/group16/932886072/djj/Iterator.java new file mode 100644 index 0000000000..4482e3a408 --- /dev/null +++ b/group16/932886072/djj/Iterator.java @@ -0,0 +1,9 @@ +package djj; + +/** + * Created by jerry on 2017/2/26. + */ +public interface Iterator { + public boolean hasNext(); + public Object next(); +} diff --git a/group16/932886072/djj/LinkedList.java b/group16/932886072/djj/LinkedList.java new file mode 100644 index 0000000000..6e40d5cc69 --- /dev/null +++ b/group16/932886072/djj/LinkedList.java @@ -0,0 +1,96 @@ +package djj; + +public class LinkedList implements List { + //头节点 + private Node head; + //尾节点 +// private Node tail; + //当前游标节点 + private Node curNode; + public int size=0; + + + public void add(Object o){ + if(head==null){ + head=new Node(o); + head.next=null; + }else{ + curNode=head; + while(curNode.next!=null){ + curNode=curNode.next; + } + curNode.next=new Node(o); + } + size++; + } + public void add(int index , Object o){ + if(index>size||index<=0){ + throw new RuntimeException("越界"); + }else{ + curNode=head; + for(int i=0;isize||index<=0){ + throw new RuntimeException("越界"); + } + Node temp=head; + for(int i=0;isize||index<=0){ + throw new RuntimeException("越界"); + } + Node temp=head; + for(int i=0;i Date: Sun, 26 Feb 2017 22:44:01 +0800 Subject: [PATCH 020/335] 63912401 --- group16/63912401/.classpath | 2 +- group16/63912401/.project | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/group16/63912401/.classpath b/group16/63912401/.classpath index 10c33642b2..d171cd4c12 100644 --- a/group16/63912401/.classpath +++ b/group16/63912401/.classpath @@ -1,6 +1,6 @@ - + diff --git a/group16/63912401/.project b/group16/63912401/.project index b6d8ce6204..ec6117b543 100644 --- a/group16/63912401/.project +++ b/group16/63912401/.project @@ -1,6 +1,6 @@ - coding2017 + 63912401 From 2808a2a3756748c2161e554688a79438c81ea974 Mon Sep 17 00:00:00 2001 From: Korben_CHY Date: Sun, 26 Feb 2017 22:43:00 +0800 Subject: [PATCH 021/335] add package coding/basic --- .../src/org/korben/{ => coding/basic}/list/KArrayList.java | 2 +- .../src/org/korben/{ => coding/basic}/list/KIterator.java | 2 +- .../src/org/korben/{ => coding/basic}/list/KLinkedList.java | 2 +- .../src/org/korben/{ => coding/basic}/list/KList.java | 2 +- .../org/korben/{ => coding/basic}/list/KListIteratorTest.java | 2 +- .../src/org/korben/{ => coding/basic}/list/KListTest.java | 2 +- .../src/org/korben/{ => coding/basic}/queue/KArrayQueue.java | 2 +- .../src/org/korben/{ => coding/basic}/queue/KQueue.java | 2 +- .../src/org/korben/{ => coding/basic}/queue/KQueueTest.java | 2 +- .../src/org/korben/{ => coding/basic}/stack/KStack.java | 2 +- .../src/org/korben/{ => coding/basic}/stack/KStackTest.java | 2 +- .../src/org/korben/{ => coding/basic}/tree/BinaryTreeNode.java | 2 +- .../org/korben/{ => coding/basic}/tree/BinaryTreeNodeTest.java | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) rename group20/1107837739/1107837739Learning/src/org/korben/{ => coding/basic}/list/KArrayList.java (99%) rename group20/1107837739/1107837739Learning/src/org/korben/{ => coding/basic}/list/KIterator.java (75%) rename group20/1107837739/1107837739Learning/src/org/korben/{ => coding/basic}/list/KLinkedList.java (98%) rename group20/1107837739/1107837739Learning/src/org/korben/{ => coding/basic}/list/KList.java (91%) rename group20/1107837739/1107837739Learning/src/org/korben/{ => coding/basic}/list/KListIteratorTest.java (94%) rename group20/1107837739/1107837739Learning/src/org/korben/{ => coding/basic}/list/KListTest.java (99%) rename group20/1107837739/1107837739Learning/src/org/korben/{ => coding/basic}/queue/KArrayQueue.java (98%) rename group20/1107837739/1107837739Learning/src/org/korben/{ => coding/basic}/queue/KQueue.java (84%) rename group20/1107837739/1107837739Learning/src/org/korben/{ => coding/basic}/queue/KQueueTest.java (97%) rename group20/1107837739/1107837739Learning/src/org/korben/{ => coding/basic}/stack/KStack.java (97%) rename group20/1107837739/1107837739Learning/src/org/korben/{ => coding/basic}/stack/KStackTest.java (97%) rename group20/1107837739/1107837739Learning/src/org/korben/{ => coding/basic}/tree/BinaryTreeNode.java (98%) rename group20/1107837739/1107837739Learning/src/org/korben/{ => coding/basic}/tree/BinaryTreeNodeTest.java (97%) diff --git a/group20/1107837739/1107837739Learning/src/org/korben/list/KArrayList.java b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/list/KArrayList.java similarity index 99% rename from group20/1107837739/1107837739Learning/src/org/korben/list/KArrayList.java rename to group20/1107837739/1107837739Learning/src/org/korben/coding/basic/list/KArrayList.java index 4d6236b537..0f443462ed 100644 --- a/group20/1107837739/1107837739Learning/src/org/korben/list/KArrayList.java +++ b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/list/KArrayList.java @@ -1,4 +1,4 @@ -package org.korben.list; +package org.korben.coding.basic.list; import java.util.Objects; diff --git a/group20/1107837739/1107837739Learning/src/org/korben/list/KIterator.java b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/list/KIterator.java similarity index 75% rename from group20/1107837739/1107837739Learning/src/org/korben/list/KIterator.java rename to group20/1107837739/1107837739Learning/src/org/korben/coding/basic/list/KIterator.java index c29e566178..b5245ecca0 100644 --- a/group20/1107837739/1107837739Learning/src/org/korben/list/KIterator.java +++ b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/list/KIterator.java @@ -1,4 +1,4 @@ -package org.korben.list; +package org.korben.coding.basic.list; /** * Created by Korben on 24/02/2017. diff --git a/group20/1107837739/1107837739Learning/src/org/korben/list/KLinkedList.java b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/list/KLinkedList.java similarity index 98% rename from group20/1107837739/1107837739Learning/src/org/korben/list/KLinkedList.java rename to group20/1107837739/1107837739Learning/src/org/korben/coding/basic/list/KLinkedList.java index e14efad19c..2ca4452981 100644 --- a/group20/1107837739/1107837739Learning/src/org/korben/list/KLinkedList.java +++ b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/list/KLinkedList.java @@ -1,4 +1,4 @@ -package org.korben.list; +package org.korben.coding.basic.list; import java.util.Objects; diff --git a/group20/1107837739/1107837739Learning/src/org/korben/list/KList.java b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/list/KList.java similarity index 91% rename from group20/1107837739/1107837739Learning/src/org/korben/list/KList.java rename to group20/1107837739/1107837739Learning/src/org/korben/coding/basic/list/KList.java index e5d33b984b..e5b166094e 100644 --- a/group20/1107837739/1107837739Learning/src/org/korben/list/KList.java +++ b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/list/KList.java @@ -1,4 +1,4 @@ -package org.korben.list; +package org.korben.coding.basic.list; /** * Korben's List diff --git a/group20/1107837739/1107837739Learning/src/org/korben/list/KListIteratorTest.java b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/list/KListIteratorTest.java similarity index 94% rename from group20/1107837739/1107837739Learning/src/org/korben/list/KListIteratorTest.java rename to group20/1107837739/1107837739Learning/src/org/korben/coding/basic/list/KListIteratorTest.java index 994538732f..7017e0ed2c 100644 --- a/group20/1107837739/1107837739Learning/src/org/korben/list/KListIteratorTest.java +++ b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/list/KListIteratorTest.java @@ -1,4 +1,4 @@ -package org.korben.list; +package org.korben.coding.basic.list; import org.junit.Assert; import org.junit.Before; diff --git a/group20/1107837739/1107837739Learning/src/org/korben/list/KListTest.java b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/list/KListTest.java similarity index 99% rename from group20/1107837739/1107837739Learning/src/org/korben/list/KListTest.java rename to group20/1107837739/1107837739Learning/src/org/korben/coding/basic/list/KListTest.java index ed3055b74e..2c6febecc3 100644 --- a/group20/1107837739/1107837739Learning/src/org/korben/list/KListTest.java +++ b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/list/KListTest.java @@ -1,4 +1,4 @@ -package org.korben.list; +package org.korben.coding.basic.list; import java.util.Objects; import org.junit.Assert; diff --git a/group20/1107837739/1107837739Learning/src/org/korben/queue/KArrayQueue.java b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/queue/KArrayQueue.java similarity index 98% rename from group20/1107837739/1107837739Learning/src/org/korben/queue/KArrayQueue.java rename to group20/1107837739/1107837739Learning/src/org/korben/coding/basic/queue/KArrayQueue.java index 3e975058f4..eea57cf035 100644 --- a/group20/1107837739/1107837739Learning/src/org/korben/queue/KArrayQueue.java +++ b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/queue/KArrayQueue.java @@ -1,4 +1,4 @@ -package org.korben.queue; +package org.korben.coding.basic.queue; import java.util.NoSuchElementException; diff --git a/group20/1107837739/1107837739Learning/src/org/korben/queue/KQueue.java b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/queue/KQueue.java similarity index 84% rename from group20/1107837739/1107837739Learning/src/org/korben/queue/KQueue.java rename to group20/1107837739/1107837739Learning/src/org/korben/coding/basic/queue/KQueue.java index 14763efd99..9d8146d50d 100644 --- a/group20/1107837739/1107837739Learning/src/org/korben/queue/KQueue.java +++ b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/queue/KQueue.java @@ -1,4 +1,4 @@ -package org.korben.queue; +package org.korben.coding.basic.queue; /** * Korben's Queue Interface diff --git a/group20/1107837739/1107837739Learning/src/org/korben/queue/KQueueTest.java b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/queue/KQueueTest.java similarity index 97% rename from group20/1107837739/1107837739Learning/src/org/korben/queue/KQueueTest.java rename to group20/1107837739/1107837739Learning/src/org/korben/coding/basic/queue/KQueueTest.java index 3d9557748f..17c3703a64 100644 --- a/group20/1107837739/1107837739Learning/src/org/korben/queue/KQueueTest.java +++ b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/queue/KQueueTest.java @@ -1,4 +1,4 @@ -package org.korben.queue; +package org.korben.coding.basic.queue; import java.util.NoSuchElementException; import org.junit.Assert; diff --git a/group20/1107837739/1107837739Learning/src/org/korben/stack/KStack.java b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/stack/KStack.java similarity index 97% rename from group20/1107837739/1107837739Learning/src/org/korben/stack/KStack.java rename to group20/1107837739/1107837739Learning/src/org/korben/coding/basic/stack/KStack.java index 8dc39e4efd..eb83eb47cd 100644 --- a/group20/1107837739/1107837739Learning/src/org/korben/stack/KStack.java +++ b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/stack/KStack.java @@ -1,4 +1,4 @@ -package org.korben.stack; +package org.korben.coding.basic.stack; import java.util.EmptyStackException; import java.util.Objects; diff --git a/group20/1107837739/1107837739Learning/src/org/korben/stack/KStackTest.java b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/stack/KStackTest.java similarity index 97% rename from group20/1107837739/1107837739Learning/src/org/korben/stack/KStackTest.java rename to group20/1107837739/1107837739Learning/src/org/korben/coding/basic/stack/KStackTest.java index e3f173eb3f..20b451a7ef 100644 --- a/group20/1107837739/1107837739Learning/src/org/korben/stack/KStackTest.java +++ b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/stack/KStackTest.java @@ -1,4 +1,4 @@ -package org.korben.stack; +package org.korben.coding.basic.stack; import java.util.EmptyStackException; import org.junit.Assert; diff --git a/group20/1107837739/1107837739Learning/src/org/korben/tree/BinaryTreeNode.java b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/tree/BinaryTreeNode.java similarity index 98% rename from group20/1107837739/1107837739Learning/src/org/korben/tree/BinaryTreeNode.java rename to group20/1107837739/1107837739Learning/src/org/korben/coding/basic/tree/BinaryTreeNode.java index 30c613edd0..3cfcacc37c 100644 --- a/group20/1107837739/1107837739Learning/src/org/korben/tree/BinaryTreeNode.java +++ b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/tree/BinaryTreeNode.java @@ -1,4 +1,4 @@ -package org.korben.tree; +package org.korben.coding.basic.tree; /** * Korben's BinaryTreeNode diff --git a/group20/1107837739/1107837739Learning/src/org/korben/tree/BinaryTreeNodeTest.java b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/tree/BinaryTreeNodeTest.java similarity index 97% rename from group20/1107837739/1107837739Learning/src/org/korben/tree/BinaryTreeNodeTest.java rename to group20/1107837739/1107837739Learning/src/org/korben/coding/basic/tree/BinaryTreeNodeTest.java index a6fb4ed4e9..05873872a7 100644 --- a/group20/1107837739/1107837739Learning/src/org/korben/tree/BinaryTreeNodeTest.java +++ b/group20/1107837739/1107837739Learning/src/org/korben/coding/basic/tree/BinaryTreeNodeTest.java @@ -1,4 +1,4 @@ -package org.korben.tree; +package org.korben.coding.basic.tree; import org.junit.Assert; From 28b6b343028d910e70019573e8b3b9e5cfcc0cf3 Mon Sep 17 00:00:00 2001 From: weifei619 Date: Sun, 26 Feb 2017 22:57:56 +0800 Subject: [PATCH 022/335] github --- .../src/GithubWork/ArrayList.java | 73 ++++++++++ .../src/GithubWork/JunitTest.java | 47 ++++++ .../src/GithubWork/LinkedList.java | 136 ++++++++++++++++++ .../src/GithubWork/List.java | 10 ++ .../src/GithubWork/Queue.java | 43 ++++++ .../src/GithubWork/Stack.java | 22 +++ ...6\207\347\253\240\345\234\260\345\235\200" | 1 + 7 files changed, 332 insertions(+) create mode 100644 group20/1430208241/1430208241leaning/src/GithubWork/ArrayList.java create mode 100644 group20/1430208241/1430208241leaning/src/GithubWork/JunitTest.java create mode 100644 group20/1430208241/1430208241leaning/src/GithubWork/LinkedList.java create mode 100644 group20/1430208241/1430208241leaning/src/GithubWork/List.java create mode 100644 group20/1430208241/1430208241leaning/src/GithubWork/Queue.java create mode 100644 group20/1430208241/1430208241leaning/src/GithubWork/Stack.java create mode 100644 "group20/1430208241/1430208241leaning/src/\346\226\207\347\253\240\345\234\260\345\235\200" diff --git a/group20/1430208241/1430208241leaning/src/GithubWork/ArrayList.java b/group20/1430208241/1430208241leaning/src/GithubWork/ArrayList.java new file mode 100644 index 0000000000..f74501b5ba --- /dev/null +++ b/group20/1430208241/1430208241leaning/src/GithubWork/ArrayList.java @@ -0,0 +1,73 @@ +package GithubWork; + +import java.util.Arrays; + +public class ArrayList implements List { + private int size = 0; + private Object[] elementdata = new Object[100]; + + public void add(Object o) { + if (elementdata.length <= size) { + ensureCapacity(size + 1); + } + elementdata[size++] = o; + } + + private void ensureCapacity(int minCapacity) { + int oldCapacity = elementdata.length; + if (oldCapacity < minCapacity) { + + int newCapacity = (int) (oldCapacity * 1.5); + if (newCapacity < minCapacity) + newCapacity = minCapacity; + elementdata = Arrays.copyOf(elementdata, newCapacity); + } + } + + public void add(int index, Object o) { + if (index > size || index < 0) { + throw new IndexOutOfBoundsException(); + + } + + ensureCapacity(size + 1); + System.arraycopy(elementdata, index, elementdata, index, size - index); + elementdata[index] = o; + size++; + } + + public Object get(int index) { + RangeCheck(index); + + return elementdata[index]; + } + + public Object remove(int index) { + RangeCheck(index); + Object oldvalue = elementdata[index]; + int numMoved = size - index - 1; + if (numMoved > 0) + System.arraycopy(elementdata, index + 1, elementdata, index, numMoved); + elementdata[--size] = null; + return oldvalue; + } + + private void RangeCheck(int index) { + if (index >= size) + throw new IndexOutOfBoundsException(); + } + + public int size() { + int i; + for (i = 0; i < elementdata.length; i++) { + size++; + if (null == elementdata[i]) { + break; + } + + } + return size; + + } + +} diff --git a/group20/1430208241/1430208241leaning/src/GithubWork/JunitTest.java b/group20/1430208241/1430208241leaning/src/GithubWork/JunitTest.java new file mode 100644 index 0000000000..b011de10f0 --- /dev/null +++ b/group20/1430208241/1430208241leaning/src/GithubWork/JunitTest.java @@ -0,0 +1,47 @@ +package GithubWork; + +import org.junit.Test; + +public class JunitTest { + @Test + public void ArrayList(){ + ArrayList a=new ArrayList(); + a.add(1); + a.add(2); + a.add(3); + a.add(4); + a.get(2); + + System.out.println(a); + + + } + @Test + public void Queue(){ + Queue q=new Queue(4); + q.enQueue(1); + q.enQueue(2); + q.enQueue(3); + q.enQueue(4); + + while(!q.isEmpty()){ + int i=(int) q.deQueue(); + System.out.println(i); + } + System.out.println(q.size()); + } + @Test + public void LinkedList(){ + LinkedList ls=new LinkedList(); + ls.add(1); + ls.add(7); + ls.add(3); + ls.add(4, 5); + ls.get(2); + ls.addFirst(0); + + ls.remove(3); + System.out.println(ls); + + } +} diff --git a/group20/1430208241/1430208241leaning/src/GithubWork/LinkedList.java b/group20/1430208241/1430208241leaning/src/GithubWork/LinkedList.java new file mode 100644 index 0000000000..657ca117dc --- /dev/null +++ b/group20/1430208241/1430208241leaning/src/GithubWork/LinkedList.java @@ -0,0 +1,136 @@ +package GithubWork; + +import java.util.Iterator; + +public class LinkedList implements List { + + private Node head = null;// ͷڵ + private int size = 0; + private Node last = null; + + /* + * в (non-Javadoc) + * + * @see GithubWork.List#add(java.lang.Object) + */ + public void add(Object o) { + Node newNode = new Node(0);// ʵһڵ + if (head == null) { + head = newNode; + return; + } + Node tmp = head; + while (tmp.next != null) { + tmp = tmp.next; + } + tmp.next = newNode; + size++; + } + + public void add(int index, Object o) { + Node newNode = new Node(0); + Node indexNode = head; + int i = 0; + while (i == index) { + indexNode = indexNode.next; + i++; + } + Node indexNextNode = indexNode.next; + indexNode.next = newNode; + newNode.pre = indexNode; + newNode.next = indexNextNode; + indexNextNode.pre = newNode; + size++; + } + + public Object get(int index) { + Node indexNode = head; + int i = 0; + while (i == index) { + indexNode = indexNode.next; + i++; + } + return indexNode; + } + + public Object remove(int index) { + if (index < 1 || index > size()) { + throw new IndexOutOfBoundsException(); + } + if (index == 1) { + head = head.next; + return head; + } + int i = 1; + Node preNode = head; + Node curNode = preNode.next; + while (curNode != null) { + if (i == index) { + preNode.next = curNode.next; + + } + preNode = curNode; + curNode = curNode.next; + i++; + } + return curNode; + } + + public int size() { + return size; + } + + public void addFirst(Object o) { + Node newNode = new Node(o); + newNode.data = o; + newNode.next = head; + head.pre = newNode; + head = newNode; + size++; + } + + public void addLast(Object o) { + Node newNode = new Node(o); + newNode.data = o; + + newNode.pre = last; + last.next = newNode; + last = newNode; + size++; + + } + + public Object removeFirst() { + Node ref = head; + head = head.next; + head.pre = null; + size--; + return ref; + } + + public Object removeLast() { + Node rel = last; + last = last.pre; + last.next = null; + size--; + return rel; + + } + + public Iterator iterator() { + + return null; + } + + private static class Node { + Object data;// ڵ + Node next = null;// ͷڵ + Node pre = null; + + public Node(Object data) { + this.data = data; + } + + } + +} diff --git a/group20/1430208241/1430208241leaning/src/GithubWork/List.java b/group20/1430208241/1430208241leaning/src/GithubWork/List.java new file mode 100644 index 0000000000..169fc14fd1 --- /dev/null +++ b/group20/1430208241/1430208241leaning/src/GithubWork/List.java @@ -0,0 +1,10 @@ +package GithubWork; + +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/group20/1430208241/1430208241leaning/src/GithubWork/Queue.java b/group20/1430208241/1430208241leaning/src/GithubWork/Queue.java new file mode 100644 index 0000000000..792ca233f5 --- /dev/null +++ b/group20/1430208241/1430208241leaning/src/GithubWork/Queue.java @@ -0,0 +1,43 @@ +package GithubWork; + +public class Queue { + private int maxSize; + private Object[] array;//Ԫ + private int front;//ǰһԪ + private int rear;//һԪ + private int items=0;//Ԫظ + //󲢳ʼ + public Queue(int s){ + maxSize=s; + array=new Object[maxSize]; + front=0; + rear=-1; + + } + public void enQueue(Object o){ + if(rear==maxSize-1){ + rear=-1; + } + array[++rear]=o; + items++; + + } + + public Object deQueue(){ + Object temp =array[front++]; + if(front==maxSize){ + front=0; + } + items--; + return temp; + } + + public boolean isEmpty(){ + + return items==0; + } + + public int size(){ + return array.length; + } +} diff --git a/group20/1430208241/1430208241leaning/src/GithubWork/Stack.java b/group20/1430208241/1430208241leaning/src/GithubWork/Stack.java new file mode 100644 index 0000000000..43f138021c --- /dev/null +++ b/group20/1430208241/1430208241leaning/src/GithubWork/Stack.java @@ -0,0 +1,22 @@ +package GithubWork; + +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/group20/1430208241/1430208241leaning/src/\346\226\207\347\253\240\345\234\260\345\235\200" "b/group20/1430208241/1430208241leaning/src/\346\226\207\347\253\240\345\234\260\345\235\200" new file mode 100644 index 0000000000..472bb524e9 --- /dev/null +++ "b/group20/1430208241/1430208241leaning/src/\346\226\207\347\253\240\345\234\260\345\235\200" @@ -0,0 +1 @@ +http://blog.csdn.net/wifi619/article/details/57510982 \ No newline at end of file From 524595918c85f8cafbf5a9ae3953ca0b36575cff Mon Sep 17 00:00:00 2001 From: 592146505 <592146505@qq.com> Date: Sun, 26 Feb 2017 23:00:58 +0800 Subject: [PATCH 023/335] update List and add BinaryTreeNode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 完善List,完成BinaryTreeNode,stack未完成 --- .../wsc/exception/NullElementException.java | 23 +++ .../exception/RepeatingElementException.java | 23 +++ .../wsc/util => org/wsc/list}/ArrayList.java | 2 +- .../src/org/wsc/list/Iterator.java | 21 +++ .../wsc/util => org/wsc/list}/LinkedList.java | 26 ++- .../{cn/wsc/util => org/wsc/list}/List.java | 2 +- .../src/org/wsc/list/Queue.java | 42 +++++ .../wsc/utils => org/wsc/stack}/Stack.java | 4 +- .../src/org/wsc/tree_node/BinaryTreeNode.java | 166 ++++++++++++++++++ 9 files changed, 303 insertions(+), 6 deletions(-) create mode 100644 group20/592146505/data _structure/src/org/wsc/exception/NullElementException.java create mode 100644 group20/592146505/data _structure/src/org/wsc/exception/RepeatingElementException.java rename group20/592146505/data _structure/src/{cn/wsc/util => org/wsc/list}/ArrayList.java (99%) create mode 100644 group20/592146505/data _structure/src/org/wsc/list/Iterator.java rename group20/592146505/data _structure/src/{cn/wsc/util => org/wsc/list}/LinkedList.java (92%) rename group20/592146505/data _structure/src/{cn/wsc/util => org/wsc/list}/List.java (98%) create mode 100644 group20/592146505/data _structure/src/org/wsc/list/Queue.java rename group20/592146505/data _structure/src/{cn/wsc/utils => org/wsc/stack}/Stack.java (83%) create mode 100644 group20/592146505/data _structure/src/org/wsc/tree_node/BinaryTreeNode.java diff --git a/group20/592146505/data _structure/src/org/wsc/exception/NullElementException.java b/group20/592146505/data _structure/src/org/wsc/exception/NullElementException.java new file mode 100644 index 0000000000..aa7763ef00 --- /dev/null +++ b/group20/592146505/data _structure/src/org/wsc/exception/NullElementException.java @@ -0,0 +1,23 @@ +package org.wsc.exception; + +/** + * + * 空元素异常 + * @author Administrator + * @date 2017年2月26日下午4:15:49 + * @version v1.0 + * + */ +public class NullElementException extends RuntimeException { + + private static final long serialVersionUID = 4729177529481680909L; + + public NullElementException() { + super(); + } + + public NullElementException(String message) { + super(message); + } + +} diff --git a/group20/592146505/data _structure/src/org/wsc/exception/RepeatingElementException.java b/group20/592146505/data _structure/src/org/wsc/exception/RepeatingElementException.java new file mode 100644 index 0000000000..a5b66c54a1 --- /dev/null +++ b/group20/592146505/data _structure/src/org/wsc/exception/RepeatingElementException.java @@ -0,0 +1,23 @@ +package org.wsc.exception; + +/** + * + * 重复元素异常 + * @author Administrator + * @date 2017年2月26日下午4:15:49 + * @version v1.0 + * + */ +public class RepeatingElementException extends RuntimeException { + + private static final long serialVersionUID = 4729177529481680909L; + + public RepeatingElementException() { + super(); + } + + public RepeatingElementException(String message) { + super(message); + } + +} diff --git a/group20/592146505/data _structure/src/cn/wsc/util/ArrayList.java b/group20/592146505/data _structure/src/org/wsc/list/ArrayList.java similarity index 99% rename from group20/592146505/data _structure/src/cn/wsc/util/ArrayList.java rename to group20/592146505/data _structure/src/org/wsc/list/ArrayList.java index 94bb1f3217..d4d2abdc48 100644 --- a/group20/592146505/data _structure/src/cn/wsc/util/ArrayList.java +++ b/group20/592146505/data _structure/src/org/wsc/list/ArrayList.java @@ -1,4 +1,4 @@ -package cn.wsc.util; +package org.wsc.list; import java.util.Arrays; import java.util.ConcurrentModificationException; diff --git a/group20/592146505/data _structure/src/org/wsc/list/Iterator.java b/group20/592146505/data _structure/src/org/wsc/list/Iterator.java new file mode 100644 index 0000000000..59590bbf7e --- /dev/null +++ b/group20/592146505/data _structure/src/org/wsc/list/Iterator.java @@ -0,0 +1,21 @@ +package org.wsc.list; + +public interface Iterator { + /** + * 是否存在下一个元素 + * @return + */ + boolean hasNext(); + + /** + * 获取下一个元素 + * @return + */ + E next(); + + /** + * 删除当前元素 + */ + void remove(); + +} diff --git a/group20/592146505/data _structure/src/cn/wsc/util/LinkedList.java b/group20/592146505/data _structure/src/org/wsc/list/LinkedList.java similarity index 92% rename from group20/592146505/data _structure/src/cn/wsc/util/LinkedList.java rename to group20/592146505/data _structure/src/org/wsc/list/LinkedList.java index ccb9ff2783..09ad35f200 100644 --- a/group20/592146505/data _structure/src/cn/wsc/util/LinkedList.java +++ b/group20/592146505/data _structure/src/org/wsc/list/LinkedList.java @@ -1,18 +1,19 @@ -package cn.wsc.util; +package org.wsc.list; import java.util.ConcurrentModificationException; import java.util.NoSuchElementException; /** * LinkedList类 - * + * 实现List接口和Queue接口 + * 基于链表的集合 * @author Administrator * @date 2017年2月25日上午10:52:41 * @version v1.0 * * @param */ -public class LinkedList implements List { +public class LinkedList implements List,Queue { private int size; Node first; // 链表的头节点 @@ -224,6 +225,14 @@ public E remove(int index) { return unlink(node(index)); } + public E removeFirst() { + //获取头节点 + final Node f = first; + if (f == null) + throw new NoSuchElementException(); + return remove(0); + } + /** * 删除节点 * @@ -252,6 +261,16 @@ E unlink(Node x) { return element; } + @Override + public void enQueue(E e) { + linkLast(e); + } + + @Override + public E deQueue() { + return removeFirst(); + } + /** * 位置范围检查 >0 && <=size * @@ -281,4 +300,5 @@ private void checkElementIndex(int index) { private String outOfBoundsMsg(int index) { return "Index: " + index + ", Size: " + this.size; } + } diff --git a/group20/592146505/data _structure/src/cn/wsc/util/List.java b/group20/592146505/data _structure/src/org/wsc/list/List.java similarity index 98% rename from group20/592146505/data _structure/src/cn/wsc/util/List.java rename to group20/592146505/data _structure/src/org/wsc/list/List.java index 9b61278fc7..d7ef5ee96f 100644 --- a/group20/592146505/data _structure/src/cn/wsc/util/List.java +++ b/group20/592146505/data _structure/src/org/wsc/list/List.java @@ -1,4 +1,4 @@ -package cn.wsc.util; +package org.wsc.list; /** * List接口 diff --git a/group20/592146505/data _structure/src/org/wsc/list/Queue.java b/group20/592146505/data _structure/src/org/wsc/list/Queue.java new file mode 100644 index 0000000000..2087335e58 --- /dev/null +++ b/group20/592146505/data _structure/src/org/wsc/list/Queue.java @@ -0,0 +1,42 @@ +package org.wsc.list; + +/** + * + * 队列 + * + * @author Administrator + * @date 2017年2月25日下午6:08:01 + * @version v1.0 + * + * @param + */ +public interface Queue { + + /** + * 入列 + * + * @param e + */ + public void enQueue(E e); + + /** + * 出列 + * + * @return + */ + public E deQueue(); + + /** + * 是否为空 + * + * @return + */ + public boolean isEmpty(); + + /** + * 元素长度 + * + * @return + */ + public int size(); +} diff --git a/group20/592146505/data _structure/src/cn/wsc/utils/Stack.java b/group20/592146505/data _structure/src/org/wsc/stack/Stack.java similarity index 83% rename from group20/592146505/data _structure/src/cn/wsc/utils/Stack.java rename to group20/592146505/data _structure/src/org/wsc/stack/Stack.java index 3f156461e8..96b931ca07 100644 --- a/group20/592146505/data _structure/src/cn/wsc/utils/Stack.java +++ b/group20/592146505/data _structure/src/org/wsc/stack/Stack.java @@ -1,4 +1,6 @@ -package cn.wsc.utils; +package org.wsc.stack; + +import org.wsc.list.ArrayList; public class Stack { private ArrayList elementData = new ArrayList(); diff --git a/group20/592146505/data _structure/src/org/wsc/tree_node/BinaryTreeNode.java b/group20/592146505/data _structure/src/org/wsc/tree_node/BinaryTreeNode.java new file mode 100644 index 0000000000..b68784541d --- /dev/null +++ b/group20/592146505/data _structure/src/org/wsc/tree_node/BinaryTreeNode.java @@ -0,0 +1,166 @@ +package org.wsc.tree_node; + +import org.wsc.exception.NullElementException; +import org.wsc.exception.RepeatingElementException; + +/** + * BinaryTreeNode 二叉树结构 + * + * + * @author Administrator + * @date 2017年2月26日下午5:47:32 + * @version v1.0 + * + * @param + * 必须实现Comparable接口 + */ +@SuppressWarnings("rawtypes") +public class BinaryTreeNode { + + /** 左节点 */ + private BinaryTreeNode left; + /** 数据区 */ + private E data; + /** 右节点 */ + private BinaryTreeNode right; + + /** + * 插入 + * + * @param data + * @return + */ + @SuppressWarnings("unchecked") + public BinaryTreeNode insert(E data) { + if (data == null) + throw new NullElementException("Do not insert a null"); + // 当前数据区为空,则将data放入数据区 + if (this.data == null) { + this.data = data; + return this; + } + // 对比当前数据区数据和data大小 + int result = this.data.compareTo(data); + // 如果相等,则抛出异常 + if (result == 0) + throw new RepeatingElementException("Do not insert duplicate element"); + // 当前数据区数据大于data,将data递归放入左节点 + if (result > 0) { + // 左节点为空,则将数据置入左节点 + if (left == null) + left = new BinaryTreeNode(data); + else// 左节点不为空,则将数据递归置入左节点 + left.insert(data); + } else { + // 右节点为空,则将数据置入右节点 + if (right == null) + right = new BinaryTreeNode(data); + else// 右节点不为空,则将数据递归置入右节点 + right.insert(data); + } + return this; + } + + /** + * 查询 + * + * @param data + * @return + */ + @SuppressWarnings("unchecked") + public BinaryTreeNode seek(E data) { + checkCurrElement(); + if (data == null) + return null; + // 对比当前数据区数据和data大小 + int result = this.data.compareTo(data); + if (result == 0) { + return this; + } else if (result > 0) {// 当前数据区数据大于data,递归对比左节点 + return left == null ? null : left.seek(data); + } else {// 当前数据区数据小于data,递归对比右节点 + return right == null ? null : right.seek(data); + } + + } + + /** + * 删除 + * + * @param data + * @return + */ + public BinaryTreeNode remove(E data) { + return removeChild(null, data); + } + + @SuppressWarnings("unchecked") + public BinaryTreeNode removeChild(BinaryTreeNode supNode, E data) { + checkCurrElement(); + if (data == null) + return null; + // 对比当前数据区数据和data大小 + int result = this.data.compareTo(data); + // 如果相同,将通过父节点将子节点引用置为null + if (supNode != null && result == 0) { + if (supNode.left == this) + supNode.left = null; + else + supNode.right = null; + } else if (result > 0) {// 当前数据区数据大于data,递归对比左节点 + return left == null ? null : left.removeChild(this, data); + } else {// 当前数据区数据小于data,递归对比右节点 + return right == null ? null : right.removeChild(this, data); + } + return this; + } + + /** + * 检查当前节点元素是否有效 + */ + private void checkCurrElement() { + if (this.data == null) + throw new NullElementException("The current node element is null"); + } + + public BinaryTreeNode() { + super(); + } + + public BinaryTreeNode(E data) { + super(); + this.data = data; + } + + public BinaryTreeNode(BinaryTreeNode left, E data, BinaryTreeNode right) { + super(); + this.left = left; + this.data = data; + this.right = right; + } + + public E getData() { + return data; + } + + public void setData(E 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; + } + +} From 276d8d1cdaed32fd561aba558a0296ee99c38ed6 Mon Sep 17 00:00:00 2001 From: lralin Date: Sun, 26 Feb 2017 23:36:04 +0800 Subject: [PATCH 024/335] the first homework --- .../src/com/coding/basic/ArrayList.java | 87 ++++++++++ .../src/com/coding/basic/BinaryTreeNode.java | 32 ++++ .../src/com/coding/basic/Iterator.java | 7 + .../src/com/coding/basic/LinkedList.java | 152 ++++++++++++++++++ .../20170226/src/com/coding/basic/List.java | 9 ++ .../20170226/src/com/coding/basic/Queue.java | 44 +++++ .../20170226/src/com/coding/basic/Stack.java | 23 +++ 7 files changed, 354 insertions(+) create mode 100644 group20/872045674/20170226/src/com/coding/basic/ArrayList.java create mode 100644 group20/872045674/20170226/src/com/coding/basic/BinaryTreeNode.java create mode 100644 group20/872045674/20170226/src/com/coding/basic/Iterator.java create mode 100644 group20/872045674/20170226/src/com/coding/basic/LinkedList.java create mode 100644 group20/872045674/20170226/src/com/coding/basic/List.java create mode 100644 group20/872045674/20170226/src/com/coding/basic/Queue.java create mode 100644 group20/872045674/20170226/src/com/coding/basic/Stack.java diff --git a/group20/872045674/20170226/src/com/coding/basic/ArrayList.java b/group20/872045674/20170226/src/com/coding/basic/ArrayList.java new file mode 100644 index 0000000000..8b495831fe --- /dev/null +++ b/group20/872045674/20170226/src/com/coding/basic/ArrayList.java @@ -0,0 +1,87 @@ +package com.coding.basic; + +import java.util.Arrays; + +public class ArrayList implements List { + + private int size = 0; + + private Object[] elementData = new Object[7]; + + public void add(Object o){ + if(size>elementData.length-1){ + ensureCapacity(size); + } + elementData[size++] = o; + } + + public void add(int index, Object o){ + System.out.println(elementData.length+" length"); + System.out.println(size+" size"); + size++; + if(index<0||index>size||index>Integer.MAX_VALUE){ + System.out.println("add 位置输入错误,请输入合理的位置"); + return; + } + if(size>elementData.length-1){ + ensureCapacity(size); + } + System.arraycopy(elementData,index,elementData,index+1,size-index-1); + elementData[index] = o; + } + + public Object get(int index){ + if(index<0||index>size-1){ + System.out.println("get 位置输入错误,请输入合理的位置"); + return null; + } + + return elementData[index]; + } + + public Object remove(int index){ + if(index<0||index>size-1){ + System.out.println("remove 位置输入错误,请输入合理的位置"); + return false; + } + System.arraycopy(elementData,index+1,elementData,index,size-index-1); + elementData[--size]=null; + return true; + } + + public int size(){ + return size; + } + + private void ensureCapacity(int nimCapacity){ + int oldCapacity = elementData.length; + int newCapacity = oldCapacity+(oldCapacity/2+1); + if(newCapacity < nimCapacity){ + newCapacity = nimCapacity; + } + if(newCapacity>Integer.MAX_VALUE){ + newCapacity = Integer.MAX_VALUE; + } + elementData = Arrays.copyOf(elementData,newCapacity); + } + + public static void main(String[] args) { + ArrayList list=new ArrayList(); + + list.add(1); + list.add(2); + list.add(3); + list.add(4); + list.add(2,10); + list.remove(3); + for(int i=0;i Date: Mon, 27 Feb 2017 00:30:58 +0800 Subject: [PATCH 025/335] greenhills <63912401@qq.com> --- .../src/com/coding/basic/ArrayList.java | 14 +++++ .../63912401/src/com/coding/basic/Stack.java | 8 +-- .../63912401/src/com/coding/basic/Stack2.java | 51 +++++++++++++++++++ 3 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 group16/63912401/src/com/coding/basic/Stack2.java diff --git a/group16/63912401/src/com/coding/basic/ArrayList.java b/group16/63912401/src/com/coding/basic/ArrayList.java index a8d16b49a5..f86a2e7a8a 100644 --- a/group16/63912401/src/com/coding/basic/ArrayList.java +++ b/group16/63912401/src/com/coding/basic/ArrayList.java @@ -79,6 +79,13 @@ public Object get(int index){ return elementData[index]; } + /** + * 获取末尾数据 + */ + public Object getLast(){ + return elementData[this.size-1]; + } + /** * 移除索引处数据 */ @@ -95,6 +102,13 @@ public Object remove(int index){ return removed; } + /** + * 移除末尾数据 + */ + public Object removeLast(){ + return remove(this.size-1); + } + /** * 获取数据量 */ diff --git a/group16/63912401/src/com/coding/basic/Stack.java b/group16/63912401/src/com/coding/basic/Stack.java index 8e1865f722..b343c6de1d 100644 --- a/group16/63912401/src/com/coding/basic/Stack.java +++ b/group16/63912401/src/com/coding/basic/Stack.java @@ -7,14 +7,14 @@ * 2017年2月25日 下午9:49:41 */ public class Stack { - private LinkedList elementData = new LinkedList(); + private ArrayList elementData = new ArrayList(); /** * 入栈 * @param o */ public void push(Object o){ - elementData.addFirst(o); + elementData.add(o); } /** @@ -22,7 +22,7 @@ public void push(Object o){ * @return */ public Object pop(){ - return elementData.removeFirst(); + return elementData.removeLast(); } /** @@ -30,7 +30,7 @@ public Object pop(){ * @return */ public Object peek(){ - return elementData.get(0); + return elementData.getLast(); } /** diff --git a/group16/63912401/src/com/coding/basic/Stack2.java b/group16/63912401/src/com/coding/basic/Stack2.java new file mode 100644 index 0000000000..8c10ccdf06 --- /dev/null +++ b/group16/63912401/src/com/coding/basic/Stack2.java @@ -0,0 +1,51 @@ +package com.coding.basic; + +/** + * 栈数据结构 + * Stack + * @author greenhills + * 2017年2月25日 下午9:49:41 + */ +public class Stack2 { + private LinkedList elementData = new LinkedList(); + + /** + * 入栈 + * @param o + */ + public void push(Object o){ + elementData.addFirst(o); + } + + /** + * 出栈 + * @return + */ + public Object pop(){ + return elementData.removeFirst(); + } + + /** + * 获取栈顶数据 + * @return + */ + public Object peek(){ + return elementData.get(0); + } + + /** + * 判断是否为空 + * @return + */ + public boolean isEmpty(){ + return elementData.size()==0; + } + + /** + * 获取栈内数据量 + * @return + */ + public int size(){ + return elementData.size(); + } +} From 23ae157a3aad38ac19a9e1358102f75b3eca0334 Mon Sep 17 00:00:00 2001 From: JayXu Date: Mon, 27 Feb 2017 08:51:10 +0800 Subject: [PATCH 026/335] c --- group15/1511_714512544/.idea/workspace.xml | 189 +++++++++++++-------- 1 file changed, 117 insertions(+), 72 deletions(-) diff --git a/group15/1511_714512544/.idea/workspace.xml b/group15/1511_714512544/.idea/workspace.xml index e9a1aea025..3dc368f566 100644 --- a/group15/1511_714512544/.idea/workspace.xml +++ b/group15/1511_714512544/.idea/workspace.xml @@ -89,8 +89,6 @@ - - @@ -152,6 +150,8 @@ + + @@ -165,7 +165,7 @@ - + @@ -180,32 +180,6 @@ - - - - - - - - - - - @@ -732,6 +706,32 @@ + + + + + + + + + + + @@ -741,11 +741,10 @@ - + - @@ -770,7 +769,10 @@ - + + + + 1487829266287 @@ -864,10 +866,10 @@ - - + @@ -879,21 +881,21 @@ - + - + - + - + @@ -947,6 +949,27 @@ + + + + + + + + + + + + + + + + + + + + + @@ -1012,13 +1035,6 @@ - - - - - - - @@ -1068,13 +1084,6 @@ - - - - - - - @@ -1101,17 +1110,6 @@ - - - - - - - - - - - @@ -1136,14 +1134,6 @@ - - - - - - - - @@ -1199,12 +1189,67 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 033deb02636790db3d87c6abe9fa61b0ea869fc1 Mon Sep 17 00:00:00 2001 From: JayXu Date: Mon, 27 Feb 2017 09:00:51 +0800 Subject: [PATCH 027/335] xuweijay --- .../src/com/coderising/array/ArrayUtil.java | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 group15/1511_714512544/src/com/coderising/array/ArrayUtil.java diff --git a/group15/1511_714512544/src/com/coderising/array/ArrayUtil.java b/group15/1511_714512544/src/com/coderising/array/ArrayUtil.java new file mode 100644 index 0000000000..101259845c --- /dev/null +++ b/group15/1511_714512544/src/com/coderising/array/ArrayUtil.java @@ -0,0 +1,96 @@ +package com.coderising.array; + +public class ArrayUtil { + + /** + * 给定一个整形数组a , 对该数组的值进行置换 + 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7] + 如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7] + * @param origin + * @return + */ + public void reverseArray(int[] origin){ + + } + + /** + * 现在有如下的一个数组: 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; + } + + +} \ No newline at end of file From a27907b8684234086a2a2b94a051574568bf8f2c Mon Sep 17 00:00:00 2001 From: JayXu Date: Mon, 27 Feb 2017 09:04:43 +0800 Subject: [PATCH 028/335] xuweijay --- group15/1511_714512544/.idea/workspace.xml | 157 ++++++++++++++---- .../coderising/litestruts/LoginAction.java | 39 +++++ .../src/com/coderising/litestruts/Struts.java | 34 ++++ .../com/coderising/litestruts/StrutsTest.java | 43 +++++ .../src/com/coderising/litestruts/View.java | 23 +++ .../src/com/coderising/litestruts/struts.xml | 11 ++ 6 files changed, 272 insertions(+), 35 deletions(-) create mode 100644 group15/1511_714512544/src/com/coderising/litestruts/LoginAction.java create mode 100644 group15/1511_714512544/src/com/coderising/litestruts/Struts.java create mode 100644 group15/1511_714512544/src/com/coderising/litestruts/StrutsTest.java create mode 100644 group15/1511_714512544/src/com/coderising/litestruts/View.java create mode 100644 group15/1511_714512544/src/com/coderising/litestruts/struts.xml diff --git a/group15/1511_714512544/.idea/workspace.xml b/group15/1511_714512544/.idea/workspace.xml index 3dc368f566..c7b1dc1894 100644 --- a/group15/1511_714512544/.idea/workspace.xml +++ b/group15/1511_714512544/.idea/workspace.xml @@ -2,6 +2,11 @@ + + + + + @@ -23,6 +28,7 @@ @@ -49,6 +55,7 @@ @@ -76,7 +83,7 @@ - + @@ -128,11 +135,67 @@ @@ -176,36 +239,11 @@ + - - - - - - - - - - - @@ -732,6 +770,32 @@ + + + + + + + + + + + @@ -741,10 +805,9 @@ - + - - + @@ -773,6 +836,7 @@ + 1487829266287 @@ -830,7 +894,14 @@ -