From f73d49c80426482c72d60cc558e8ebae5a682941 Mon Sep 17 00:00:00 2001 From: Administrator Date: Thu, 23 Feb 2017 14:25:16 +0800 Subject: [PATCH 001/475] =?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/475] =?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/475] 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/475] 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 6fcdd56d4440cf4f54a13254bfeab603fe3019fd Mon Sep 17 00:00:00 2001 From: Haochen Date: Sat, 25 Feb 2017 13:49:06 +0800 Subject: [PATCH 005/475] add journal(week 1) --- group01/895457260/journal/week1.md | 24 ++++++++++++++++++++++++ group01/895457260/journal/~$week1.docx | Bin 0 -> 162 bytes 2 files changed, 24 insertions(+) create mode 100644 group01/895457260/journal/week1.md create mode 100644 group01/895457260/journal/~$week1.docx diff --git a/group01/895457260/journal/week1.md b/group01/895457260/journal/week1.md new file mode 100644 index 0000000000..14f35620bc --- /dev/null +++ b/group01/895457260/journal/week1.md @@ -0,0 +1,24 @@ +���ԣ�����÷��ḻ���ҹ����쳣ǿ��Ļ�����Ҳ����������������������������ƺ������ܸ������ֻ����Ĺ��ܣ��������ǽм����������ԭ�����۶�ô���ӣ���ô����Ĺ��ܣ����ܹ��Ϊ���������ݼ��㡣�ӣ������ˣ������룬�򣬷ǡ�����Щ�򵥵ļ��㾭����ϣ�ʵ���������ۻ����ҵ�Ч���� +��ô�������μ��㣿���ǵ�һ�����⡣ +������֪��������ڲ�ʹ�ö����ƣ�Ҳ����0��1�������ü̵���������ܣ����������ܴ��������������߼��ţ���/��/���ţ������߼��ſ�����ɼӷ����ȸ�����������Ȼ��ЩҲ����Զ����Ƶģ�����Щ���������ⲿ�Ķ��������룬�پ���һϵ�б任���õ������ƵĽ������󴫳��ⲿ����ѧ�ġ������߼������ſ����Ѿ����˴�ƪ������˵���� +�ص����⣺��ν��м��㣿����Ҫ��һ���������ܴ��ⲿ����2�����ݣ�Ȼ������ǼӼ��˳����ǣ��ٴ���һ����������һ���������Ƶ������ӷ����Ǽ��������DZ�ġ���������С�ALU��������Arithmetic Logic Unit�������߼���Ԫ����ʵ���ϳ����ܽ���2�����ݽ��м������⣬���ܽ���һ�ѱ�����ݣ��źţ����������������ּ��㣬��Щ���������ͽ����������źš��� +���룺���м��������2�� + �����ź����� +����������� +����ALU���Ϳ��������ָ����ļ��㡣 +�������������ˣ����ݴ������� +��һЩ������������ڴ������ڴ�ʵ�����Ǵ洢�������Ա���������������ڸ�ALU���㡣���洢����Ϊ�ܶ�С���ӣ�ÿ�����Ӷ���Ψһ��ų�Ϊ����ַ�����������ܷ�һ�����ݡ� +�洢���ܽ�������3�����룺1��ַ��2���ݡ�3��д���ƶˡ�������1�������1���������ݡ� +�ٸ����ӣ�����1��ʾ��һ��С���ӣ��������3Ϊ0��ʾ������ô�ͻ�����������������ݣ�����2�ᱻ���ԡ��������3Ϊ1��ʾд����ô�ͻ�������2�����ݸ��ǵ�������ԭ�е����ݣ�����ᱻ���ԡ� +Ҫ��ij���߼���·�ѵ�ַ�����ݡ���д�����͸��ڴ棬Ȼ�����ڴ�������ݴ���ALU���㣬�ٰѽ���ͻ��ڴ档��ALUֻ�ܼ��㣬����߼���·������ALU���������ǿ��԰�ALU������߼���·����һ�𣬽���CPU��Central Processing Unit�����봦������ +��������ݵ���Դ����������ALU�����źŴ����������⡣�ش���Ȼ�ǣ��ڴ档 +�����ź��кܶ����ÿ�������źŶ���1λ�����ƣ����������Ҫ�Ŀ����ź�һ��һ�����ŷŵ��ڴ����ô�Ʊص����ڴ�ռ���˷ѣ���Ϊ�ڴ���һ�������ܴ�źܶ�λ������������Ϊ�ˣ���������һ���߼���·����������һ���ڴ���ӵĶ��������룬�������������������Щ�����źţ�������߼���·�ͽ�����ָ�����������������Ž�CPU�Ӧ�÷Ž�ָ�������������ݣ���Ϊ��ָ��� +��������������̾ͱ���ˣ� +1�����ڴ�ȡ��һ�����ӣ���ָ����Ž�ָ�����������õ�����������źš� +2���ٴ��ڴ�ȡ��2�����ӣ������ݣ�������ALU���м��㡣 +3��������д���ڴ档 +��������̼����������ݶ������ڴ棬ʵ���ϲ��������� +��ʱ�����µ���������ˣ�1��2��ͬ���Ǵ��ڴ�ȡ�����ӣ�����ж�����ָ������ݣ�CPU�ﻹ��һ�������С�PC����Program Counter����������������ܱ���1��������ʾ�ڴ��ַ�����ڴ�ȡָ����PC�ĵ�ַ�͵��ڴ棬��ʱ������ڴ�����ת��ָ�������������ڴ�ȡ�������õ����ݣ����������ʹ��PC�ĵ�ַ����ʱ�ڴ������Ͳ���ָ��ָ��������������ֱ�Ӵ���ALU�� +�����ͨ��ij�ַ�ʽ�����ظ�����ļ�����̣�ֻҪ�ڴ�������ȷ���е�ָ������ݣ�����������Զ������������ڴ�������Ƚ�С�����ܴ�Ź��������ݣ����Ǿ��õ���Ӳ�̡� +Ӳ�̵������󣬿����Ȱ�ָ������ݷŵ�Ӳ�����Ҫʱ�����ڴ���ȡ����дӲ�̺Ͷ�д�ڴ����ơ� +˫��Ӳ�����һ��exe��exe�е�ָ������ݾͻ��Զ������ڴ棬Ȼ����CPU�����㣬���������д��Ӳ�̡� +����ƪ���º����˼Ĵ��������桢���ߵȹ��죬�����������ݶ����������ڴ棩 diff --git a/group01/895457260/journal/~$week1.docx b/group01/895457260/journal/~$week1.docx new file mode 100644 index 0000000000000000000000000000000000000000..57dc40002ce63cb9d904e5c545d5eff9625db2fe GIT binary patch literal 162 zcmZSgNX$>pNX=s)39vJGFeEbMGbA%)Fr+ddG@rlmA&x Date: Sat, 25 Feb 2017 13:53:25 +0800 Subject: [PATCH 006/475] test --- .../week1 - \345\211\257\346\234\254.md" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "group01/895457260/journal/week1 - \345\211\257\346\234\254.md" diff --git "a/group01/895457260/journal/week1 - \345\211\257\346\234\254.md" "b/group01/895457260/journal/week1 - \345\211\257\346\234\254.md" new file mode 100644 index 0000000000..14f35620bc --- /dev/null +++ "b/group01/895457260/journal/week1 - \345\211\257\346\234\254.md" @@ -0,0 +1,24 @@ +���ԣ�����÷��ḻ���ҹ����쳣ǿ��Ļ�����Ҳ����������������������������ƺ������ܸ������ֻ����Ĺ��ܣ��������ǽм����������ԭ�����۶�ô���ӣ���ô����Ĺ��ܣ����ܹ��Ϊ���������ݼ��㡣�ӣ������ˣ������룬�򣬷ǡ�����Щ�򵥵ļ��㾭����ϣ�ʵ���������ۻ����ҵ�Ч���� +��ô�������μ��㣿���ǵ�һ�����⡣ +������֪��������ڲ�ʹ�ö����ƣ�Ҳ����0��1�������ü̵���������ܣ����������ܴ��������������߼��ţ���/��/���ţ������߼��ſ�����ɼӷ����ȸ�����������Ȼ��ЩҲ����Զ����Ƶģ�����Щ���������ⲿ�Ķ��������룬�پ���һϵ�б任���õ������ƵĽ������󴫳��ⲿ����ѧ�ġ������߼������ſ����Ѿ����˴�ƪ������˵���� +�ص����⣺��ν��м��㣿����Ҫ��һ���������ܴ��ⲿ����2�����ݣ�Ȼ������ǼӼ��˳����ǣ��ٴ���һ����������һ���������Ƶ������ӷ����Ǽ��������DZ�ġ���������С�ALU��������Arithmetic Logic Unit�������߼���Ԫ����ʵ���ϳ����ܽ���2�����ݽ��м������⣬���ܽ���һ�ѱ�����ݣ��źţ����������������ּ��㣬��Щ���������ͽ����������źš��� +���룺���м��������2�� + �����ź����� +����������� +����ALU���Ϳ��������ָ����ļ��㡣 +�������������ˣ����ݴ������� +��һЩ������������ڴ������ڴ�ʵ�����Ǵ洢�������Ա���������������ڸ�ALU���㡣���洢����Ϊ�ܶ�С���ӣ�ÿ�����Ӷ���Ψһ��ų�Ϊ����ַ�����������ܷ�һ�����ݡ� +�洢���ܽ�������3�����룺1��ַ��2���ݡ�3��д���ƶˡ�������1�������1���������ݡ� +�ٸ����ӣ�����1��ʾ��һ��С���ӣ��������3Ϊ0��ʾ������ô�ͻ�����������������ݣ�����2�ᱻ���ԡ��������3Ϊ1��ʾд����ô�ͻ�������2�����ݸ��ǵ�������ԭ�е����ݣ�����ᱻ���ԡ� +Ҫ��ij���߼���·�ѵ�ַ�����ݡ���д�����͸��ڴ棬Ȼ�����ڴ�������ݴ���ALU���㣬�ٰѽ���ͻ��ڴ档��ALUֻ�ܼ��㣬����߼���·������ALU���������ǿ��԰�ALU������߼���·����һ�𣬽���CPU��Central Processing Unit�����봦������ +��������ݵ���Դ����������ALU�����źŴ����������⡣�ش���Ȼ�ǣ��ڴ档 +�����ź��кܶ����ÿ�������źŶ���1λ�����ƣ����������Ҫ�Ŀ����ź�һ��һ�����ŷŵ��ڴ����ô�Ʊص����ڴ�ռ���˷ѣ���Ϊ�ڴ���һ�������ܴ�źܶ�λ������������Ϊ�ˣ���������һ���߼���·����������һ���ڴ���ӵĶ��������룬�������������������Щ�����źţ�������߼���·�ͽ�����ָ�����������������Ž�CPU�Ӧ�÷Ž�ָ�������������ݣ���Ϊ��ָ��� +��������������̾ͱ���ˣ� +1�����ڴ�ȡ��һ�����ӣ���ָ����Ž�ָ�����������õ�����������źš� +2���ٴ��ڴ�ȡ��2�����ӣ������ݣ�������ALU���м��㡣 +3��������д���ڴ档 +��������̼����������ݶ������ڴ棬ʵ���ϲ��������� +��ʱ�����µ���������ˣ�1��2��ͬ���Ǵ��ڴ�ȡ�����ӣ�����ж�����ָ������ݣ�CPU�ﻹ��һ�������С�PC����Program Counter����������������ܱ���1��������ʾ�ڴ��ַ�����ڴ�ȡָ����PC�ĵ�ַ�͵��ڴ棬��ʱ������ڴ�����ת��ָ�������������ڴ�ȡ�������õ����ݣ����������ʹ��PC�ĵ�ַ����ʱ�ڴ������Ͳ���ָ��ָ��������������ֱ�Ӵ���ALU�� +�����ͨ��ij�ַ�ʽ�����ظ�����ļ�����̣�ֻҪ�ڴ�������ȷ���е�ָ������ݣ�����������Զ������������ڴ�������Ƚ�С�����ܴ�Ź��������ݣ����Ǿ��õ���Ӳ�̡� +Ӳ�̵������󣬿����Ȱ�ָ������ݷŵ�Ӳ�����Ҫʱ�����ڴ���ȡ����дӲ�̺Ͷ�д�ڴ����ơ� +˫��Ӳ�����һ��exe��exe�е�ָ������ݾͻ��Զ������ڴ棬Ȼ����CPU�����㣬���������д��Ӳ�̡� +����ƪ���º����˼Ĵ��������桢���ߵȹ��죬�����������ݶ����������ڴ棩 From ccb758cf84b233a4adf38a97256f4ca703d321d3 Mon Sep 17 00:00:00 2001 From: Haochen Date: Sat, 25 Feb 2017 13:54:05 +0800 Subject: [PATCH 007/475] test --- .../week1 - \345\211\257\346\234\254.md" | 24 ------------------ group01/895457260/journal/week1.md | 24 ------------------ group01/895457260/journal/~$week1.docx | Bin 162 -> 0 bytes 3 files changed, 48 deletions(-) delete mode 100644 "group01/895457260/journal/week1 - \345\211\257\346\234\254.md" delete mode 100644 group01/895457260/journal/week1.md delete mode 100644 group01/895457260/journal/~$week1.docx diff --git "a/group01/895457260/journal/week1 - \345\211\257\346\234\254.md" "b/group01/895457260/journal/week1 - \345\211\257\346\234\254.md" deleted file mode 100644 index 14f35620bc..0000000000 --- "a/group01/895457260/journal/week1 - \345\211\257\346\234\254.md" +++ /dev/null @@ -1,24 +0,0 @@ -���ԣ�����÷��ḻ���ҹ����쳣ǿ��Ļ�����Ҳ����������������������������ƺ������ܸ������ֻ����Ĺ��ܣ��������ǽм����������ԭ�����۶�ô���ӣ���ô����Ĺ��ܣ����ܹ��Ϊ���������ݼ��㡣�ӣ������ˣ������룬�򣬷ǡ�����Щ�򵥵ļ��㾭����ϣ�ʵ���������ۻ����ҵ�Ч���� -��ô�������μ��㣿���ǵ�һ�����⡣ -������֪��������ڲ�ʹ�ö����ƣ�Ҳ����0��1�������ü̵���������ܣ����������ܴ��������������߼��ţ���/��/���ţ������߼��ſ�����ɼӷ����ȸ�����������Ȼ��ЩҲ����Զ����Ƶģ�����Щ���������ⲿ�Ķ��������룬�پ���һϵ�б任���õ������ƵĽ������󴫳��ⲿ����ѧ�ġ������߼������ſ����Ѿ����˴�ƪ������˵���� -�ص����⣺��ν��м��㣿����Ҫ��һ���������ܴ��ⲿ����2�����ݣ�Ȼ������ǼӼ��˳����ǣ��ٴ���һ����������һ���������Ƶ������ӷ����Ǽ��������DZ�ġ���������С�ALU��������Arithmetic Logic Unit�������߼���Ԫ����ʵ���ϳ����ܽ���2�����ݽ��м������⣬���ܽ���һ�ѱ�����ݣ��źţ����������������ּ��㣬��Щ���������ͽ����������źš��� -���룺���м��������2�� + �����ź����� -����������� -����ALU���Ϳ��������ָ����ļ��㡣 -�������������ˣ����ݴ������� -��һЩ������������ڴ������ڴ�ʵ�����Ǵ洢�������Ա���������������ڸ�ALU���㡣���洢����Ϊ�ܶ�С���ӣ�ÿ�����Ӷ���Ψһ��ų�Ϊ����ַ�����������ܷ�һ�����ݡ� -�洢���ܽ�������3�����룺1��ַ��2���ݡ�3��д���ƶˡ�������1�������1���������ݡ� -�ٸ����ӣ�����1��ʾ��һ��С���ӣ��������3Ϊ0��ʾ������ô�ͻ�����������������ݣ�����2�ᱻ���ԡ��������3Ϊ1��ʾд����ô�ͻ�������2�����ݸ��ǵ�������ԭ�е����ݣ�����ᱻ���ԡ� -Ҫ��ij���߼���·�ѵ�ַ�����ݡ���д�����͸��ڴ棬Ȼ�����ڴ�������ݴ���ALU���㣬�ٰѽ���ͻ��ڴ档��ALUֻ�ܼ��㣬����߼���·������ALU���������ǿ��԰�ALU������߼���·����һ�𣬽���CPU��Central Processing Unit�����봦������ -��������ݵ���Դ����������ALU�����źŴ����������⡣�ش���Ȼ�ǣ��ڴ档 -�����ź��кܶ����ÿ�������źŶ���1λ�����ƣ����������Ҫ�Ŀ����ź�һ��һ�����ŷŵ��ڴ����ô�Ʊص����ڴ�ռ���˷ѣ���Ϊ�ڴ���һ�������ܴ�źܶ�λ������������Ϊ�ˣ���������һ���߼���·����������һ���ڴ���ӵĶ��������룬�������������������Щ�����źţ�������߼���·�ͽ�����ָ�����������������Ž�CPU�Ӧ�÷Ž�ָ�������������ݣ���Ϊ��ָ��� -��������������̾ͱ���ˣ� -1�����ڴ�ȡ��һ�����ӣ���ָ����Ž�ָ�����������õ�����������źš� -2���ٴ��ڴ�ȡ��2�����ӣ������ݣ�������ALU���м��㡣 -3��������д���ڴ档 -��������̼����������ݶ������ڴ棬ʵ���ϲ��������� -��ʱ�����µ���������ˣ�1��2��ͬ���Ǵ��ڴ�ȡ�����ӣ�����ж�����ָ������ݣ�CPU�ﻹ��һ�������С�PC����Program Counter����������������ܱ���1��������ʾ�ڴ��ַ�����ڴ�ȡָ����PC�ĵ�ַ�͵��ڴ棬��ʱ������ڴ�����ת��ָ�������������ڴ�ȡ�������õ����ݣ����������ʹ��PC�ĵ�ַ����ʱ�ڴ������Ͳ���ָ��ָ��������������ֱ�Ӵ���ALU�� -�����ͨ��ij�ַ�ʽ�����ظ�����ļ�����̣�ֻҪ�ڴ�������ȷ���е�ָ������ݣ�����������Զ������������ڴ�������Ƚ�С�����ܴ�Ź��������ݣ����Ǿ��õ���Ӳ�̡� -Ӳ�̵������󣬿����Ȱ�ָ������ݷŵ�Ӳ�����Ҫʱ�����ڴ���ȡ����дӲ�̺Ͷ�д�ڴ����ơ� -˫��Ӳ�����һ��exe��exe�е�ָ������ݾͻ��Զ������ڴ棬Ȼ����CPU�����㣬���������д��Ӳ�̡� -����ƪ���º����˼Ĵ��������桢���ߵȹ��죬�����������ݶ����������ڴ棩 diff --git a/group01/895457260/journal/week1.md b/group01/895457260/journal/week1.md deleted file mode 100644 index 14f35620bc..0000000000 --- a/group01/895457260/journal/week1.md +++ /dev/null @@ -1,24 +0,0 @@ -���ԣ�����÷��ḻ���ҹ����쳣ǿ��Ļ�����Ҳ����������������������������ƺ������ܸ������ֻ����Ĺ��ܣ��������ǽм����������ԭ�����۶�ô���ӣ���ô����Ĺ��ܣ����ܹ��Ϊ���������ݼ��㡣�ӣ������ˣ������룬�򣬷ǡ�����Щ�򵥵ļ��㾭����ϣ�ʵ���������ۻ����ҵ�Ч���� -��ô�������μ��㣿���ǵ�һ�����⡣ -������֪��������ڲ�ʹ�ö����ƣ�Ҳ����0��1�������ü̵���������ܣ����������ܴ��������������߼��ţ���/��/���ţ������߼��ſ�����ɼӷ����ȸ�����������Ȼ��ЩҲ����Զ����Ƶģ�����Щ���������ⲿ�Ķ��������룬�پ���һϵ�б任���õ������ƵĽ������󴫳��ⲿ����ѧ�ġ������߼������ſ����Ѿ����˴�ƪ������˵���� -�ص����⣺��ν��м��㣿����Ҫ��һ���������ܴ��ⲿ����2�����ݣ�Ȼ������ǼӼ��˳����ǣ��ٴ���һ����������һ���������Ƶ������ӷ����Ǽ��������DZ�ġ���������С�ALU��������Arithmetic Logic Unit�������߼���Ԫ����ʵ���ϳ����ܽ���2�����ݽ��м������⣬���ܽ���һ�ѱ�����ݣ��źţ����������������ּ��㣬��Щ���������ͽ����������źš��� -���룺���м��������2�� + �����ź����� -����������� -����ALU���Ϳ��������ָ����ļ��㡣 -�������������ˣ����ݴ������� -��һЩ������������ڴ������ڴ�ʵ�����Ǵ洢�������Ա���������������ڸ�ALU���㡣���洢����Ϊ�ܶ�С���ӣ�ÿ�����Ӷ���Ψһ��ų�Ϊ����ַ�����������ܷ�һ�����ݡ� -�洢���ܽ�������3�����룺1��ַ��2���ݡ�3��д���ƶˡ�������1�������1���������ݡ� -�ٸ����ӣ�����1��ʾ��һ��С���ӣ��������3Ϊ0��ʾ������ô�ͻ�����������������ݣ�����2�ᱻ���ԡ��������3Ϊ1��ʾд����ô�ͻ�������2�����ݸ��ǵ�������ԭ�е����ݣ�����ᱻ���ԡ� -Ҫ��ij���߼���·�ѵ�ַ�����ݡ���д�����͸��ڴ棬Ȼ�����ڴ�������ݴ���ALU���㣬�ٰѽ���ͻ��ڴ档��ALUֻ�ܼ��㣬����߼���·������ALU���������ǿ��԰�ALU������߼���·����һ�𣬽���CPU��Central Processing Unit�����봦������ -��������ݵ���Դ����������ALU�����źŴ����������⡣�ش���Ȼ�ǣ��ڴ档 -�����ź��кܶ����ÿ�������źŶ���1λ�����ƣ����������Ҫ�Ŀ����ź�һ��һ�����ŷŵ��ڴ����ô�Ʊص����ڴ�ռ���˷ѣ���Ϊ�ڴ���һ�������ܴ�źܶ�λ������������Ϊ�ˣ���������һ���߼���·����������һ���ڴ���ӵĶ��������룬�������������������Щ�����źţ�������߼���·�ͽ�����ָ�����������������Ž�CPU�Ӧ�÷Ž�ָ�������������ݣ���Ϊ��ָ��� -��������������̾ͱ���ˣ� -1�����ڴ�ȡ��һ�����ӣ���ָ����Ž�ָ�����������õ�����������źš� -2���ٴ��ڴ�ȡ��2�����ӣ������ݣ�������ALU���м��㡣 -3��������д���ڴ档 -��������̼����������ݶ������ڴ棬ʵ���ϲ��������� -��ʱ�����µ���������ˣ�1��2��ͬ���Ǵ��ڴ�ȡ�����ӣ�����ж�����ָ������ݣ�CPU�ﻹ��һ�������С�PC����Program Counter����������������ܱ���1��������ʾ�ڴ��ַ�����ڴ�ȡָ����PC�ĵ�ַ�͵��ڴ棬��ʱ������ڴ�����ת��ָ�������������ڴ�ȡ�������õ����ݣ����������ʹ��PC�ĵ�ַ����ʱ�ڴ������Ͳ���ָ��ָ��������������ֱ�Ӵ���ALU�� -�����ͨ��ij�ַ�ʽ�����ظ�����ļ�����̣�ֻҪ�ڴ�������ȷ���е�ָ������ݣ�����������Զ������������ڴ�������Ƚ�С�����ܴ�Ź��������ݣ����Ǿ��õ���Ӳ�̡� -Ӳ�̵������󣬿����Ȱ�ָ������ݷŵ�Ӳ�����Ҫʱ�����ڴ���ȡ����дӲ�̺Ͷ�д�ڴ����ơ� -˫��Ӳ�����һ��exe��exe�е�ָ������ݾͻ��Զ������ڴ棬Ȼ����CPU�����㣬���������д��Ӳ�̡� -����ƪ���º����˼Ĵ��������桢���ߵȹ��죬�����������ݶ����������ڴ棩 diff --git a/group01/895457260/journal/~$week1.docx b/group01/895457260/journal/~$week1.docx deleted file mode 100644 index 57dc40002ce63cb9d904e5c545d5eff9625db2fe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 162 zcmZSgNX$>pNX=s)39vJGFeEbMGbA%)Fr+ddG@rlmA&x Date: Sat, 25 Feb 2017 13:55:08 +0800 Subject: [PATCH 008/475] add journal(week 1) --- group01/895457260/journal/week1.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 group01/895457260/journal/week1.md diff --git a/group01/895457260/journal/week1.md b/group01/895457260/journal/week1.md new file mode 100644 index 0000000000..14f35620bc --- /dev/null +++ b/group01/895457260/journal/week1.md @@ -0,0 +1,24 @@ +���ԣ�����÷��ḻ���ҹ����쳣ǿ��Ļ�����Ҳ����������������������������ƺ������ܸ������ֻ����Ĺ��ܣ��������ǽм����������ԭ�����۶�ô���ӣ���ô����Ĺ��ܣ����ܹ��Ϊ���������ݼ��㡣�ӣ������ˣ������룬�򣬷ǡ�����Щ�򵥵ļ��㾭����ϣ�ʵ���������ۻ����ҵ�Ч���� +��ô�������μ��㣿���ǵ�һ�����⡣ +������֪��������ڲ�ʹ�ö����ƣ�Ҳ����0��1�������ü̵���������ܣ����������ܴ��������������߼��ţ���/��/���ţ������߼��ſ�����ɼӷ����ȸ�����������Ȼ��ЩҲ����Զ����Ƶģ�����Щ���������ⲿ�Ķ��������룬�پ���һϵ�б任���õ������ƵĽ������󴫳��ⲿ����ѧ�ġ������߼������ſ����Ѿ����˴�ƪ������˵���� +�ص����⣺��ν��м��㣿����Ҫ��һ���������ܴ��ⲿ����2�����ݣ�Ȼ������ǼӼ��˳����ǣ��ٴ���һ����������һ���������Ƶ������ӷ����Ǽ��������DZ�ġ���������С�ALU��������Arithmetic Logic Unit�������߼���Ԫ����ʵ���ϳ����ܽ���2�����ݽ��м������⣬���ܽ���һ�ѱ�����ݣ��źţ����������������ּ��㣬��Щ���������ͽ����������źš��� +���룺���м��������2�� + �����ź����� +����������� +����ALU���Ϳ��������ָ����ļ��㡣 +�������������ˣ����ݴ������� +��һЩ������������ڴ������ڴ�ʵ�����Ǵ洢�������Ա���������������ڸ�ALU���㡣���洢����Ϊ�ܶ�С���ӣ�ÿ�����Ӷ���Ψһ��ų�Ϊ����ַ�����������ܷ�һ�����ݡ� +�洢���ܽ�������3�����룺1��ַ��2���ݡ�3��д���ƶˡ�������1�������1���������ݡ� +�ٸ����ӣ�����1��ʾ��һ��С���ӣ��������3Ϊ0��ʾ������ô�ͻ�����������������ݣ�����2�ᱻ���ԡ��������3Ϊ1��ʾд����ô�ͻ�������2�����ݸ��ǵ�������ԭ�е����ݣ�����ᱻ���ԡ� +Ҫ��ij���߼���·�ѵ�ַ�����ݡ���д�����͸��ڴ棬Ȼ�����ڴ�������ݴ���ALU���㣬�ٰѽ���ͻ��ڴ档��ALUֻ�ܼ��㣬����߼���·������ALU���������ǿ��԰�ALU������߼���·����һ�𣬽���CPU��Central Processing Unit�����봦������ +��������ݵ���Դ����������ALU�����źŴ����������⡣�ش���Ȼ�ǣ��ڴ档 +�����ź��кܶ����ÿ�������źŶ���1λ�����ƣ����������Ҫ�Ŀ����ź�һ��һ�����ŷŵ��ڴ����ô�Ʊص����ڴ�ռ���˷ѣ���Ϊ�ڴ���һ�������ܴ�źܶ�λ������������Ϊ�ˣ���������һ���߼���·����������һ���ڴ���ӵĶ��������룬�������������������Щ�����źţ�������߼���·�ͽ�����ָ�����������������Ž�CPU�Ӧ�÷Ž�ָ�������������ݣ���Ϊ��ָ��� +��������������̾ͱ���ˣ� +1�����ڴ�ȡ��һ�����ӣ���ָ����Ž�ָ�����������õ�����������źš� +2���ٴ��ڴ�ȡ��2�����ӣ������ݣ�������ALU���м��㡣 +3��������д���ڴ档 +��������̼����������ݶ������ڴ棬ʵ���ϲ��������� +��ʱ�����µ���������ˣ�1��2��ͬ���Ǵ��ڴ�ȡ�����ӣ�����ж�����ָ������ݣ�CPU�ﻹ��һ�������С�PC����Program Counter����������������ܱ���1��������ʾ�ڴ��ַ�����ڴ�ȡָ����PC�ĵ�ַ�͵��ڴ棬��ʱ������ڴ�����ת��ָ�������������ڴ�ȡ�������õ����ݣ����������ʹ��PC�ĵ�ַ����ʱ�ڴ������Ͳ���ָ��ָ��������������ֱ�Ӵ���ALU�� +�����ͨ��ij�ַ�ʽ�����ظ�����ļ�����̣�ֻҪ�ڴ�������ȷ���е�ָ������ݣ�����������Զ������������ڴ�������Ƚ�С�����ܴ�Ź��������ݣ����Ǿ��õ���Ӳ�̡� +Ӳ�̵������󣬿����Ȱ�ָ������ݷŵ�Ӳ�����Ҫʱ�����ڴ���ȡ����дӲ�̺Ͷ�д�ڴ����ơ� +˫��Ӳ�����һ��exe��exe�е�ָ������ݾͻ��Զ������ڴ棬Ȼ����CPU�����㣬���������д��Ӳ�̡� +����ƪ���º����˼Ĵ��������桢���ߵȹ��죬�����������ݶ����������ڴ棩 From 6d51daee20facff61eb1242307b620ec0d8af389 Mon Sep 17 00:00:00 2001 From: Viscaria233 Date: Sat, 25 Feb 2017 14:13:38 +0800 Subject: [PATCH 009/475] update week1.md --- group01/895457260/journal/week1.md | 58 +++++++++++++++++------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/group01/895457260/journal/week1.md b/group01/895457260/journal/week1.md index 14f35620bc..4c93a1638e 100644 --- a/group01/895457260/journal/week1.md +++ b/group01/895457260/journal/week1.md @@ -1,24 +1,34 @@ -���ԣ�����÷��ḻ���ҹ����쳣ǿ��Ļ�����Ҳ����������������������������ƺ������ܸ������ֻ����Ĺ��ܣ��������ǽм����������ԭ�����۶�ô���ӣ���ô����Ĺ��ܣ����ܹ��Ϊ���������ݼ��㡣�ӣ������ˣ������룬�򣬷ǡ�����Щ�򵥵ļ��㾭����ϣ�ʵ���������ۻ����ҵ�Ч���� -��ô�������μ��㣿���ǵ�һ�����⡣ -������֪��������ڲ�ʹ�ö����ƣ�Ҳ����0��1�������ü̵���������ܣ����������ܴ��������������߼��ţ���/��/���ţ������߼��ſ�����ɼӷ����ȸ�����������Ȼ��ЩҲ����Զ����Ƶģ�����Щ���������ⲿ�Ķ��������룬�پ���һϵ�б任���õ������ƵĽ������󴫳��ⲿ����ѧ�ġ������߼������ſ����Ѿ����˴�ƪ������˵���� -�ص����⣺��ν��м��㣿����Ҫ��һ���������ܴ��ⲿ����2�����ݣ�Ȼ������ǼӼ��˳����ǣ��ٴ���һ����������һ���������Ƶ������ӷ����Ǽ��������DZ�ġ���������С�ALU��������Arithmetic Logic Unit�������߼���Ԫ����ʵ���ϳ����ܽ���2�����ݽ��м������⣬���ܽ���һ�ѱ�����ݣ��źţ����������������ּ��㣬��Щ���������ͽ����������źš��� -���룺���м��������2�� + �����ź����� -����������� -����ALU���Ϳ��������ָ����ļ��㡣 -�������������ˣ����ݴ������� -��һЩ������������ڴ������ڴ�ʵ�����Ǵ洢�������Ա���������������ڸ�ALU���㡣���洢����Ϊ�ܶ�С���ӣ�ÿ�����Ӷ���Ψһ��ų�Ϊ����ַ�����������ܷ�һ�����ݡ� -�洢���ܽ�������3�����룺1��ַ��2���ݡ�3��д���ƶˡ�������1�������1���������ݡ� -�ٸ����ӣ�����1��ʾ��һ��С���ӣ��������3Ϊ0��ʾ������ô�ͻ�����������������ݣ�����2�ᱻ���ԡ��������3Ϊ1��ʾд����ô�ͻ�������2�����ݸ��ǵ�������ԭ�е����ݣ�����ᱻ���ԡ� -Ҫ��ij���߼���·�ѵ�ַ�����ݡ���д�����͸��ڴ棬Ȼ�����ڴ�������ݴ���ALU���㣬�ٰѽ���ͻ��ڴ档��ALUֻ�ܼ��㣬����߼���·������ALU���������ǿ��԰�ALU������߼���·����һ�𣬽���CPU��Central Processing Unit�����봦������ -��������ݵ���Դ����������ALU�����źŴ����������⡣�ش���Ȼ�ǣ��ڴ档 -�����ź��кܶ����ÿ�������źŶ���1λ�����ƣ����������Ҫ�Ŀ����ź�һ��һ�����ŷŵ��ڴ����ô�Ʊص����ڴ�ռ���˷ѣ���Ϊ�ڴ���һ�������ܴ�źܶ�λ������������Ϊ�ˣ���������һ���߼���·����������һ���ڴ���ӵĶ��������룬�������������������Щ�����źţ�������߼���·�ͽ�����ָ�����������������Ž�CPU�Ӧ�÷Ž�ָ�������������ݣ���Ϊ��ָ��� -��������������̾ͱ���ˣ� -1�����ڴ�ȡ��һ�����ӣ���ָ����Ž�ָ�����������õ�����������źš� -2���ٴ��ڴ�ȡ��2�����ӣ������ݣ�������ALU���м��㡣 -3��������д���ڴ档 -��������̼����������ݶ������ڴ棬ʵ���ϲ��������� -��ʱ�����µ���������ˣ�1��2��ͬ���Ǵ��ڴ�ȡ�����ӣ�����ж�����ָ������ݣ�CPU�ﻹ��һ�������С�PC����Program Counter����������������ܱ���1��������ʾ�ڴ��ַ�����ڴ�ȡָ����PC�ĵ�ַ�͵��ڴ棬��ʱ������ڴ�����ת��ָ�������������ڴ�ȡ�������õ����ݣ����������ʹ��PC�ĵ�ַ����ʱ�ڴ������Ͳ���ָ��ָ��������������ֱ�Ӵ���ALU�� -�����ͨ��ij�ַ�ʽ�����ظ�����ļ�����̣�ֻҪ�ڴ�������ȷ���е�ָ������ݣ�����������Զ������������ڴ�������Ƚ�С�����ܴ�Ź��������ݣ����Ǿ��õ���Ӳ�̡� -Ӳ�̵������󣬿����Ȱ�ָ������ݷŵ�Ӳ�����Ҫʱ�����ڴ���ȡ����дӲ�̺Ͷ�д�ڴ����ơ� -˫��Ӳ�����һ��exe��exe�е�ָ������ݾͻ��Զ������ڴ棬Ȼ����CPU�����㣬���������д��Ӳ�̡� -����ƪ���º����˼Ĵ��������桢���ߵȹ��죬�����������ݶ����������ڴ棩 +# 标题 +  电脑,这个用法丰富而且功能异常强大的机器,也叫做计算机。计算机这个词听起来似乎并不能概括这种机器的功能,但它就是叫计算机。究其原因,无论多么复杂,多么神奇的功能,都能归结为大量的数据计算。加,减,乘,除,与,或,非……这些简单的计算经过组合,实现了令人眼花缭乱的效果。 +  那么计算机如何计算?这是第一个问题。 +  众所周知,计算机内部使用二进制,也就是0和1。而利用继电器(或晶体管)可以做成能处理二进制数的逻辑门(与/或/非门),用逻辑门可以组成加法器等各种器件(当然这些也是针对二进制的)。这些器件接受外部的二进制输入,再经过一系列变换,得到二进制的结果,最后传出外部。大学的“数字逻辑”这门课里已经花了大篇幅进行说明。 +## 如何进行计算:ALU +  首先要有一个东西,能从外部接受2个数据,然后把它们加减乘除与或非,再传出一个结果,而且还能随意控制到底做加法还是减法,还是别的。这个东西叫“ALU”,就是Arithmetic Logic Unit,算术逻辑单元。它实际上除了能接受2个数据进行计算以外,还能接受一堆别的数据(信号),用来控制做哪种计算,这些额外的输入就叫做“控制信号”。 +``` +    ALU +    输入:进行计算的数据2个 + 控制信号若干 +    输出:计算结果 +``` +  有了ALU,就可以做各种各样的计算。 +## 数据的来源和去处:内存 +  有一些数据来自你的内存条。内存实际上是存储器,可以保存二进制数,用于给ALU计算。这块存储器分为很多小格子,每个格子都有唯一编号称为“地址”,格子里能放一个数据。 +  存储器能接受至少3个输入:1地址、2数据、3读写控制端。有至少1个输出:1读出的数据。 +  举个例子:输入1表示了一个小格子,如果输入3为0表示读,那么就会输出这个格子里的数据,输入2会被忽略。如果输入3为1表示写,那么就会用输入2的数据覆盖掉格子里原有的数据,输出会被忽略。 +## ALU和内存交互:组成CPU +  要有某块逻辑电路把地址、数据、读写控制送给内存,然后获得内存里的数据传给ALU计算,再把结果送回内存。但ALU只能计算,这块逻辑电路不属于ALU,于是我们可以把ALU和这块逻辑电路放在一起,叫做CPU,Central Processing Unit,中央处理器。 +## 控制信号:指令译码 +  控制信号有很多个(每个控制信号都是1位二进制),如果把需要的控制信号一个一个并排放到内存里,那么势必导致内存空间的浪费(因为内存里一个格子能存放很多位二进制数),为此,我们另拿一块逻辑电路,让它接受一个内存格子的二进制输入,产生若干输出(就是那些控制信号)。这个逻辑电路就叫做“指令译码器”,把它放进CPU里。应该放进指令译码器的数据,称为“指令”。 +  于是整个计算过程就变成了: +``` +    1、从内存取出一个格子(是指令),放进指令译码器,得到若干组控制信号。 +    2、再从内存取出2个格子(是数据),传给ALU进行计算。 +    3、计算结果写回内存。 +``` +    (这个过程假设所有数据都来自内存,实际上并非这样) +## 区分指令和数据 +  这时又有新的问题产生了:1和2中同样是从内存取出格子,如何判断它是指令还是数据?CPU里还有一个东西叫“PC”,Program Counter,程序计数器。它能保存1个数,表示内存地址。从内存取指令,会把PC的地址送到内存,这时会控制内存的输出转向指令译码器。从内存取计算所用的数据,这个操作不使用PC的地址,那时内存的输出就不会指向指令译码器,而是直接传给ALU。 +## 更大的存储空间:硬盘 +  计算机通过某种方式不断重复上面的计算过程,只要内存里有正确排列的指令和数据,计算机就能自动工作,但是内存的容量比较小,不能存放过量的数据,于是就用到了硬盘。 +  硬盘的容量大,可以先把指令和数据放到硬盘里,需要时再由内存来取,读写硬盘和读写内存相似。 +  双击硬盘里的一个exe,exe中的指令和数据就会自动进入内存,然后由CPU做运算,结果还可以写回硬盘。 +(这篇文章忽略了寄存器、缓存、总线等构造,假设所有数据都必须来自内存) From 65a8409a2cb4e2fcb40cdc0f14d1e2392083ca0e Mon Sep 17 00:00:00 2001 From: Viscaria233 Date: Sat, 25 Feb 2017 14:15:35 +0800 Subject: [PATCH 010/475] Update week1.md --- group01/895457260/journal/week1.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/group01/895457260/journal/week1.md b/group01/895457260/journal/week1.md index 4c93a1638e..30e96532ab 100644 --- a/group01/895457260/journal/week1.md +++ b/group01/895457260/journal/week1.md @@ -1,4 +1,4 @@ -# 标题 +# 简略描述CPU的工作方式   电脑,这个用法丰富而且功能异常强大的机器,也叫做计算机。计算机这个词听起来似乎并不能概括这种机器的功能,但它就是叫计算机。究其原因,无论多么复杂,多么神奇的功能,都能归结为大量的数据计算。加,减,乘,除,与,或,非……这些简单的计算经过组合,实现了令人眼花缭乱的效果。   那么计算机如何计算?这是第一个问题。   众所周知,计算机内部使用二进制,也就是0和1。而利用继电器(或晶体管)可以做成能处理二进制数的逻辑门(与/或/非门),用逻辑门可以组成加法器等各种器件(当然这些也是针对二进制的)。这些器件接受外部的二进制输入,再经过一系列变换,得到二进制的结果,最后传出外部。大学的“数字逻辑”这门课里已经花了大篇幅进行说明。 From 26c28c189df83573127f9af161bc792d9e0acc99 Mon Sep 17 00:00:00 2001 From: kwy126 Date: Sat, 25 Feb 2017 16:26:02 +0800 Subject: [PATCH 011/475] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E4=BD=9C=E4=B8=9A=EF=BC=8C=E5=8C=85=E6=8B=ACArrayList?= =?UTF-8?q?,LinkedList,Stack,Queue,BinaryTree?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group03/58555264/.idea/compiler.xml | 16 + group03/58555264/.idea/encodings.xml | 6 + .../inspectionProfiles/Project_Default.xml | 5 + .../libraries/Maven__junit_junit_4_11.xml | 13 + .../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 + group03/58555264/.idea/misc.xml | 109 ++ group03/58555264/.idea/modules.xml | 8 + group03/58555264/.idea/sonarIssues.xml | 79 ++ .../442292b8a7efeabbe4cc176709b833b1792140ec | 0 .../75b2bc528306e8fb4b899cc781e70fe6a351737c | 2 + .../.idea/sonarlint/issuestore/index.pb | 5 + group03/58555264/.idea/workspace.xml | 1175 +++++++++++++++++ group03/58555264/58555264.iml | 23 + group03/58555264/pom.xml | 32 + .../java/com/circle/collection/ArrayList.java | 151 +++ .../com/circle/collection/BinaryTree.java | 280 ++++ .../java/com/circle/collection/Iterator.java | 11 + .../com/circle/collection/LinkedList.java | 217 +++ .../main/java/com/circle/collection/List.java | 17 + .../java/com/circle/collection/Queue.java | 25 + .../java/com/circle/collection/Stack.java | 58 + .../com/circle/collection/ArrayListTest.java | 80 ++ .../com/circle/collection/BinaryTreeTest.java | 74 ++ .../com/circle/collection/LinkedListTest.java | 160 +++ .../java/com/circle/collection/QueueTest.java | 49 + .../java/com/circle/collection/StackTest.java | 63 + 26 files changed, 2671 insertions(+) create mode 100644 group03/58555264/.idea/compiler.xml create mode 100644 group03/58555264/.idea/encodings.xml create mode 100644 group03/58555264/.idea/inspectionProfiles/Project_Default.xml create mode 100644 group03/58555264/.idea/libraries/Maven__junit_junit_4_11.xml create mode 100644 group03/58555264/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml create mode 100644 group03/58555264/.idea/misc.xml create mode 100644 group03/58555264/.idea/modules.xml create mode 100644 group03/58555264/.idea/sonarIssues.xml create mode 100644 group03/58555264/.idea/sonarlint/issuestore/4/4/442292b8a7efeabbe4cc176709b833b1792140ec create mode 100644 group03/58555264/.idea/sonarlint/issuestore/7/5/75b2bc528306e8fb4b899cc781e70fe6a351737c create mode 100644 group03/58555264/.idea/sonarlint/issuestore/index.pb create mode 100644 group03/58555264/.idea/workspace.xml create mode 100644 group03/58555264/58555264.iml create mode 100644 group03/58555264/pom.xml create mode 100644 group03/58555264/src/main/java/com/circle/collection/ArrayList.java create mode 100644 group03/58555264/src/main/java/com/circle/collection/BinaryTree.java create mode 100644 group03/58555264/src/main/java/com/circle/collection/Iterator.java create mode 100644 group03/58555264/src/main/java/com/circle/collection/LinkedList.java create mode 100644 group03/58555264/src/main/java/com/circle/collection/List.java create mode 100644 group03/58555264/src/main/java/com/circle/collection/Queue.java create mode 100644 group03/58555264/src/main/java/com/circle/collection/Stack.java create mode 100644 group03/58555264/src/test/java/com/circle/collection/ArrayListTest.java create mode 100644 group03/58555264/src/test/java/com/circle/collection/BinaryTreeTest.java create mode 100644 group03/58555264/src/test/java/com/circle/collection/LinkedListTest.java create mode 100644 group03/58555264/src/test/java/com/circle/collection/QueueTest.java create mode 100644 group03/58555264/src/test/java/com/circle/collection/StackTest.java diff --git a/group03/58555264/.idea/compiler.xml b/group03/58555264/.idea/compiler.xml new file mode 100644 index 0000000000..d4d178c429 --- /dev/null +++ b/group03/58555264/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/group03/58555264/.idea/encodings.xml b/group03/58555264/.idea/encodings.xml new file mode 100644 index 0000000000..b26911bd02 --- /dev/null +++ b/group03/58555264/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/group03/58555264/.idea/inspectionProfiles/Project_Default.xml b/group03/58555264/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000000..8d66637cb9 --- /dev/null +++ b/group03/58555264/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/group03/58555264/.idea/libraries/Maven__junit_junit_4_11.xml b/group03/58555264/.idea/libraries/Maven__junit_junit_4_11.xml new file mode 100644 index 0000000000..f33320d8e7 --- /dev/null +++ b/group03/58555264/.idea/libraries/Maven__junit_junit_4_11.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/group03/58555264/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/group03/58555264/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000000..f58bbc1127 --- /dev/null +++ b/group03/58555264/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/group03/58555264/.idea/misc.xml b/group03/58555264/.idea/misc.xml new file mode 100644 index 0000000000..e199196115 --- /dev/null +++ b/group03/58555264/.idea/misc.xml @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + Android > Lint > Correctness + + + Android > Lint > Performance + + + Android > Lint > Security + + + Android > Lint > Usability > Icons + + + Android Lint for Kotlin + + + Code style issuesJava + + + Compiler issuesJava + + + Finalization issuesJava + + + GeneralJavaScript + + + Groovy + + + Inheritance issuesJava + + + J2ME issuesJava + + + JSP Inspections + + + Java + + + Java language level migration aidsJava + + + JavaBeans issuesJava + + + JavaScript + + + Kotlin + + + Numeric issuesJava + + + OtherGroovy + + + Performance issuesJava + + + Probable bugsJava + + + Security issuesJava + + + Serialization issuesJava + + + Verbose or redundant code constructsJava + + + + + Android + + + + + + + + + \ No newline at end of file diff --git a/group03/58555264/.idea/modules.xml b/group03/58555264/.idea/modules.xml new file mode 100644 index 0000000000..3acbd95495 --- /dev/null +++ b/group03/58555264/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/group03/58555264/.idea/sonarIssues.xml b/group03/58555264/.idea/sonarIssues.xml new file mode 100644 index 0000000000..766ed3fe03 --- /dev/null +++ b/group03/58555264/.idea/sonarIssues.xml @@ -0,0 +1,79 @@ + + + + + + \ No newline at end of file diff --git a/group03/58555264/.idea/sonarlint/issuestore/4/4/442292b8a7efeabbe4cc176709b833b1792140ec b/group03/58555264/.idea/sonarlint/issuestore/4/4/442292b8a7efeabbe4cc176709b833b1792140ec new file mode 100644 index 0000000000..e69de29bb2 diff --git a/group03/58555264/.idea/sonarlint/issuestore/7/5/75b2bc528306e8fb4b899cc781e70fe6a351737c b/group03/58555264/.idea/sonarlint/issuestore/7/5/75b2bc528306e8fb4b899cc781e70fe6a351737c new file mode 100644 index 0000000000..bc41e6c43e --- /dev/null +++ b/group03/58555264/.idea/sonarlint/issuestore/7/5/75b2bc528306e8fb4b899cc781e70fe6a351737c @@ -0,0 +1,2 @@ + +W squid:S2094"BRemove this empty class, write its code or make it an "interface".(���� \ No newline at end of file diff --git a/group03/58555264/.idea/sonarlint/issuestore/index.pb b/group03/58555264/.idea/sonarlint/issuestore/index.pb new file mode 100644 index 0000000000..279a4cb36d --- /dev/null +++ b/group03/58555264/.idea/sonarlint/issuestore/index.pb @@ -0,0 +1,5 @@ + +7 +pom.xml,4/4/442292b8a7efeabbe4cc176709b833b1792140ec +b +2src/main/java/com/circle/collection/ArrayList.java,7/5/75b2bc528306e8fb4b899cc781e70fe6a351737c \ No newline at end of file diff --git a/group03/58555264/.idea/workspace.xml b/group03/58555264/.idea/workspace.xml new file mode 100644 index 0000000000..bd847f163f --- /dev/null +++ b/group03/58555264/.idea/workspace.xml @@ -0,0 +1,1175 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + add + peek + removeFirst + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + project + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1487924915857 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + file://$PROJECT_DIR$/src/main/java/com/circle/collection/ArrayList.java + 37 + + + + file://$PROJECT_DIR$/src/test/java/com/circle/collection/ArrayListTest.java + 34 + + + + file://$PROJECT_DIR$/src/test/java/com/circle/collection/LinkedListTest.java + 87 + + + + file://$PROJECT_DIR$/src/main/java/com/circle/collection/Stack.java + 47 + + + + file://$PROJECT_DIR$/src/main/java/com/circle/collection/BinaryTree.java + 147 + + + + file://$PROJECT_DIR$/src/test/java/com/circle/collection/BinaryTreeTest.java + 69 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No facets are configured + + + + + + + + + + + + + + + 1.7 + + + + + + + + 58555264 + + + + + + + + 1.7 + + + + + + + + Maven: junit:junit:4.11 + + + + + + + + \ No newline at end of file diff --git a/group03/58555264/58555264.iml b/group03/58555264/58555264.iml new file mode 100644 index 0000000000..6f2092a3ac --- /dev/null +++ b/group03/58555264/58555264.iml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/group03/58555264/pom.xml b/group03/58555264/pom.xml new file mode 100644 index 0000000000..ede0dc4997 --- /dev/null +++ b/group03/58555264/pom.xml @@ -0,0 +1,32 @@ + + 4.0.0 + + com.circle + 58555264 + 1.0-SNAPSHOT + jar + + 58555264 + http://maven.apache.org + + + UTF-8 + + + + + junit + junit + 3.8.1 + test + + + + + junit + junit + 4.11 + + + diff --git a/group03/58555264/src/main/java/com/circle/collection/ArrayList.java b/group03/58555264/src/main/java/com/circle/collection/ArrayList.java new file mode 100644 index 0000000000..3e01045bd6 --- /dev/null +++ b/group03/58555264/src/main/java/com/circle/collection/ArrayList.java @@ -0,0 +1,151 @@ +package com.circle.collection; + +import java.util.Arrays; + +/** + * Created by keweiyang on 2017/2/25. + * 自定义ArrayList + */ +public class ArrayList implements List { + private Object[] elementData = null; + private int currentIndex = -1; + + public ArrayList(int length) { + if (length < 0) { + throw new RuntimeException("数组初始化大小必须大于0"); + } + elementData = new Object[length]; + } + + /** + * 在数组最后一位插入数据 + * + * @param object + */ + public void add(Object object) { + //1:先判断数组是否越界,由于其他函数也会用到,所以提取为一个函数 + ensureCapacity(); + //2:执行插入操作 + currentIndex++; + elementData[currentIndex] = object; + } + + + /** + * 给数组动态扩容 + */ + public void ensureCapacity() { + if (currentIndex + 2 > elementData.length) { +// Object[] newObjects = new Object[elementData.length * 2 + 2]; + elementData = Arrays.copyOf(elementData, elementData.length * 2 + 2); + //System.arraycopy(elementData, 0, newObjects, 0, newObjects.length); + } + } + + /** + * 在数组指定位置(任意位置)插入数据 + * + * @param index + * @param object + */ + public void add(int index, Object object) { + + rangeCheck(index); + ensureCapacity(); + //如果index>currentIndex,并且在数组范围内,则插入 + if (index > currentIndex && index <= elementData.length) { + currentIndex = index; + elementData[currentIndex] = object; + currentIndex++; + + } else if (index >= 0 && index < currentIndex) { + //如果0<=index< currentIndex,则将index和之后的数据往后面移动 + + for (int i = currentIndex; i >= index; i--) { + elementData[i + 1] = elementData[i]; + } + elementData[index] = object; + currentIndex++; + } else { + //如果index=currentIndex,则调用add(Object o) + add(object); + } + + + } + + private void rangeCheck(int index) { + if (index < 0 || index > elementData.length - 1) { + throw new ArrayIndexOutOfBoundsException("输入索引位置越界"); + } + } + + /** + * 获取指定位置数据 + * + * @param index + * @return + */ + public Object get(int index) { + rangeCheck(index); + return elementData[index]; + } + + /** + * 删除指定位置数据 + * + * @param index + * @return 返回要删除的数据 + */ + public Object remove(int index) { + + rangeCheck(index); + Object temp = elementData[index]; + for (int i = index + 1; i <= currentIndex; i++) { + elementData[i - 1] = elementData[i]; + } + + elementData[currentIndex] = null; + currentIndex--; + return temp; + } + + /** + * 返回数组长度 + * + * @return + */ + public int size() { + return currentIndex + 1; + } + + /** + * 遍历ArrayList + * + * @return + */ + public Iterator iterator() { + + return new Iterator() { + + int pos = -1; + + public boolean hasNext() { + if (pos + 1 <= currentIndex) { + return true; + } + return false; + } + + public Object next() { + if (hasNext()) { + pos++; + return elementData[pos]; + } + return null; + } + }; + } + + +} diff --git a/group03/58555264/src/main/java/com/circle/collection/BinaryTree.java b/group03/58555264/src/main/java/com/circle/collection/BinaryTree.java new file mode 100644 index 0000000000..cfb0d851ee --- /dev/null +++ b/group03/58555264/src/main/java/com/circle/collection/BinaryTree.java @@ -0,0 +1,280 @@ +package com.circle.collection; + +/** + * Created by keweiyang on 2017/2/25. + * 自定义二叉树 + */ +public class BinaryTree { + + private Node root; + + /** + * 查找某个节点 + * + * @param key + * @return + */ + public Node get(int key) { + Node currentNode = root; + + if (currentNode == null) { + throw new RuntimeException("这棵二叉树为空二叉树"); + } else { + while (currentNode.getData() != key) { + if (currentNode.getId() > key) { + currentNode = currentNode.getLeftChild(); + } else { + currentNode.getRightChild(); + } + + if (currentNode == null) { + return null; + } + } + } + + return currentNode; + } + + /** + * 插入一个节点 + * + * @param id + * @param data + */ + public void insert(int id, Object data) { + Node newNode = new Node(id, data); + //1:先找到插入位置 + Node parentNode = null; + Node currentNode = root; + if (root == null) { + root = newNode; + } else { + while (true) { + parentNode = currentNode; + if (currentNode.getId() > id) { + currentNode = currentNode.getLeftChild(); + if (currentNode == null) { + //如果没有左子节点,则插入 + parentNode.setLeftChild(newNode); + return; + } + } else { + currentNode = currentNode.getRightChild(); + if (currentNode == null) { + //如果没有右子节点,则插入 + parentNode.setRightChild(newNode); + return; + } + + } + } + } + } + + /** + * 删除节点 + * @param key + */ + public boolean delete(int key) { + //根据key找到对应的节点 + // 1、如果该节点不存在就抛出异常 + Node parentNode = null; + Node currentNode = root; + boolean isLeftNode = false; + if (currentNode == null) { + throw new RuntimeException("二叉树为空"); + }else{ + while (currentNode.getId() != key) { + parentNode = currentNode; + if (currentNode.getId() < key) { + currentNode = currentNode.getRightChild(); + isLeftNode = false; + }else{ + currentNode = currentNode.getLeftChild(); + isLeftNode = true; + } + + if (currentNode == null) { + return false; + } + } + } + + + //2、下面讨论该节点存在 + // 2.1如果该节点的左右子节点都不存在,则直接删除该节点 + if (currentNode.getRightChild() == null && currentNode.getLeftChild() == null) { + this.noChild(currentNode, parentNode, isLeftNode); + } + // 2.2如果该节点的只存在一个子节点 + //2.2.1 如果存在左节点 + if (currentNode.getRightChild() == null) { + this.oneLeftChild(currentNode,parentNode,isLeftNode); + } + //2.2.2 如果存在右节点 + if (currentNode.getLeftChild() == null) { + this.oneRightChild(currentNode, parentNode, isLeftNode); + } + //2.3 如果左右孩子都存在,则直接拿右孩子中最小的节点替换该节点 + if (currentNode.getLeftChild() != null && currentNode.getRightChild() != null) { + this.bothChild(currentNode, parentNode, isLeftNode); + } + return false; + + } + + private void bothChild(Node currentNode, Node parentNode, boolean flag) { + //找到中序后继节点 + if (flag) { + Node node = this.successor(currentNode); + node.setLeftChild(currentNode.getLeftChild()); + + parentNode.setLeftChild(node); + + + }else{ + Node node = this.successor(currentNode); + node.setRightChild(currentNode.getRightChild()); + + parentNode.setRightChild(node); + + } + } + + private Node successor(Node currentNode) { + //由于当前节点的左右子节点都存在,所以current一定存在 + Node parent = currentNode; + Node current = currentNode.getRightChild(); + + while (current != null) { + parent = current; + current = current.getLeftChild(); + } + + return parent; + + } + + private void oneRightChild(Node currentNode, Node parentNode, boolean flag) { + if (flag) { + parentNode.setRightChild(currentNode.getLeftChild()); + + }else{ + parentNode.setRightChild(currentNode.getRightChild()); + + } + } + + private void oneLeftChild(Node currentNode, Node parentNode, boolean flag) { + if (flag) { + parentNode.setLeftChild(currentNode.getLeftChild()); + + }else{ + parentNode.setLeftChild(currentNode.getRightChild()); + + } + } + + private void noChild(Node currentNode, Node parentNode, boolean flag) { + if (flag) { + parentNode.setLeftChild(null); + + }else{ + parentNode.setRightChild(null); + + } + } + + /** + * 前序 + * + * @param node + */ + public void preOrder(Node node) { + if (node != null) { + System.out.println(node.getId() + "--- "); + preOrder(node.getLeftChild()); + preOrder(node.getRightChild()); + + } + } + + /** + * 中序 + * + * @param node + */ + public void inOrder(Node node) { + if (node != null) { + inOrder(node.getLeftChild()); + System.out.println(node.getId() + "--"); + inOrder(node.getRightChild()); + + } + } + + /** + * 后序 + * + * @param node + */ + public void postOrder(Node node) { + if (node != null) { + postOrder(node.getLeftChild()); + postOrder(node.getRightChild()); + System.out.println(node.getId() + "---"); + } + } + + private class Node { + private int id; + private Object data; + private Node leftChild; + private Node rightChild; + + + public Node(int id, Object data) { + this.id = id; + this.data = data; + } + + public Object getData() { + return data; + } + + public void setData(Object data) { + this.data = data; + } + + public Node getLeftChild() { + return leftChild; + } + + public void setLeftChild(Node leftChild) { + this.leftChild = leftChild; + } + + public Node getRightChild() { + return rightChild; + } + + public void setRightChild(Node rightChild) { + this.rightChild = rightChild; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Override + public String toString() { + + return "id= " + id + " , data= " + data; + } + } +} diff --git a/group03/58555264/src/main/java/com/circle/collection/Iterator.java b/group03/58555264/src/main/java/com/circle/collection/Iterator.java new file mode 100644 index 0000000000..52616dfc27 --- /dev/null +++ b/group03/58555264/src/main/java/com/circle/collection/Iterator.java @@ -0,0 +1,11 @@ +package com.circle.collection; + +/** + * Created by keweiyang on 2017/2/25. + * Iterator对外暴露2个接口,隐藏了具体实现(数组or链表) + */ +public interface Iterator { + boolean hasNext(); + + Object next(); +} diff --git a/group03/58555264/src/main/java/com/circle/collection/LinkedList.java b/group03/58555264/src/main/java/com/circle/collection/LinkedList.java new file mode 100644 index 0000000000..5bf11b1fc8 --- /dev/null +++ b/group03/58555264/src/main/java/com/circle/collection/LinkedList.java @@ -0,0 +1,217 @@ +package com.circle.collection; + +/** + * Created by keweiyang on 2017/2/25. + */ +public class LinkedList implements List{ + + private Node first = null; + + private int currentIndex = -1;//主要用于统计链表长度 + + //注意Node是静态内部类 + private static class Node { + + Object data; + Node nextNode; + + public Node(Object obj) { + this.data = obj; + } + + public Node getNextNode() { + return nextNode; + } + + public void setNextNode(Node nextNode) { + this.nextNode = nextNode; + } + + @Override + public String toString() { + return "data= " + data; + } + } + + /** + * 插入 + * + * @param o + */ + public void add(Object o) { + //1:生成一个Node + Node newNode = new Node(o); + Node currentNode = first; + //2:插入Node + if (currentNode == null) { + first = newNode; + } else { + while (currentNode.getNextNode() != null) { + currentNode = currentNode.getNextNode(); + } + currentNode.setNextNode(newNode); + + } + currentIndex++; + } + + /** + * 在指定位置插入节点 + * + * @param index + * @param o + */ + public void add(int index, Object o) { + + Node newNode = new Node(o); + + if (index < 0 || index > currentIndex + 1) { + throw new RuntimeException("索引不正确"); + } + + Node currentNode = first; + Node previousNode = currentNode; + int pos = 0; + while (currentNode != null && pos != index) { + previousNode = currentNode; + currentNode = currentNode.getNextNode(); + pos++; + } + + previousNode.setNextNode(newNode); + newNode.setNextNode(currentNode); + currentIndex++; + + } + + public Object get(int index) { + + rangeCheck(index); + Node node = first; + int pos = 0; + + while (node != null && pos != index) { + + node = node.getNextNode(); + pos++; + } + return node; + } + + private void rangeCheck(int index) { + if (index < 0 || index > currentIndex) { + throw new RuntimeException("索引不正确"); + } + } + + public Object remove(int index) { + + //1:获取要删除的节点 + rangeCheck(index); + Node currentNode = first; + + + if (index == 0) { + + currentNode = first; + first = first.getNextNode(); + }else{ + Node previousNode = first; + int pos = 0; + while (currentNode != null && pos != index) { + previousNode = currentNode; + currentNode = currentNode.getNextNode(); + pos++; + } + + //2:执行删除操作 + previousNode.setNextNode(currentNode.getNextNode()); + } + + currentIndex--; + + return currentNode; + } + + public int size() { + return currentIndex + 1; + } + + public void addFirst(Object o) { + Node newNode = new Node(o); + if (first == null) { + first = newNode; + } else { + newNode.setNextNode(first); + first = newNode; + } + currentIndex++; + } + + public void addLast(Object o) { + + Node newNode = new Node(o); + Node currentNode = first; + if (currentNode == null) { + first=newNode; + } else { + while (currentNode.getNextNode() != null) { + currentNode = currentNode.getNextNode(); + } + currentNode.setNextNode(newNode); + + } + currentIndex++; + + } + + public Object removeFirst() { + + Node node = first; + if (first == null) { + throw new RuntimeException("链表长度为0,不能执行这步操作"); + } else { + first = first.getNextNode(); + } + currentIndex--; + return node; + } + + public Object removeLast() { + Node currentNode = first; + Node previousNode = currentNode; + if (currentNode == null) { + throw new RuntimeException("链表长度为0,不能执行这步操作"); + } else { + while (currentNode.getNextNode() != null) { + previousNode = currentNode; + currentNode = currentNode.getNextNode(); + } + previousNode.setNextNode(null); + + } + currentIndex--; + return currentNode; + } + + public Iterator iterator() { + return new Iterator() { + int pos = -1; + + public boolean hasNext() { + if (pos + 1 <= currentIndex) { + return true; + } + return false; + } + + public Object next() { + if (hasNext()) { + pos++; + return get(pos); + } + return null; + } + }; + } +} diff --git a/group03/58555264/src/main/java/com/circle/collection/List.java b/group03/58555264/src/main/java/com/circle/collection/List.java new file mode 100644 index 0000000000..3c15767b48 --- /dev/null +++ b/group03/58555264/src/main/java/com/circle/collection/List.java @@ -0,0 +1,17 @@ +package com.circle.collection; + +/** + * Created by keweiyang on 2017/2/25. + */ +public interface List { + void add(Object o); + + void add(int index, Object o); + + Object get(int index); + + Object remove(int index); + + int size(); + +} diff --git a/group03/58555264/src/main/java/com/circle/collection/Queue.java b/group03/58555264/src/main/java/com/circle/collection/Queue.java new file mode 100644 index 0000000000..6e67a1c524 --- /dev/null +++ b/group03/58555264/src/main/java/com/circle/collection/Queue.java @@ -0,0 +1,25 @@ +package com.circle.collection; + +/** + * Created by keweiyang on 2017/2/25. + */ +public class Queue { + private LinkedList elementData = new LinkedList(); + + public void enQueue(Object o) { + + elementData.addLast(o); + } + + public Object deQueue() { + return elementData.removeFirst(); + } + + public boolean isEmpty() { + return elementData.size() <= 0; + } + + public int size() { + return elementData.size(); + } +} diff --git a/group03/58555264/src/main/java/com/circle/collection/Stack.java b/group03/58555264/src/main/java/com/circle/collection/Stack.java new file mode 100644 index 0000000000..d57bac0841 --- /dev/null +++ b/group03/58555264/src/main/java/com/circle/collection/Stack.java @@ -0,0 +1,58 @@ +package com.circle.collection; + +/** + * Created by keweiyang on 2017/2/25. + * 自定义Stack,此Stack是基于ArrayList实现的 + */ +public class Stack { + + private ArrayList elementData = new ArrayList(4); + + /** + * 入栈 + * + * @param o + */ + public void push(Object o) { + + elementData.add(o); + } + + /** + * 出栈 + * + * @return + */ + public Object pop() { + Object ret = null; + if (elementData.size() > 0) { + ret = elementData.remove(elementData.size() - 1); + }else{ + throw new RuntimeException("栈中没有元素"); + } + return ret; + } + + /** + * 获取栈顶元素 + * + * @return + */ + public Object peek() { + Object ret = null; + if (elementData.size() > 0) { + ret = elementData.get(elementData.size() - 1); + } else { + throw new RuntimeException("栈中没有元素"); + } + return ret; + } + + public boolean isEmpty() { + return elementData.size() <= 0; + } + + public int size() { + return elementData.size(); + } +} diff --git a/group03/58555264/src/test/java/com/circle/collection/ArrayListTest.java b/group03/58555264/src/test/java/com/circle/collection/ArrayListTest.java new file mode 100644 index 0000000000..7a31fc5590 --- /dev/null +++ b/group03/58555264/src/test/java/com/circle/collection/ArrayListTest.java @@ -0,0 +1,80 @@ +package com.circle.collection; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by keweiyang on 2017/2/25. + */ +public class ArrayListTest { + private ArrayList list = null; + +// @Test + public void add() throws Exception { + list = new ArrayList(3); + list.add(1); + list.add(2); + list.add(3); + //测试自动扩容 + list.add(4); + Iterator it = list.iterator(); + while (it.hasNext()) { + System.out.println(it.next()); + } + } + +// @Test + public void add1() throws Exception { + list = new ArrayList(10); + list.add(1); + list.add(2); + list.add(3); + //测试自动扩容 + list.add(4); + list.add(5, 5); + list.add(4, 6); + Iterator it = list.iterator(); + while (it.hasNext()) { + System.out.println(it.next()); + } + + } + +// @Test + public void get() throws Exception { + list = new ArrayList(10); + list.add(1); + list.add(2); + list.add(3); + + System.out.println(list.get(1)); + + } + +// @Test + public void remove() throws Exception { + list = new ArrayList(10); + list.add(1); + list.add(2); + list.add(3); + + System.out.println(list.remove(1)); + System.out.println("------------>"); + Iterator it = list.iterator(); + while (it.hasNext()) { + System.out.println(it.next()); + } + } + + @Test + public void size() throws Exception { + list = new ArrayList(10); + list.add(1); + list.add(2); + list.add(3); + + System.out.println("size= "+list.size()); + } + +} \ No newline at end of file diff --git a/group03/58555264/src/test/java/com/circle/collection/BinaryTreeTest.java b/group03/58555264/src/test/java/com/circle/collection/BinaryTreeTest.java new file mode 100644 index 0000000000..7db0f9dc96 --- /dev/null +++ b/group03/58555264/src/test/java/com/circle/collection/BinaryTreeTest.java @@ -0,0 +1,74 @@ +package com.circle.collection; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by keweiyang on 2017/2/25. + */ +public class BinaryTreeTest { + + private BinaryTree tree; + + @Test + public void get() throws Exception { + tree = new BinaryTree(); + tree.insert(5, 5); + tree.insert(6, 6); + System.out.println(tree.get(5)); + + } + + @Test + public void insert() throws Exception { + tree = new BinaryTree(); + tree.insert(5, 5); + tree.insert(6, 6); + + } + + @Test + public void preOrder() throws Exception { + tree = new BinaryTree(); + tree.insert(5, 5); + tree.insert(6, 6); + tree.preOrder(tree.get(5)); + + } + + @Test + public void inOrder() throws Exception { + tree = new BinaryTree(); + tree.insert(5, 5); + tree.insert(6, 6); + tree.insert(4, 4); + tree.inOrder(tree.get(5)); + } + + @Test + public void postOrder() throws Exception { + tree = new BinaryTree(); + tree.insert(5, 5); + tree.insert(6, 6); + tree.insert(4, 4); + tree.postOrder(tree.get(5)); + } + + @Test + public void delete() throws Exception { + tree = new BinaryTree(); + tree.insert(7, 7); + tree.insert(5, 5); + tree.insert(10, 10); + tree.insert(2, 2); + tree.insert(6, 6); + tree.insert(11, 11); + tree.insert(13, 13); + tree.inOrder(tree.get(7)); + + tree.delete(10); + tree.inOrder(tree.get(7)); + + } +} \ No newline at end of file diff --git a/group03/58555264/src/test/java/com/circle/collection/LinkedListTest.java b/group03/58555264/src/test/java/com/circle/collection/LinkedListTest.java new file mode 100644 index 0000000000..05d99641c1 --- /dev/null +++ b/group03/58555264/src/test/java/com/circle/collection/LinkedListTest.java @@ -0,0 +1,160 @@ +package com.circle.collection; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by keweiyang on 2017/2/25. + */ +public class LinkedListTest { + private LinkedList list = null; + +// @Test + public void add() throws Exception { + + list = new LinkedList(); + + list.add(1); + list.add(2); + + Iterator it = list.iterator(); + while (it.hasNext()) { + System.out.println(it.next()); + + } + } + + @Test + public void add1() throws Exception { + list = new LinkedList(); + list.add(1); + list.add(2); + list.add(1, 3); + + list.add(3, 4); + //索引不正确情况 + list.add(6,6); + Iterator it = list.iterator(); + while (it.hasNext()) { + System.out.println(it.next()); + + } + + } + + @Test + public void get() throws Exception { + list = new LinkedList(); + list.add(1); + list.add(2); + + System.out.println(list.get(0)); + System.out.println(list.get(1)); + + } + + @Test + public void remove() throws Exception { + list = new LinkedList(); + list.add(1); + list.add(2); + list.remove(1); + + Iterator it = list.iterator(); + while (it.hasNext()) { + System.out.println(it.next()); + + } + + + } + + @Test + public void size() throws Exception { + list = new LinkedList(); + list.add(1); + list.add(2); + System.out.println("size= "+ list.size()); + } + + @Test + public void addFirst() throws Exception { + list = new LinkedList(); + list.add(1); + list.add(2); + list.addFirst("123"); + + + Iterator it = list.iterator(); + while (it.hasNext()) { + System.out.println(it.next()); + + } + + list.remove(0); + System.out.println("---------------");; + it = list.iterator(); + while (it.hasNext()) { + System.out.println(it.next()); + + } + } + + @Test + public void addLast() throws Exception { + list = new LinkedList(); + list.addFirst(1); + list.addLast(2); + list.add(3); + list.addLast(4); + list.addFirst(0); + + Iterator it = list.iterator(); + while (it.hasNext()) { + System.out.println(it.next()); + + } + + } + + @Test + public void removeFirst() throws Exception { + + list = new LinkedList(); + list.addFirst(1); + list.addLast(2); + list.add(3); + list.addLast(4); + list.addFirst(0); + list.removeFirst(); + Iterator it = list.iterator(); + while (it.hasNext()) { + System.out.println(it.next()); + } + } + + + + @Test + public void removeLast() throws Exception { + list = new LinkedList(); + list.addFirst(1); + list.addLast(2); + list.add(3); + list.addLast(4); + list.addFirst(0); + list.removeLast(); + list.removeLast(); + Iterator it = list.iterator(); + while (it.hasNext()) { + System.out.println(it.next()); + } + } + + @Test + public void iterator() throws Exception { + + } + +} \ No newline at end of file diff --git a/group03/58555264/src/test/java/com/circle/collection/QueueTest.java b/group03/58555264/src/test/java/com/circle/collection/QueueTest.java new file mode 100644 index 0000000000..6c35605e18 --- /dev/null +++ b/group03/58555264/src/test/java/com/circle/collection/QueueTest.java @@ -0,0 +1,49 @@ +package com.circle.collection; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by keweiyang on 2017/2/25. + */ +public class QueueTest { + + private Queue queue = null; + + @Test + public void enQueue() throws Exception { + queue = new Queue(); + queue.enQueue(1); + queue.enQueue(2); + queue.enQueue(4); + System.out.println(queue.deQueue()); + } + + @Test + public void deQueue() throws Exception { + + queue = new Queue(); + queue.enQueue(1); + queue.enQueue(2); + System.out.println(queue.deQueue()); + } + + @Test + public void isEmpty() throws Exception { + queue = new Queue(); +// queue.enQueue(1); +// queue.enQueue(2); + System.out.println(queue.isEmpty()); + } + + @Test + public void size() throws Exception { + + queue = new Queue(); + queue.enQueue(1); + queue.enQueue(2); + System.out.println(queue.size()); + } + +} \ No newline at end of file diff --git a/group03/58555264/src/test/java/com/circle/collection/StackTest.java b/group03/58555264/src/test/java/com/circle/collection/StackTest.java new file mode 100644 index 0000000000..6ec7a3c4ca --- /dev/null +++ b/group03/58555264/src/test/java/com/circle/collection/StackTest.java @@ -0,0 +1,63 @@ +package com.circle.collection; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by keweiyang on 2017/2/25. + */ +public class StackTest { + private Stack stack = null; + + + @Test + public void push() throws Exception { + stack = new Stack(); + stack.push(1); + stack.push(2); + stack.push(3); + stack.push(4); + System.out.println(stack.pop()); + } + + @Test + public void pop() throws Exception { + stack = new Stack(); + stack.push(1); + stack.push(2); + stack.push(3); + stack.push(4); + stack.pop(); + System.out.println(stack.pop()); + } + + @Test + public void peek() throws Exception { + + stack = new Stack(); + stack.push(1); + stack.push(2); + stack.push(3); + stack.push(4); + System.out.println(stack.peek()); + + } + + @Test + public void isEmpty() throws Exception { + + stack = new Stack(); + System.out.println(stack.isEmpty()); + + } + + @Test + public void size() throws Exception { + + stack = new Stack(); + stack.push(1); + System.out.println(stack.size()); + } + +} \ No newline at end of file From d8ac85e49cbc104c7dd4000e1104d869fecda493 Mon Sep 17 00:00:00 2001 From: GallenZhang <1298552064@qq.com> Date: Sat, 25 Feb 2017 22:07:54 +0800 Subject: [PATCH 012/475] =?UTF-8?q?=E4=BF=AE=E6=AD=A3MyLinkedList?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修正MyLinkList 类中的 removeLast 方法,removeObject = p.next; 修正为removeObject = p.next.data; --- group01/1298552064/src/week01/basic/MyLinkedList.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/group01/1298552064/src/week01/basic/MyLinkedList.java b/group01/1298552064/src/week01/basic/MyLinkedList.java index 4894c5ff6c..88db213864 100644 --- a/group01/1298552064/src/week01/basic/MyLinkedList.java +++ b/group01/1298552064/src/week01/basic/MyLinkedList.java @@ -124,7 +124,7 @@ public Object removeLast() { Node p = head; for (int i = 0; i < size; i++) { if (p.next.next == null) { - removeObject = p.next; + removeObject = p.next.data; p.next = null; break; } else { 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 013/475] =?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; + // �ж�list�ij����Ƿ�������鳤�� + 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; + } + //��index������o�����ҽ�o��next�ڵ���Ϊ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 014/475] =?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: Sun, 26 Feb 2017 10:45:47 +0800 Subject: [PATCH 015/475] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group04/465034663/.classpath | 6 ++++++ group04/465034663/.gitignore | 1 + group04/465034663/.project | 17 +++++++++++++++++ .../465034663/RemoteSystemsTempFiles/.project | 12 ++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 group04/465034663/.classpath create mode 100644 group04/465034663/.gitignore create mode 100644 group04/465034663/.project create mode 100644 group04/465034663/RemoteSystemsTempFiles/.project diff --git a/group04/465034663/.classpath b/group04/465034663/.classpath new file mode 100644 index 0000000000..d171cd4c12 --- /dev/null +++ b/group04/465034663/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/group04/465034663/.gitignore b/group04/465034663/.gitignore new file mode 100644 index 0000000000..ae3c172604 --- /dev/null +++ b/group04/465034663/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/group04/465034663/.project b/group04/465034663/.project new file mode 100644 index 0000000000..fa51ef6448 --- /dev/null +++ b/group04/465034663/.project @@ -0,0 +1,17 @@ + + + DataStruct + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/group04/465034663/RemoteSystemsTempFiles/.project b/group04/465034663/RemoteSystemsTempFiles/.project new file mode 100644 index 0000000000..7675629320 --- /dev/null +++ b/group04/465034663/RemoteSystemsTempFiles/.project @@ -0,0 +1,12 @@ + + + RemoteSystemsTempFiles + + + + + + + org.eclipse.rse.ui.remoteSystemsTempNature + + From b0e890d98d50168776a1254a6f4c31de5b45f63a Mon Sep 17 00:00:00 2001 From: Arthur <465034663@qq.com> Date: Sun, 26 Feb 2017 10:48:39 +0800 Subject: [PATCH 016/475] =?UTF-8?q?=E5=9F=BA=E7=A1=80=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group04/465034663/RemoteSystemsTempFiles/.project | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 group04/465034663/RemoteSystemsTempFiles/.project diff --git a/group04/465034663/RemoteSystemsTempFiles/.project b/group04/465034663/RemoteSystemsTempFiles/.project deleted file mode 100644 index 7675629320..0000000000 --- a/group04/465034663/RemoteSystemsTempFiles/.project +++ /dev/null @@ -1,12 +0,0 @@ - - - RemoteSystemsTempFiles - - - - - - - org.eclipse.rse.ui.remoteSystemsTempNature - - From de383b739b0315cb634196cd0634817b2558eb31 Mon Sep 17 00:00:00 2001 From: "pwh-PC\\pwh" Date: Sat, 25 Feb 2017 21:52:03 -0500 Subject: [PATCH 017/475] 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 018/475] 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 019/475] 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 95442a7424e5e4f4dd4d43c3e9528c28d8adbda8 Mon Sep 17 00:00:00 2001 From: Arthur <465034663@qq.com> Date: Sun, 26 Feb 2017 11:33:08 +0800 Subject: [PATCH 020/475] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group04/465034663/.gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/group04/465034663/.gitignore b/group04/465034663/.gitignore index ae3c172604..e69de29bb2 100644 --- a/group04/465034663/.gitignore +++ b/group04/465034663/.gitignore @@ -1 +0,0 @@ -/bin/ From c54579418e284c539db2e534829dfb0d23a4f8dd Mon Sep 17 00:00:00 2001 From: Arthur <465034663@qq.com> Date: Sun, 26 Feb 2017 12:04:25 +0800 Subject: [PATCH 021/475] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xusheng/arraylist/MyArrayList.java | 130 +++++++++++ .../com/xusheng/arraylist/MyCollection.java | 19 ++ .../src/com/xusheng/arraylist/MyIterator.java | 10 + .../src/com/xusheng/arraylist/MyList.java | 14 ++ .../com/xusheng/arraylist/MyListIterator.java | 12 + .../src/com/xusheng/arraylist/TestData.java | 29 +++ .../com/xusheng/linkedlist/MyLinkedList.java | 180 +++++++++++++++ .../src/com/xusheng/linkedlist/TestMain.java | 38 +++ .../src/com/xusheng/stack/MyLinkedStack.java | 98 ++++++++ .../src/com/xusheng/stack/MyLinkedStack2.java | 52 +++++ .../src/com/xusheng/stack/TestMain.java | 17 ++ .../src/com/xusheng/tree/AvlTree.java | 217 ++++++++++++++++++ .../com/xusheng/tree/BinarySearchTree.java | 128 +++++++++++ .../src/com/xusheng/tree/TestMain.java | 21 ++ 14 files changed, 965 insertions(+) create mode 100644 group04/465034663/src/com/xusheng/arraylist/MyArrayList.java create mode 100644 group04/465034663/src/com/xusheng/arraylist/MyCollection.java create mode 100644 group04/465034663/src/com/xusheng/arraylist/MyIterator.java create mode 100644 group04/465034663/src/com/xusheng/arraylist/MyList.java create mode 100644 group04/465034663/src/com/xusheng/arraylist/MyListIterator.java create mode 100644 group04/465034663/src/com/xusheng/arraylist/TestData.java create mode 100644 group04/465034663/src/com/xusheng/linkedlist/MyLinkedList.java create mode 100644 group04/465034663/src/com/xusheng/linkedlist/TestMain.java create mode 100644 group04/465034663/src/com/xusheng/stack/MyLinkedStack.java create mode 100644 group04/465034663/src/com/xusheng/stack/MyLinkedStack2.java create mode 100644 group04/465034663/src/com/xusheng/stack/TestMain.java create mode 100644 group04/465034663/src/com/xusheng/tree/AvlTree.java create mode 100644 group04/465034663/src/com/xusheng/tree/BinarySearchTree.java create mode 100644 group04/465034663/src/com/xusheng/tree/TestMain.java diff --git a/group04/465034663/src/com/xusheng/arraylist/MyArrayList.java b/group04/465034663/src/com/xusheng/arraylist/MyArrayList.java new file mode 100644 index 0000000000..5030a33f09 --- /dev/null +++ b/group04/465034663/src/com/xusheng/arraylist/MyArrayList.java @@ -0,0 +1,130 @@ +package com.xusheng.arraylist; + +import java.util.Iterator; +import java.util.NoSuchElementException; + +public class MyArrayList implements Iterable{ + + private T[] item; + + private static final int DEFAULT_CAPACITY = 10; + + private int size; + + public int size(){ + return size; + } + + private void doClear(){ + this.size = 0; + ensureCapacity(DEFAULT_CAPACITY); + } + + /** + * 此方法用于确定list的容量 + * @param newCapacity + */ + public void ensureCapacity(int newCapacity){ + if(newCapacity < size){ + return; + } + + T[] old = item; + item = (T[]) new Object[newCapacity]; + for(int i=0;i size){ + throw new ArrayIndexOutOfBoundsException(); + } + if(item.length == size){ + ensureCapacity(size*2+1); + } + for(int i=size;i>index;i--){ + item[i] = item[i-1]; + } + item[index] = element; + size++; + } + + public boolean add(T element){ + add(size,element); + return true; + } + + public T get(int index){ + if(index<0 || index>=size){ + throw new ArrayIndexOutOfBoundsException(); + } + return item[index]; + } + + public T set(int index,T element){ + if(index<0 || index>=size){ + throw new ArrayIndexOutOfBoundsException(); + } + T old = item[index]; + item[index] = element; + return old; + } + + public T remove(int index){ + if(index<0 || index>=size){ + throw new ArrayIndexOutOfBoundsException(); + } + T moved = item[index]; + for(int i=size-1;i>index;i++){ + item[i-1] = item[i]; + } + size--; + return moved; + } + + public void trimToSize(){ + ensureCapacity(size); + } + + @Override + public Iterator iterator() { + return new ArrayListIterator(); + } + + private class ArrayListIterator implements Iterator{ + + private int currentIndex = 0; + + @Override + public boolean hasNext() { + return currentIndex extends MyIterator{ + + int size(); + + boolean isEmpty(); + + void clear(); + + boolean contains(T element); + + boolean add(T element); + + boolean remove(T element); + + MyIterator myIterator(); + +} diff --git a/group04/465034663/src/com/xusheng/arraylist/MyIterator.java b/group04/465034663/src/com/xusheng/arraylist/MyIterator.java new file mode 100644 index 0000000000..e37d82cfb1 --- /dev/null +++ b/group04/465034663/src/com/xusheng/arraylist/MyIterator.java @@ -0,0 +1,10 @@ +package com.xusheng.arraylist; + +public interface MyIterator { + + boolean hasNext(); + + T next(); + + void remove(); +} diff --git a/group04/465034663/src/com/xusheng/arraylist/MyList.java b/group04/465034663/src/com/xusheng/arraylist/MyList.java new file mode 100644 index 0000000000..e73a27e96b --- /dev/null +++ b/group04/465034663/src/com/xusheng/arraylist/MyList.java @@ -0,0 +1,14 @@ +package com.xusheng.arraylist; + +public interface MyList extends MyCollection { + + T get(int index); + + T set(int index,T element); + + void add(int index,T element); + + void remove(int index,T element); + + MyListIterator myListIterator(); +} diff --git a/group04/465034663/src/com/xusheng/arraylist/MyListIterator.java b/group04/465034663/src/com/xusheng/arraylist/MyListIterator.java new file mode 100644 index 0000000000..c6ca8604e9 --- /dev/null +++ b/group04/465034663/src/com/xusheng/arraylist/MyListIterator.java @@ -0,0 +1,12 @@ +package com.xusheng.arraylist; + +public interface MyListIterator extends MyIterator{ + + boolean hasPrevious(); + + T previous(); + + void add(T element); + + void set(T element); +} diff --git a/group04/465034663/src/com/xusheng/arraylist/TestData.java b/group04/465034663/src/com/xusheng/arraylist/TestData.java new file mode 100644 index 0000000000..c1f5f4c499 --- /dev/null +++ b/group04/465034663/src/com/xusheng/arraylist/TestData.java @@ -0,0 +1,29 @@ +package com.xusheng.arraylist; + +import java.util.Iterator; + +public class TestData { + + public static void main(String[] args) { + MyArrayList mal = new MyArrayList(); + mal.add("haha"); + mal.add("haha2"); +// System.out.println(mal.size()); +// for(int i=0;i implements Iterable { + private int size; + private int modCount=0; + private Node beginMarker; + private Node endMarker; + + public MyLinkedList() { + doClear(); + } + + public void clear(){ + doClear(); + } + + public void doClear(){ + beginMarker = new Node(null,null,null); + endMarker = new Node(null,beginMarker,null); + beginMarker.next = endMarker; + + this.size = 0; + this.modCount++; + } + + public int size(){ + return this.size; + } + + public boolean isEmpty(){ + return size==0; + } + + public void add(int index,T element){ + addBefore(getNode(index),element); + } + + public boolean add(T element){ + add(size,element); + return true; + } + + public T get(int index){ + return getNode(index).data; + } + + public T set(int index,T element){ + Node node = getNode(index); + T oldElement = node.data; + node.data = element; + return oldElement; + } + + public T remove(int index){ + return remove(getNode(index)); + } + + //此方法用于判断集合中是否含有输入的元素 + public boolean contains(T element){ + for(int i=0;i node = getNode(index); + Node beforep,afterp; + beforep = node.prev; + afterp = node.next; + + beforep.next = afterp; + afterp.prev = beforep; + + node.next = afterp.next; + node.prev = afterp; + + afterp.next = node; + afterp.prev = beforep; + + } + + private T remove(Node delNode){ + delNode.next.prev = delNode.prev; + delNode.prev.next = delNode.next; + size--; + modCount++; + return delNode.data; + } + + private void addBefore(Node p,T element){ + Node newNode = new Node(element,p.prev,p); + newNode.prev.next = newNode; + p.prev = newNode; + this.size++; + this.modCount++; + } + + private Node getNode(int index){ + Node p; + if(index>=0 && index<=size){ + if(index<(size/2)){ + p = beginMarker.next; + for(int i=0;iindex;i--){ + p = p.prev; + } + } + }else{ + throw new IndexOutOfBoundsException(); + } + return p; + } + + @Override + public Iterator iterator() { + return new LinkedListIterator(); + } + + private class Node{ + public T data; + public Node prev; + public Node next; + public Node(T data, Node prev, Node next) { + this.data = data; + this.prev = prev; + this.next = next; + } + } + + private class LinkedListIterator implements Iterator{ + + private Node current = beginMarker.next; + private int expectedModCount = modCount; + private boolean okToRemove = false; + + @Override + public boolean hasNext() { + return current != endMarker; + } + + @Override + public T next(){ + if(modCount != expectedModCount){ + throw new ConcurrentModificationException(); + } + if(!hasNext()){ + throw new NoSuchElementException(); + } + T n = current.data; + current = current.next; + okToRemove = true; + return n; + } + + public void remove(){ + if(modCount != expectedModCount){ + throw new ConcurrentModificationException(); + } + if(!okToRemove){ + throw new IllegalStateException(); + } + MyLinkedList.this.remove(current.prev); + size--; + expectedModCount++; + okToRemove = false; + } + } +} diff --git a/group04/465034663/src/com/xusheng/linkedlist/TestMain.java b/group04/465034663/src/com/xusheng/linkedlist/TestMain.java new file mode 100644 index 0000000000..1e4f735446 --- /dev/null +++ b/group04/465034663/src/com/xusheng/linkedlist/TestMain.java @@ -0,0 +1,38 @@ +package com.xusheng.linkedlist; + +import java.util.Iterator; + +public class TestMain { + + public static void main(String[] args) { + MyLinkedList mll = new MyLinkedList(); + mll.add(0, "haha1"); + mll.add(1,"haha2"); + mll.add(2, "haha3"); + mll.add(3,"haha4"); + mll.add("haha5"); + for(int i=0;i { + + private int size; + private int modCount; + private Node beginMarker; + private Node endMarker; + private int currentIndex = size; + + + + public MyLinkedStack() { + doClear(); + } + + private void doClear(){ + this.size=0; + this.modCount=0; + beginMarker = new Node(null,null,null); + endMarker = new Node(null,beginMarker,null); + beginMarker.next = endMarker; + } + + public int size(){ + return this.size; + } + + public T get(int index){ + Node n = get(index,0,size); + return n.data; + } + + public T pop(){ + Node n = get(this.size-1,0,size); + T old = n.data; + n.prev.next = n.next; + n.next.prev = n.prev; + this.size--; + return n.data; + } + + public void push(T element){ + add(size,element); + } + + public void add(int index,T element){ + addBefore(get(index,0,size),element); + } + + private void addBefore(Node n,T element){ + Node newNode = new Node(element,n.prev,n); + n.prev.next = newNode; + n.prev = newNode; + this.size++; + this.modCount++; + } + + private Node get(int index,int low,int upper){ + if(indexupper){ + throw new IndexOutOfBoundsException(); + } + Node p; + if(index<(size/2)){ + p = beginMarker.next; + for(int i=0;iindex;i--){ + p = p.prev; + } + } + return p; + } + + private class Node{ + + private T data; + private Node prev; + private Node next; + public Node(T data, Node prev, Node next) { + super(); + this.data = data; + this.prev = prev; + this.next = next; + } + + + + } +} diff --git a/group04/465034663/src/com/xusheng/stack/MyLinkedStack2.java b/group04/465034663/src/com/xusheng/stack/MyLinkedStack2.java new file mode 100644 index 0000000000..1f9f722d46 --- /dev/null +++ b/group04/465034663/src/com/xusheng/stack/MyLinkedStack2.java @@ -0,0 +1,52 @@ +package com.xusheng.stack; + +/** + * 此栈是用单链表实现 + * @author xusheng + * + */ +public class MyLinkedStack2 { + + private Node beginNode; + private Node endNode; + private int size; + + + + public MyLinkedStack2() { + size = 0; + doClear(); + } + + private void doClear(){ + endNode = new Node(null,null); + beginNode = new Node(null,beginNode); + } + + private void insert(Node p,T element){ + Node newNode = new Node(element,p.next); + p.next = newNode; + this.size++; + } + + private Node getNode(int index){ + Node p; + p = beginNode.next; + for(int i=0;i{ + public T data; + public Node next; + public Node(T data, Node next) { + this.data = data; + this.next = next; + } + + + } + +} diff --git a/group04/465034663/src/com/xusheng/stack/TestMain.java b/group04/465034663/src/com/xusheng/stack/TestMain.java new file mode 100644 index 0000000000..eedb3e1354 --- /dev/null +++ b/group04/465034663/src/com/xusheng/stack/TestMain.java @@ -0,0 +1,17 @@ +package com.xusheng.stack; + +public class TestMain { + + public static void main(String[] args) { + MyLinkedStack mls = new MyLinkedStack(); + mls.add(0,"haha1"); + mls.add(1, "haha2"); + mls.push("haha3"); + System.out.println(mls.pop()); + System.out.println(mls.size()); + System.out.println(mls.pop()); + System.out.println(mls.size()); + System.out.println(mls.pop()); + System.out.println(mls.size()); + } +} diff --git a/group04/465034663/src/com/xusheng/tree/AvlTree.java b/group04/465034663/src/com/xusheng/tree/AvlTree.java new file mode 100644 index 0000000000..d4e1beb500 --- /dev/null +++ b/group04/465034663/src/com/xusheng/tree/AvlTree.java @@ -0,0 +1,217 @@ +package com.xusheng.tree; + +/** + * 实现平衡二叉树 + * @author xusheng + * + * @param + */ +public class AvlTree> { + + private AvlNode root; + + public AvlTree() { + this.root = null; + } + + /** + * 对不平衡点的左儿子的左子树进行插入 + * 将二叉树围绕不平衡点的左子节点进行左旋转 + * @param k2 + * @return + */ + private AvlNode rotateWithLeftChild(AvlNode k2){ + AvlNode k1 = k2.leftNode; + k2.leftNode = k1.rightNode; + k1.rightNode = k2; + k2.height = Math.max(height(k2.leftNode), height(k2.rightNode))+1; + k1.height = Math.max(height(k1.leftNode), k2.height)+1; + return k1; + } + + /** + * 对不平衡点的右儿子的右子树进行插入 + * 将二叉树围绕不平衡点的右子节点进行旋转 + * @param k2 + * @return + */ + private AvlNode rotateWithRightChild(AvlNode k2){ + AvlNode k1 = k2.rightNode; + k2.rightNode = k1.leftNode; + k1.leftNode = k2; + k2.height = Math.max(height(k2.leftNode), height(k2.rightNode))+1; + k1.height = Math.max(height(k1.rightNode), k2.height)+1; + return k1; + } + + /** + * 对不平衡点的左儿子的右子树进行插入 + * 先将二叉树不平衡点的左儿子围绕它的右子节点旋转 + * 后将二叉树围绕不平衡点的左儿子进行旋转 + * @param k3 + * @return + */ + private AvlNode doubleRotateWithLeftChild(AvlNode k3){ + k3.leftNode = rotateWithRightChild(k3.leftNode); + return rotateWithLeftChild(k3); + } + + /** + * 对不平衡点的右儿子的左子树进行插入 + * 先将二叉树不平衡点的右儿子围绕它的左子节点旋转 + * 后将二叉树围绕不平衡点的右儿子进行旋转 + * @param k3 + * @return + */ + private AvlNode doubleRotateWithRightChild(AvlNode k3){ + k3.rightNode = rotateWithLeftChild(k3.rightNode); + return rotateWithRightChild(k3); + } + + private static final int ALLOW_IMBALANCE = 1;//该常量表示数的高度差最多为1 + /** + * 此方法用来对二叉树进行平衡 + * @param node + * @return + */ + private AvlNode balance(AvlNode node){ + + if(node == null){ + return node; + } + + if(height(node.leftNode) - height(node.rightNode) > ALLOW_IMBALANCE){ + if(height(node.leftNode.leftNode) >= height(node.leftNode.rightNode)){ + node = rotateWithLeftChild(node); + }else{ + node = doubleRotateWithLeftChild(node); + } + }else if(height(node.rightNode) - height(node.leftNode) > ALLOW_IMBALANCE){ + if(height(node.rightNode.rightNode) >= height(node.rightNode.leftNode)){ + node = rotateWithRightChild(node); + }else{ + node = doubleRotateWithRightChild(node); + } + } + + node.height = Math.max(height(node.leftNode), height(node.rightNode))+1; + + return node; + } + private int height(AvlNode t){ + return t == null ? -1 : t.height; + } + + public boolean isEmpty(){ + return this.root == null; + } + + public void insert(T element){ + root = insert(element,root); + } + + private AvlNode insert(T element,AvlNode node){ + if(node == null){ + return new AvlNode(element,null,null); + } + + int intCompare = element.compareTo(node.data); + + if(intCompare < 0){ + node.leftNode = insert(element,node.leftNode); + }else if(intCompare > 0){ + node.rightNode = insert(element,node.rightNode); + } + return node; + } + + + public boolean contains(T element){ + return contains(element,root); + } + + private boolean contains(T element,AvlNode node){ + + if(node == null){ + return false; + } + + int intCompare = element.compareTo(node.data); + + if(intCompare < 0){ + return contains(element,node.leftNode); + }else if(intCompare > 0){ + return contains(element,node.rightNode); + }else{ + return true; + } + } + + public void remove(T element){ + remove(element,root); + } + + private AvlNode remove(T element,AvlNode node){ + if(node == null){ + return node; + } + + int intCompare = element.compareTo(node.data); + + if(intCompare < 0){ + node.leftNode = remove(element,node.leftNode); + }else if(intCompare > 0){ + node.rightNode = remove(element,node.rightNode); + } + else if(node.leftNode != null && node.rightNode != null){ + node.data = findMin(node).data; + node.rightNode = remove(node.data,node.rightNode); + }else{ + node = (node.leftNode != null) ? node.leftNode : node.rightNode; + } + return node; + } + + + private AvlNode findMin(AvlNode node){ + if(node == null){ + return null; + }else if(node.leftNode == null){ + return node; + }else{ + return findMin(node.leftNode); + } + } + + private AvlNode findMax(AvlNode node){ + if(node == null){ + return null; + } + + while(node.rightNode != null){ + node = node.rightNode; + } + + return node; + } + + private class AvlNode{ + + private T data; + private AvlNode leftNode; + private AvlNode rightNode; + private int height; + + public AvlNode(T data, AvlNode leftNode,AvlNode rightNode) { + this.data = data; + this.leftNode = leftNode; + this.rightNode = rightNode; + } + + public AvlNode(T element) { + this(element,null,null); + } + + + } +} diff --git a/group04/465034663/src/com/xusheng/tree/BinarySearchTree.java b/group04/465034663/src/com/xusheng/tree/BinarySearchTree.java new file mode 100644 index 0000000000..6a2799db72 --- /dev/null +++ b/group04/465034663/src/com/xusheng/tree/BinarySearchTree.java @@ -0,0 +1,128 @@ +package com.xusheng.tree; + +/** + * 实现二叉查找树 + * @author xusheng + * + * @param + */ +public class BinarySearchTree> { + + private BinaryNode root; + + public BinarySearchTree() { + this.root = null; + } + + public boolean isEmpty(){ + return this.root == null; + } + + public void insert(T element){ + root = insert(element,root); + } + + private BinaryNode insert(T element,BinaryNode node){ + if(node == null){ + return new BinaryNode(element,null,null); + } + + int intCompare = element.compareTo(node.data); + + if(intCompare < 0){ + node.leftNode = insert(element,node.leftNode); + }else if(intCompare > 0){ + node.rightNode = insert(element,node.rightNode); + } + return node; + } + + + public boolean contains(T element){ + return contains(element,root); + } + + private boolean contains(T element,BinaryNode node){ + + if(node == null){ + return false; + } + + int intCompare = element.compareTo(node.data); + + if(intCompare < 0){ + return contains(element,node.leftNode); + }else if(intCompare > 0){ + return contains(element,node.rightNode); + }else{ + return true; + } + } + + public void remove(T element){ + remove(element,root); + } + + private BinaryNode remove(T element,BinaryNode node){ + if(node == null){ + return node; + } + + int intCompare = element.compareTo(node.data); + + if(intCompare < 0){ + node.leftNode = remove(element,node.leftNode); + }else if(intCompare > 0){ + node.rightNode = remove(element,node.rightNode); + } + else if(node.leftNode != null && node.rightNode != null){ + node.data = findMin(node).data; + node.rightNode = remove(node.data,node.rightNode); + }else{ + node = (node.leftNode != null) ? node.leftNode : node.rightNode; + } + return node; + } + + + private BinaryNode findMin(BinaryNode node){ + if(node == null){ + return null; + }else if(node.leftNode == null){ + return node; + }else{ + return findMin(node.leftNode); + } + } + + private BinaryNode findMax(BinaryNode node){ + if(node == null){ + return null; + } + + while(node.rightNode != null){ + node = node.rightNode; + } + + return node; + } + + private class BinaryNode{ + + private T data; + private BinaryNode leftNode; + private BinaryNode rightNode; + + public BinaryNode(T data, BinaryNode leftNode,BinaryNode rightNode) { + this.data = data; + this.leftNode = leftNode; + this.rightNode = rightNode; + } + + public BinaryNode(T element) { + this(element,null,null); + } + + + } +} diff --git a/group04/465034663/src/com/xusheng/tree/TestMain.java b/group04/465034663/src/com/xusheng/tree/TestMain.java new file mode 100644 index 0000000000..3f3af252dd --- /dev/null +++ b/group04/465034663/src/com/xusheng/tree/TestMain.java @@ -0,0 +1,21 @@ +package com.xusheng.tree; + +public class TestMain { + + public static void main(String[] args) { + BinarySearchTree bst = new BinarySearchTree(); + bst.insert(8); + bst.insert(3); + bst.insert(7); + bst.insert(1); + bst.insert(10); + System.out.println(bst.contains(3)); + bst.remove(4); + System.out.println(bst.contains(3)); +// BinarySearchTree bst = new BinarySearchTree(); +// bst.insert("haha1"); +// bst.insert("haha2"); +// bst.insert("haha3"); +// System.out.println(bst.contains("haha3")); + } +} From 5ab7d2a3197f283c722b64b2f5b492877f053cdd Mon Sep 17 00:00:00 2001 From: Arthur <465034663@qq.com> Date: Sun, 26 Feb 2017 12:11:36 +0800 Subject: [PATCH 022/475] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group04/465034663/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/group04/465034663/.gitignore b/group04/465034663/.gitignore index e69de29bb2..ae3c172604 100644 --- a/group04/465034663/.gitignore +++ b/group04/465034663/.gitignore @@ -0,0 +1 @@ +/bin/ From bfa02e5d37abf341e251356b3b2b4f28b72c7700 Mon Sep 17 00:00:00 2001 From: Arthur <465034663@qq.com> Date: Sun, 26 Feb 2017 12:13:31 +0800 Subject: [PATCH 023/475] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group04/465034663/.settings/org.eclipse.core.resources.prefs | 2 ++ group04/465034663/.settings/org.eclipse.core.runtime.prefs | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 group04/465034663/.settings/org.eclipse.core.resources.prefs create mode 100644 group04/465034663/.settings/org.eclipse.core.runtime.prefs diff --git a/group04/465034663/.settings/org.eclipse.core.resources.prefs b/group04/465034663/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000000..4824b80263 --- /dev/null +++ b/group04/465034663/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/group04/465034663/.settings/org.eclipse.core.runtime.prefs b/group04/465034663/.settings/org.eclipse.core.runtime.prefs new file mode 100644 index 0000000000..f8a67de1d4 --- /dev/null +++ b/group04/465034663/.settings/org.eclipse.core.runtime.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +line.separator=\r\n 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 024/475] 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 025/475] =?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 026/475] =?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 027/475] 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 028/475] =?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 16:26:48 +0800 Subject: [PATCH 029/475] 2/19homework --- group14/641013587/14_641013587/.classpath | 7 + group14/641013587/14_641013587/.gitignore | 1 + group14/641013587/14_641013587/.project | 17 +++ .../.settings/org.eclipse.jdt.core.prefs | 11 ++ .../src/com/coding/basic/ArrayList.java | 79 +++++++++++ .../src/com/coding/basic/BinaryTreeNode.java | 32 +++++ .../src/com/coding/basic/Iterator.java | 7 + .../src/com/coding/basic/LinkedList.java | 123 ++++++++++++++++++ .../src/com/coding/basic/List.java | 9 ++ .../src/com/coding/basic/Queue.java | 19 +++ .../src/com/coding/basic/Stack.java | 25 ++++ .../src/com/coding/test/MyTest.java | 59 +++++++++ .../641013587/RemoteSystemsTempFiles/.project | 12 ++ 13 files changed, 401 insertions(+) create mode 100644 group14/641013587/14_641013587/.classpath create mode 100644 group14/641013587/14_641013587/.gitignore create mode 100644 group14/641013587/14_641013587/.project create mode 100644 group14/641013587/14_641013587/.settings/org.eclipse.jdt.core.prefs create mode 100644 group14/641013587/14_641013587/src/com/coding/basic/ArrayList.java create mode 100644 group14/641013587/14_641013587/src/com/coding/basic/BinaryTreeNode.java create mode 100644 group14/641013587/14_641013587/src/com/coding/basic/Iterator.java create mode 100644 group14/641013587/14_641013587/src/com/coding/basic/LinkedList.java create mode 100644 group14/641013587/14_641013587/src/com/coding/basic/List.java create mode 100644 group14/641013587/14_641013587/src/com/coding/basic/Queue.java create mode 100644 group14/641013587/14_641013587/src/com/coding/basic/Stack.java create mode 100644 group14/641013587/14_641013587/src/com/coding/test/MyTest.java create mode 100644 group14/641013587/RemoteSystemsTempFiles/.project diff --git a/group14/641013587/14_641013587/.classpath b/group14/641013587/14_641013587/.classpath new file mode 100644 index 0000000000..373dce4005 --- /dev/null +++ b/group14/641013587/14_641013587/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/group14/641013587/14_641013587/.gitignore b/group14/641013587/14_641013587/.gitignore new file mode 100644 index 0000000000..ae3c172604 --- /dev/null +++ b/group14/641013587/14_641013587/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/group14/641013587/14_641013587/.project b/group14/641013587/14_641013587/.project new file mode 100644 index 0000000000..7433fa7872 --- /dev/null +++ b/group14/641013587/14_641013587/.project @@ -0,0 +1,17 @@ + + + 14_641013587 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/group14/641013587/14_641013587/.settings/org.eclipse.jdt.core.prefs b/group14/641013587/14_641013587/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..3a21537071 --- /dev/null +++ b/group14/641013587/14_641013587/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/group14/641013587/14_641013587/src/com/coding/basic/ArrayList.java b/group14/641013587/14_641013587/src/com/coding/basic/ArrayList.java new file mode 100644 index 0000000000..48b84f02a2 --- /dev/null +++ b/group14/641013587/14_641013587/src/com/coding/basic/ArrayList.java @@ -0,0 +1,79 @@ +package com.coding.basic; + +public class ArrayList implements List { + + private int size = 0; + + private Object[] elementData = new Object[100]; + + public void add(Object o){ + //�ҳ����һ���յ�λ�ø�ֵ + for(int i=0;i=size){ + return this.elementData[elementData.length]; + }else{ + return this.elementData[index]; + } + } + + public Object remove(int index){ + Object object = get(index); + System.arraycopy(elementData,index+1,elementData,index,size-1); + elementData[size-1]=null; + size--; + return object; + } + + public int size(){ + return size; + } + + public Iterator iterator(){ + + return new Iterator() { + + private int nextNum=0; + + @Override + public Object next() { + return get(nextNum++); + } + + @Override + public boolean hasNext() { + return nextNum>=size?false:true; + } + }; + } + +} diff --git a/group14/641013587/14_641013587/src/com/coding/basic/BinaryTreeNode.java b/group14/641013587/14_641013587/src/com/coding/basic/BinaryTreeNode.java new file mode 100644 index 0000000000..d7ac820192 --- /dev/null +++ b/group14/641013587/14_641013587/src/com/coding/basic/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/group14/641013587/14_641013587/src/com/coding/basic/Iterator.java b/group14/641013587/14_641013587/src/com/coding/basic/Iterator.java new file mode 100644 index 0000000000..06ef6311b2 --- /dev/null +++ b/group14/641013587/14_641013587/src/com/coding/basic/Iterator.java @@ -0,0 +1,7 @@ +package com.coding.basic; + +public interface Iterator { + public boolean hasNext(); + public Object next(); + +} diff --git a/group14/641013587/14_641013587/src/com/coding/basic/LinkedList.java b/group14/641013587/14_641013587/src/com/coding/basic/LinkedList.java new file mode 100644 index 0000000000..de7114b424 --- /dev/null +++ b/group14/641013587/14_641013587/src/com/coding/basic/LinkedList.java @@ -0,0 +1,123 @@ +package com.coding.basic; + +public class LinkedList implements List { + + private Node head=new Node(); + + public void add(Object o){ + if(head.data==null){ + head.data=o; + return; + } + Node node=head; + for(;node.next!=null;){ + node=node.next; + } + node.next=new Node(); + node.next.data=o; + + } + public void add(int index , Object o){ + if(index==0){ + addFirst(o); + return; + } + Node node=head; + for(int i=0;i + + RemoteSystemsTempFiles + + + + + + + org.eclipse.rse.ui.remoteSystemsTempNature + + From 34f6b4db2c96c8fec8d216e77e4c8a3430768399 Mon Sep 17 00:00:00 2001 From: jianghaonan Date: Sun, 26 Feb 2017 19:56:05 +0800 Subject: [PATCH 030/475] =?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 031/475] =?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 032/475] 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 033/475] 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 034/475] =?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 035/475] 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 036/475] 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 037/475] 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 038/475] 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 039/475] 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: Sun, 26 Feb 2017 23:57:49 +0800 Subject: [PATCH 040/475] HomeWork --- .../src/com/xxt/DataStructure/List.java | 9 ++ .../com/xxt/DataStructure/MyArrayList.java | 99 ++++++++++++ .../com/xxt/DataStructure/MyLinkedList.java | 141 ++++++++++++++++++ .../src/com/xxt/DataStructure/MyQueue.java | 88 +++++++++++ .../src/com/xxt/DataStructure/MyStack.java | 52 +++++++ .../com/xxt/DataStructure/base/ArrayList.java | 36 +++++ .../DataStructure/base/BinaryTreeNode.java | 32 ++++ .../com/xxt/DataStructure/base/Iterator.java | 7 + .../xxt/DataStructure/base/LinkedList.java | 48 ++++++ .../src/com/xxt/DataStructure/base/List.java | 12 ++ .../src/com/xxt/DataStructure/base/Queue.java | 18 +++ .../src/com/xxt/DataStructure/base/Stack.java | 24 +++ 12 files changed, 566 insertions(+) create mode 100644 group01/553624797/code2017/src/com/xxt/DataStructure/List.java create mode 100644 group01/553624797/code2017/src/com/xxt/DataStructure/MyArrayList.java create mode 100644 group01/553624797/code2017/src/com/xxt/DataStructure/MyLinkedList.java create mode 100644 group01/553624797/code2017/src/com/xxt/DataStructure/MyQueue.java create mode 100644 group01/553624797/code2017/src/com/xxt/DataStructure/MyStack.java create mode 100644 group01/553624797/code2017/src/com/xxt/DataStructure/base/ArrayList.java create mode 100644 group01/553624797/code2017/src/com/xxt/DataStructure/base/BinaryTreeNode.java create mode 100644 group01/553624797/code2017/src/com/xxt/DataStructure/base/Iterator.java create mode 100644 group01/553624797/code2017/src/com/xxt/DataStructure/base/LinkedList.java create mode 100644 group01/553624797/code2017/src/com/xxt/DataStructure/base/List.java create mode 100644 group01/553624797/code2017/src/com/xxt/DataStructure/base/Queue.java create mode 100644 group01/553624797/code2017/src/com/xxt/DataStructure/base/Stack.java diff --git a/group01/553624797/code2017/src/com/xxt/DataStructure/List.java b/group01/553624797/code2017/src/com/xxt/DataStructure/List.java new file mode 100644 index 0000000000..473354e821 --- /dev/null +++ b/group01/553624797/code2017/src/com/xxt/DataStructure/List.java @@ -0,0 +1,9 @@ +package com.xxt.DataStructure; + +public interface List { + public void add(Object o); + public void add(int index, Object o); + public Object get(int index); + public Object remove(int index); + public int size(); +} diff --git a/group01/553624797/code2017/src/com/xxt/DataStructure/MyArrayList.java b/group01/553624797/code2017/src/com/xxt/DataStructure/MyArrayList.java new file mode 100644 index 0000000000..9d3f3e8f03 --- /dev/null +++ b/group01/553624797/code2017/src/com/xxt/DataStructure/MyArrayList.java @@ -0,0 +1,99 @@ +package com.xxt.DataStructure; + +import java.util.ArrayList; +import java.util.Arrays; + +/** + * Created by star on 2017/2/26. + */ +public class MyArrayList implements List { + + + + private Object[] elementData; + private int size = elementData.length; + + + public MyArrayList(int initialCapacity) { + if (initialCapacity > 0) { + this.elementData = new Object[initialCapacity]; + } else { + throw new IllegalArgumentException("Illegal Capacity: " + initialCapacity); + } + } + + public MyArrayList() { + this(10); + } + + + @Override + public void add(Object o) { + ensureCapacity(size + 1); + elementData[size + 1] = o; + } + + @Override + public void add(int index, Object o) { + //判断数组下标是否越界 + if(index < 0 || index > elementData.length){ + throw new IndexOutOfBoundsException("index : "+index+"size : "+size); + } + ensureCapacity(index); + System.arraycopy(elementData, index,elementData, index + 1, size - index); + elementData[index] = o; + size++; + } + + @Override + public Object get(int index) { + return elementData[index]; + } + + @Override + public Object remove(int index) { + //判断数组下标是否越界 + if(index < 0 || index > elementData.length){ + throw new IndexOutOfBoundsException("index : "+index+"size : "+size); + } + + + //取出删除的值 + Object oldValue = elementData[index]; + + //做删除操作同样是复制数组 + //计算要删除的数量 + int numMoved = size - index - 1; + if ( numMoved > 0){ + System.arraycopy(elementData, index + 1, elementData, index, numMoved); + } + + //将数组最后一个元素置为空,让GC回收 + elementData[size - 1] = null; + return oldValue; + + } + + @Override + public int size() { + return elementData.length; + } + + + //判断是否扩容 + public void ensureCapacity(int minCapacity) { + //取得当前数组容量 + int currentCapacity = elementData.length; + //如果最小需要的容量小于当前数组容量则需要扩容 + if (minCapacity < currentCapacity) { + int newCapacity = currentCapacity + (currentCapacity >> 1); + //如果扩容后的长度还是小于最小需要的长度,则直接以最小需要的长度作为当前数组的长度 + if (newCapacity < minCapacity) { + newCapacity = minCapacity; + elementData = Arrays.copyOf(elementData, newCapacity); + } + } + + } + +} diff --git a/group01/553624797/code2017/src/com/xxt/DataStructure/MyLinkedList.java b/group01/553624797/code2017/src/com/xxt/DataStructure/MyLinkedList.java new file mode 100644 index 0000000000..0c40956197 --- /dev/null +++ b/group01/553624797/code2017/src/com/xxt/DataStructure/MyLinkedList.java @@ -0,0 +1,141 @@ +package com.xxt.DataStructure; + +import java.util.Iterator; + +import java.util.LinkedList; +import java.util.function.Consumer; + +/** + * Created by star on 2017/2/25. + */ +public class MyLinkedList implements List{ + + public static class Node{ + E elementData; + Node prerious; + Node next; + + public Node(Node prerious , E elementData, Node next) { + this.prerious = prerious; + this.elementData= elementData; + this.next = next; + } + } + + + + private Node header; + private Node last; + + private int size = 0; + + + //往最后一个节点添加元素 + @Override + public void add(Object elementData) { + addBefore((E) elementData, last); + } + + @Override + public void add(int index, Object elementData) { + addBefore((E) elementData, (index == size ? last : node(index))); + } + + @Override + public Object get(int index) { + return node(index).elementData; + + } + + //获取index位置的节点 + private Node node(int index){ + if(index < 0 || index > size){ + throw new IndexOutOfBoundsException("数组下标越界"+size); + } + + if(index < (size >> 1)){ + Node e = header; + for(int i = 0; i < index; i ++){ + e = header.next; + return e; + } + }else { + Node e = last; + for(int i = size - 1; i > index; i--){ + e = last.prerious; + return e; + } + } + return null; + } + + + @Override + public Object remove(int index) { + + if (index < 0 || index > size) { + throw new IndexOutOfBoundsException("inde :" + index); + } + + return remove(node(index)); + } + + + + //返回被删除的节点 + private Object remove(Node e){ + E movedElementData = e.elementData; + + //被删除节点的上个节点指向该节点的下个节点 + e.prerious.next = e.next; + + //被删除节点的下个节点指向该节点的上个节点 + e.next.prerious = e.prerious; + + + //将该节点置为空,让GC能够回收 + e.next = e.prerious = null; + e.elementData = null; + //长度-1 + size--; + return movedElementData; + } + + + @Override + public int size() { + return size; + } + + public Object removeFirst(){ + return remove(header.next); + + + } + + public Object removeLast(){ + return remove(last.prerious); + } + + public Iterator iterator(){ + return null; + } + + + + //插入一个新的节点 + private Node addBefore(E e, Node node){ + + Node newNode = new Node(node.prerious, e, node.next); + + //将上个节点的next指向自己 + newNode.prerious.next = newNode; + + //将下个节点的previous指向自己 + newNode.next.prerious = newNode; + + size++; + return newNode; + } + +} diff --git a/group01/553624797/code2017/src/com/xxt/DataStructure/MyQueue.java b/group01/553624797/code2017/src/com/xxt/DataStructure/MyQueue.java new file mode 100644 index 0000000000..75d878af3b --- /dev/null +++ b/group01/553624797/code2017/src/com/xxt/DataStructure/MyQueue.java @@ -0,0 +1,88 @@ +package com.xxt.DataStructure; + +import java.util.Iterator; + +/** + * Created by star on 2017/2/26. + */ +public class MyQueue{ + + + public static class Node{ + Object elementData; + Node prerious; + Node next; + + public Node(Object elementData, Node prerious, Node next) { + this.elementData = elementData; + this.prerious = prerious; + this.next = next; + } + + } + + + private MyQueue.Node header; + private MyQueue.Node last; + + private int size = 0; + + + //入队操作.在链表的头节点插入元素 + public void enQueue(Object o){ + addBefore(o, header); + } + + + //出队操作,返回链表的尾节点的元素 + public Object deQueue(){ + return node(size); + } + + + public boolean isEmpty(){ + return header == last; + } + + + + public int size(){ + return size; + } + + private Node addBefore(Object o , Node node){ + Node newNode = new Node(o, node.prerious, node.next); + + newNode.prerious.next = newNode; + newNode.next.prerious = newNode; + + size++; + return newNode; + + } + + + private Node node(int index){ + if(index < 0 || index > size){ + throw new IndexOutOfBoundsException("数组下标越界"+size); + } + + if(index < (size >> 1)){ + Node e = header; + for(int i = 0; i < index; i ++){ + e = header.next; + return e; + } + }else { + Node e = last; + for(int i = size - 1; i > index; i--){ + e = last.prerious; + return e; + } + } + return null; + } + + + +} diff --git a/group01/553624797/code2017/src/com/xxt/DataStructure/MyStack.java b/group01/553624797/code2017/src/com/xxt/DataStructure/MyStack.java new file mode 100644 index 0000000000..4ac0cf3698 --- /dev/null +++ b/group01/553624797/code2017/src/com/xxt/DataStructure/MyStack.java @@ -0,0 +1,52 @@ +package com.xxt.DataStructure; + +import java.util.EmptyStackException; + +/** + * Created by star on 2017/2/26. + */ +public class MyStack { + + + //采用数组实现; + private Object[] array; + //栈顶指针 + private int top; + private final static int size = 100; + + public MyStack(Object[] array, int top) { + this.array = array; + //空栈 + top = -1 ; + } + + public void push(Object elementData){ + //栈满 + if(top == size - 1){ + throw new StackOverflowError(); + }else { + array[++top] = elementData; + } + } + + //弹栈 + public Object pop(){ + if( top == -1){ + throw new EmptyStackException(); + }else { + return array[top--]; + } + } + + public boolean isEmpty(){ + return top == -1; + } + + public Object peek(){ + if(top == -1){ + throw new EmptyStackException(); + }else { + return array[top]; + } + } +} diff --git a/group01/553624797/code2017/src/com/xxt/DataStructure/base/ArrayList.java b/group01/553624797/code2017/src/com/xxt/DataStructure/base/ArrayList.java new file mode 100644 index 0000000000..635c22fa88 --- /dev/null +++ b/group01/553624797/code2017/src/com/xxt/DataStructure/base/ArrayList.java @@ -0,0 +1,36 @@ +package com.xxt.DataStructure.base; + +import com.xxt.DataStructure.base.List; + +import java.util.Iterator; + +public class ArrayList implements List { + + private int size = 0; + + private Object[] elementData = new Object[100]; + + public void add(Object o){ + + } + public void add(int index, Object o){ + + } + + public Object get(int index){ + return null; + } + + public Object remove(int index){ + return null; + } + + public int size(){ + return -1; + } + + public Iterator iterator(){ + return null; + } + +} diff --git a/group01/553624797/code2017/src/com/xxt/DataStructure/base/BinaryTreeNode.java b/group01/553624797/code2017/src/com/xxt/DataStructure/base/BinaryTreeNode.java new file mode 100644 index 0000000000..ada0b84c78 --- /dev/null +++ b/group01/553624797/code2017/src/com/xxt/DataStructure/base/BinaryTreeNode.java @@ -0,0 +1,32 @@ +package com.xxt.DataStructure.base; + +public class BinaryTreeNode { + + private Object data; + private BinaryTreeNode left; + private BinaryTreeNode right; + + public Object getData() { + return data; + } + public void setData(Object data) { + this.data = data; + } + public BinaryTreeNode getLeft() { + return left; + } + public void setLeft(BinaryTreeNode left) { + this.left = left; + } + public BinaryTreeNode getRight() { + return right; + } + public void setRight(BinaryTreeNode right) { + this.right = right; + } + + public BinaryTreeNode insert(Object o){ + return null; + } + +} diff --git a/group01/553624797/code2017/src/com/xxt/DataStructure/base/Iterator.java b/group01/553624797/code2017/src/com/xxt/DataStructure/base/Iterator.java new file mode 100644 index 0000000000..4c8b3ae747 --- /dev/null +++ b/group01/553624797/code2017/src/com/xxt/DataStructure/base/Iterator.java @@ -0,0 +1,7 @@ +package com.xxt.DataStructure.base; + +public interface Iterator { + public boolean hasNext(); + public Object next(); + +} diff --git a/group01/553624797/code2017/src/com/xxt/DataStructure/base/LinkedList.java b/group01/553624797/code2017/src/com/xxt/DataStructure/base/LinkedList.java new file mode 100644 index 0000000000..924cf10ff0 --- /dev/null +++ b/group01/553624797/code2017/src/com/xxt/DataStructure/base/LinkedList.java @@ -0,0 +1,48 @@ +package com.xxt.DataStructure.base; + +import com.xxt.DataStructure.base.List; + +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 com.xxt.DataStructure.base.Iterator iterator(){ + return null; + } + + + private static class Node{ + Object data; + Node next; + + } +} diff --git a/group01/553624797/code2017/src/com/xxt/DataStructure/base/List.java b/group01/553624797/code2017/src/com/xxt/DataStructure/base/List.java new file mode 100644 index 0000000000..2148154c46 --- /dev/null +++ b/group01/553624797/code2017/src/com/xxt/DataStructure/base/List.java @@ -0,0 +1,12 @@ +package com.xxt.DataStructure.base; + +/** + * Created by star on 2017/2/26. + */ +public interface List { + public void add(Object o); + public void add(int index, Object o); + public Object get(int index); + public Object remove(int index); + public int size(); +} \ No newline at end of file diff --git a/group01/553624797/code2017/src/com/xxt/DataStructure/base/Queue.java b/group01/553624797/code2017/src/com/xxt/DataStructure/base/Queue.java new file mode 100644 index 0000000000..5427579179 --- /dev/null +++ b/group01/553624797/code2017/src/com/xxt/DataStructure/base/Queue.java @@ -0,0 +1,18 @@ +package com.xxt.DataStructure.base; + +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/group01/553624797/code2017/src/com/xxt/DataStructure/base/Stack.java b/group01/553624797/code2017/src/com/xxt/DataStructure/base/Stack.java new file mode 100644 index 0000000000..9c62bcdceb --- /dev/null +++ b/group01/553624797/code2017/src/com/xxt/DataStructure/base/Stack.java @@ -0,0 +1,24 @@ +package com.xxt.DataStructure.base; + +import com.xxt.DataStructure.base.ArrayList; + +public class Stack { + private ArrayList elementData = new ArrayList(); + + public void push(Object o){ + } + + public Object pop(){ + return null; + } + + public Object peek(){ + return null; + } + public boolean isEmpty(){ + return false; + } + public int size(){ + return -1; + } +} From 112528a3679a5cd2e84d41e11e6ad9ac06618bf8 Mon Sep 17 00:00:00 2001 From: greenhills <63912401@qq.com> Date: Mon, 27 Feb 2017 00:30:58 +0800 Subject: [PATCH 041/475] 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 c88098699dabc6ede2c44b6749bd4e136f41deb4 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 27 Feb 2017 08:35:00 +0800 Subject: [PATCH 042/475] LinkedList --- .../java/com/coding/basic/LinkedList.java | 157 +++++++++++++----- .../src/main/java/com/coding/basic/Queue.java | 6 + .../java/com/coding/basic/LinkedListTest.java | 37 ++++- 3 files changed, 153 insertions(+), 47 deletions(-) diff --git a/group04/24658892/learnjava/src/main/java/com/coding/basic/LinkedList.java b/group04/24658892/learnjava/src/main/java/com/coding/basic/LinkedList.java index e2c4e5e795..aec01c6cc6 100644 --- a/group04/24658892/learnjava/src/main/java/com/coding/basic/LinkedList.java +++ b/group04/24658892/learnjava/src/main/java/com/coding/basic/LinkedList.java @@ -1,46 +1,119 @@ 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; - - } + + private Node head; + private Node tail; + private int size; + + public LinkedList() { + head = new Node(null, null); + tail = head; + } + + public void add(Object o) { + tail = new Node(o, null); + if (head.next == null) { + head.next = tail; + } + else { + Node node = head.next; + int i = 0; + while (node.next != null && i < size) { + node = node.next; + i++; + } + node.next = tail; + } + size++; + } + + public void add(int index, Object o) { + if (index > size) { + throw new IndexOutOfBoundsException(); + } + if (index == 0) { + addFirst(o); + } + else if (index == size) { + addLast(o); + } + else { + Node node = head.next; + for (int i = 0; i < index; i++) { + node = node.next; + } + node.next = new Node(o, node.next); + } + size++; + } + + public Object get(int index) { + return null; + } + + public Object remove(int index) { + return null; + } + + public int size() { + return size; + } + + public void addFirst(Object o) { + head.next = new Node(o, head.next); + size++; + } + + public void addLast(Object o) { + Node node = tail; + tail = new Node(o, null); + node.next = tail; + size++; + } + + public Object removeFirst() { + if (head.next == null) { + throw new IndexOutOfBoundsException(); + } + Node node = head.next; + head.next = node.next; + node.next = null; + return node; + } + + public Object removeLast() { + return null; + } + + public Iterator iterator() { + return null; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + if (size > 0) { + Node node = head.next; + int i = 0; + while (node.next != null && i < size) { + sb.append("index=").append(i).append(";value=").append(node.data).append("\n"); + node = node.next; + i++; + } + sb.append("index=").append(i).append(";value=").append(node.data).append("\n"); + } + return sb.toString(); + } + + private static class Node { + + Node(Object data, Node next) { + this.data = data; + this.next = next; + } + + Object data; + Node next; + } } diff --git a/group04/24658892/learnjava/src/main/java/com/coding/basic/Queue.java b/group04/24658892/learnjava/src/main/java/com/coding/basic/Queue.java index 4c87d9cb16..90eb1fe9a6 100644 --- a/group04/24658892/learnjava/src/main/java/com/coding/basic/Queue.java +++ b/group04/24658892/learnjava/src/main/java/com/coding/basic/Queue.java @@ -1,5 +1,7 @@ package com.coding.basic; +import java.util.EmptyStackException; + public class Queue { private ArrayList elementData = new ArrayList(); @@ -11,6 +13,10 @@ public void enQueue(Object o) { } public Object deQueue() { + if (isEmpty()) { + throw new EmptyStackException(); + } + size--; return elementData.remove(0); } diff --git a/group04/24658892/learnjava/src/test/java/com/coding/basic/LinkedListTest.java b/group04/24658892/learnjava/src/test/java/com/coding/basic/LinkedListTest.java index 6acbb70d37..8df8e631bf 100644 --- a/group04/24658892/learnjava/src/test/java/com/coding/basic/LinkedListTest.java +++ b/group04/24658892/learnjava/src/test/java/com/coding/basic/LinkedListTest.java @@ -6,12 +6,25 @@ public class LinkedListTest { @Test public void add() throws Exception { - + LinkedList linkedList = new LinkedList(); + linkedList.add(0); + linkedList.add(1); + linkedList.add(2); + linkedList.add(3); + linkedList.add(4); + System.out.print(linkedList.toString()); } @Test public void add1() throws Exception { - + LinkedList linkedList = new LinkedList(); + linkedList.add(0); + linkedList.add(1); + linkedList.add(2); + linkedList.add(3); + linkedList.add(4); + linkedList.add(2,21); + System.out.print(linkedList.toString()); } @Test @@ -31,17 +44,31 @@ public void size() throws Exception { @Test public void addFirst() throws Exception { - + LinkedList linkedList = new LinkedList(); + linkedList.addFirst(1); + linkedList.addFirst(2); + linkedList.addFirst(3); + System.out.print(linkedList.toString()); } @Test public void addLast() throws Exception { - + LinkedList linkedList = new LinkedList(); + linkedList.addLast(1); + linkedList.addLast(2); + linkedList.addLast(3); + System.out.print(linkedList.toString()); } @Test public void removeFirst() throws Exception { - + LinkedList linkedList = new LinkedList(); + linkedList.addLast(1); + linkedList.addLast(2); + linkedList.addLast(3); + linkedList.removeFirst(); + linkedList.removeFirst(); + System.out.print(linkedList.toString()); } @Test From 23ae157a3aad38ac19a9e1358102f75b3eca0334 Mon Sep 17 00:00:00 2001 From: JayXu Date: Mon, 27 Feb 2017 08:51:10 +0800 Subject: [PATCH 043/475] 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 044/475] 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 045/475] 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 @@ -