From c4b94e171d1f2b3f840282b6ce875318cd81e94a Mon Sep 17 00:00:00 2001 From: xiaozi Date: Wed, 8 Mar 2017 23:08:18 +0800 Subject: [PATCH 1/4] This is a test. --- group24/1054283210/.classpath | 6 ++++++ group24/1054283210/.gitignore | 1 + group24/1054283210/.project | 17 +++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 group24/1054283210/.classpath create mode 100644 group24/1054283210/.gitignore create mode 100644 group24/1054283210/.project diff --git a/group24/1054283210/.classpath b/group24/1054283210/.classpath new file mode 100644 index 0000000000..d171cd4c12 --- /dev/null +++ b/group24/1054283210/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/group24/1054283210/.gitignore b/group24/1054283210/.gitignore new file mode 100644 index 0000000000..ae3c172604 --- /dev/null +++ b/group24/1054283210/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/group24/1054283210/.project b/group24/1054283210/.project new file mode 100644 index 0000000000..b401802bd0 --- /dev/null +++ b/group24/1054283210/.project @@ -0,0 +1,17 @@ + + + 1054283210Learning + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + From 43aece6c0f38ed06904695de001272eb3e90aeb6 Mon Sep 17 00:00:00 2001 From: xiaozi Date: Sun, 12 Mar 2017 20:08:46 +0800 Subject: [PATCH 2/4] This is the first week's work. --- group24/1054283210/.classpath | 1 + .../xiaozi123/coding2017/basic/ArrayList.java | 103 +++++++++++ .../coding2017/basic/BinaryTreeNode.java | 72 ++++++++ .../xiaozi123/coding2017/basic/Iterator.java | 7 + .../coding2017/basic/LinkedList.java | 163 ++++++++++++++++++ .../xiaozi123/coding2017/basic/List.java | 9 + .../xiaozi123/coding2017/basic/Queue.java | 46 +++++ .../xiaozi123/coding2017/basic/Stack.java | 51 ++++++ ...7\347\253\240\345\234\260\345\235\200.txt" | 1 + 9 files changed, 453 insertions(+) create mode 100644 group24/1054283210/src/com/github/xiaozi123/coding2017/basic/ArrayList.java create mode 100644 group24/1054283210/src/com/github/xiaozi123/coding2017/basic/BinaryTreeNode.java create mode 100644 group24/1054283210/src/com/github/xiaozi123/coding2017/basic/Iterator.java create mode 100644 group24/1054283210/src/com/github/xiaozi123/coding2017/basic/LinkedList.java create mode 100644 group24/1054283210/src/com/github/xiaozi123/coding2017/basic/List.java create mode 100644 group24/1054283210/src/com/github/xiaozi123/coding2017/basic/Queue.java create mode 100644 group24/1054283210/src/com/github/xiaozi123/coding2017/basic/Stack.java create mode 100644 "group24/1054283210/src/com/github/xiaozi123/coding2017/basic/\346\226\207\347\253\240\345\234\260\345\235\200.txt" diff --git a/group24/1054283210/.classpath b/group24/1054283210/.classpath index d171cd4c12..2d7497573f 100644 --- a/group24/1054283210/.classpath +++ b/group24/1054283210/.classpath @@ -2,5 +2,6 @@ + diff --git a/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/ArrayList.java b/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/ArrayList.java new file mode 100644 index 0000000000..891c355406 --- /dev/null +++ b/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/ArrayList.java @@ -0,0 +1,103 @@ +package com.github.xiaozi123.coding2017.basic; + +import java.util.Arrays; + +import org.omg.CORBA.PUBLIC_MEMBER; + +public class ArrayList implements List { + + private int size = 0; + + private Object[] elementData = new Object[100]; + + public void add(Object o){ + if(size>=elementData.length){//如果没有内存 获取两倍内存 + elementData=Arrays.copyOf(elementData,size+1); + } + elementData[size]=o; + size++; + } + public void add(int index, Object o){ + if(index<0||index>=elementData.length){ + throw new ArrayIndexOutOfBoundsException("OutOfBound"); + } + + if(size>=elementData.length){//如果没有内存 获取两倍内存 + elementData=Arrays.copyOf(elementData, size+1); + } + System.arraycopy(elementData, index, elementData, index+1, elementData.length-index-1); + elementData[index]=o; + size++; + } + + public Object get(int index){ + if(index<0||index>=elementData.length){ + throw new ArrayIndexOutOfBoundsException("OutOfBound"); + } + return elementData[index]; + } + + public Object remove(int index){ + if(index<0||index>=elementData.length){ + throw new ArrayIndexOutOfBoundsException("OutOfBound"); + } + Object temp=elementData[index]; + System.arraycopy(elementData, index+1, elementData, index, elementData.length-index-1); + size--; + return temp; + } + + /* + * (non-Javadoc)获取目前长度 + * @see com.github.xiaozi123.coding2017.basic.List#size() + */ + public int size(){ + if(size>=elementData.length){//如果没有内存 获取两倍内存 + elementData=Arrays.copyOf(elementData,size+1); + } + return size; + } + + // next() hasnext()方法 + public Iterator iterator(){ + return new Iterator(){ + private int index = 0; + public Object next(){ + return elementData[index++]; + } + public boolean hasNext(){ + return index >= size; + } + }; + } + + public static void main(String[] args) { + ArrayList arrayList=new ArrayList(); + + arrayList.add(0); + arrayList.add(1); + arrayList.add(2); + System.out.println("数据个数为3:"+(arrayList.size==3)); + + System.out.print("数据应该为0,1,2: "); + for (int i = 0; i < arrayList.size(); i++) { + System.out.print(arrayList.get(i)+" "); + } + System.out.println(); + + arrayList.add(1,1); + System.out.print("数据应该为:0,1,1,2: "); + for (int i = 0; i < arrayList.size(); i++) { + System.out.print(arrayList.get(i)+" "); + } + System.out.println(); + + System.out.print("数据应该为0: "); + System.out.println(arrayList.remove(0)); + + + } + + +} + diff --git a/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/BinaryTreeNode.java b/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/BinaryTreeNode.java new file mode 100644 index 0000000000..a86b1b15bd --- /dev/null +++ b/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/BinaryTreeNode.java @@ -0,0 +1,72 @@ +package com.github.xiaozi123.coding2017.basic; + +public class BinaryTreeNode { + + private Object data; + private BinaryTreeNode left; + private BinaryTreeNode right; + + public Object getData() { + return data; + } + public void setData(Object data) { + this.data = data; + } + public BinaryTreeNode getLeft() { + return left; + } + public void setLeft(BinaryTreeNode left) { + this.left = left; + } + public BinaryTreeNode getRight() { + return right; + } + public void setRight(BinaryTreeNode right) { + this.right = right; + } + + public BinaryTreeNode insert(Object o){ + if (data==null) { + this.setData(0); + } + if ((Integer)o<=(Integer)data) { + if (left==null) { + left=new BinaryTreeNode(); + left.setData(o); + return left; + } + return left.insert(o); + }else{ + if (right==null) { + right=new BinaryTreeNode(); + right.setData(o); + return right; + } + return right.insert(o); + + } + } + @Override + public String toString() { + // TODO Auto-generated method stub + return data+" "+left+" "+right; + } + + public static void main(String[] args) { + BinaryTreeNode binaryTreeNode=new BinaryTreeNode(); + for (int i = 0; i < 5; i++) { + binaryTreeNode.insert(i); + } + System.out.println(binaryTreeNode); + } + +// 0 +// 0 1 +// null null null 2 +// null 3 +// null 4 +// null null + + + +} diff --git a/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/Iterator.java b/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/Iterator.java new file mode 100644 index 0000000000..35c6b39017 --- /dev/null +++ b/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/Iterator.java @@ -0,0 +1,7 @@ +package com.github.xiaozi123.coding2017.basic; + +public interface Iterator { + public boolean hasNext(); + public Object next(); + +} diff --git a/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/LinkedList.java b/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/LinkedList.java new file mode 100644 index 0000000000..66ab1e0300 --- /dev/null +++ b/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/LinkedList.java @@ -0,0 +1,163 @@ +package com.github.xiaozi123.coding2017.basic; + +import java.util.NoSuchElementException; + +import jdk.nashorn.internal.ir.IndexNode; + +public class LinkedList implements List { + + private Node head; + private int size; + + private Node node(Object o) { + Node now=new Node(); + now.data=o; + now.next=null; + size++; + return now; + } + + public void add(Object o){ + if (head==null) { + head=node(o); + } + else { + addLast(o); + } + + } + public void add(int index , Object o){ + if (index<0||index>size) { + throw new IndexOutOfBoundsException("OutOfBound"); + }else if (index==0) { + addFirst(o); + }else if (index==size+1) { + addLast(o); + }else{ + Node beforeNode=head; + for (int i = 0; i < index-1; i++) { + beforeNode=beforeNode.next; + } + Node addNode=node(o); + addNode.next=beforeNode.next; + beforeNode.next=addNode; + } + } + + + public Object get(int index){ + if (index<0||index>size) { + throw new IndexOutOfBoundsException("OutOfBound"); + } else { + Node indexNode=head; + for (int i = 0; i < index; i++) { + indexNode=indexNode.next; + } + return indexNode.data; + } + + } + public Object remove(int index){ + if (index<0||index>size) { + throw new IndexOutOfBoundsException("OutOfBound"); + }else if(index==0){ + return removeFirst(); + }else if(index==size){ + return removeLast(); + + }else{ + Node beforeNode=head; + for (int i = 0; i < index-1; i++) { + beforeNode=beforeNode.next; + } + + Node indexNode=head; + for (int i = 0; i < index; i++) { + indexNode=indexNode.next; + } + beforeNode.next=indexNode.next; + indexNode.next=null; + size--; + return indexNode.data; + } + } + + public int size(){ + return size; + } + + public void addFirst(Object o){ + Node headNode=node(o); + headNode.data=o; + headNode.next=head.next; + head=headNode; + + } + + public void addLast(Object o){ + Node tailNode=head; + while(tailNode.next!=null){ + tailNode=tailNode.next; + } + Node lastNode=node(o); + tailNode.next=lastNode; + } + public Object removeFirst(){ + if (head==null) { + throw new NoSuchElementException(); + } + Object temp= head.data; + head=head.next; + size--; + return temp; + } + public Object removeLast(){ + if (head==null) { + throw new NoSuchElementException(); + } + Node newNode=head; + while(newNode.next.next!=null){ + newNode=newNode.next; + } + Node lastNode=newNode.next; + newNode.next=null; + size--; + return lastNode.data; + + } + public Iterator iterator(){ + return null; + } + + + private static class Node{ + Object data; + Node next; + + } + + public static void main(String[] args) { + LinkedList linkedList=new LinkedList(); + + linkedList.add(1); + linkedList.add(2); + linkedList.add(3); + + System.out.println("数字个数为3:"+linkedList.size()); + + System.out.println("获取的数字为1:"+linkedList.get(0)); + System.out.println("获取的数字为2:"+linkedList.get(1)); + System.out.println("获取的数字为3:"+linkedList.get(2)); + // add get remove size + + System.out.println("*************"); + + System.out.println(linkedList.remove(0));//1 + System.out.println("获取的数字为2:"+linkedList.get(0)); + System.out.println("获取的数字为3:"+linkedList.get(1)); + System.out.println("数字个数为2:"+linkedList.size()); + + } + +} + diff --git a/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/List.java b/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/List.java new file mode 100644 index 0000000000..950ce93269 --- /dev/null +++ b/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/List.java @@ -0,0 +1,9 @@ +package com.github.xiaozi123.coding2017.basic; + +public interface List { + public void add(Object o); + public void add(int index, Object o); + public Object get(int index); + public Object remove(int index); + public int size(); +} diff --git a/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/Queue.java b/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/Queue.java new file mode 100644 index 0000000000..75b122a253 --- /dev/null +++ b/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/Queue.java @@ -0,0 +1,46 @@ +package com.github.xiaozi123.coding2017.basic; + +public class Queue { + private LinkedList elementData=new LinkedList(); + + public void enQueue(Object o){ + elementData.add(o); + } + + public Object deQueue(){ + return elementData.removeFirst(); + } + + public boolean isEmpty(){ + return elementData.size()==0; + } + + public int size(){ + return elementData.size(); + } + + public static void main(String[] args) { + Queue queue=new Queue(); + if (queue.isEmpty()) { + System.out.println("队列现在是空。"); + } + + int n=3; + for (int i = 0; i < n; i++) { + queue.enQueue(i); + } + System.out.println("队列现在有"+queue.size()+"个数"); + System.out.print("队首应该是:0---"); + System.out.println(queue.deQueue()); + System.out.print("队伍第二个数应该是:1---"); + System.out.println(queue.deQueue()); + System.out.print("队伍第二个数应该是:2---"); + System.out.println(queue.deQueue()); + + + + + } + + +} diff --git a/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/Stack.java b/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/Stack.java new file mode 100644 index 0000000000..d9994f5648 --- /dev/null +++ b/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/Stack.java @@ -0,0 +1,51 @@ +package com.github.xiaozi123.coding2017.basic; + +public class Stack { + private ArrayList elementData = new ArrayList(); + + /* + * 入栈 + */ + public void push(Object o){ + elementData.add(o); + } + + public Object pop(){ + return elementData.remove(elementData.size()-1); + } + + public Object peek(){ + return elementData.get(elementData.size()-1); + } + public boolean isEmpty(){ + return elementData.size()==0; + } + public int size(){ + return elementData.size(); + } + + public static void main(String[] args) { + Stack stack=new Stack(); + if (stack.isEmpty()) { + System.out.println("stack为空。"); + } + int n=3; + for (int i = 0; i < n; i++) { + stack.push(i); + } + System.out.println("stack现在尺寸应该为3:"+(stack.size()==3)); + System.out.println("stack里面数据应该为:2,1,0."); + for (int i = 0; i < n; i++) { + System.out.println(stack.pop()); + } +// for (int i = 0; i < n; i++) { +// stack.peek(); +// } +// + + + + } + + +} diff --git "a/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/\346\226\207\347\253\240\345\234\260\345\235\200.txt" "b/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/\346\226\207\347\253\240\345\234\260\345\235\200.txt" new file mode 100644 index 0000000000..3977d579a8 --- /dev/null +++ "b/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/\346\226\207\347\253\240\345\234\260\345\235\200.txt" @@ -0,0 +1 @@ +http://www.jianshu.com/p/6688791d16c0 \ No newline at end of file From 87eab63a90471f48a41c142649a578f603a45c07 Mon Sep 17 00:00:00 2001 From: xiaozi Date: Sun, 12 Mar 2017 20:44:08 +0800 Subject: [PATCH 3/4] add --- .../src/com/github/xiaozi123/coding2017/basic/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 group24/1054283210/src/com/github/xiaozi123/coding2017/basic/.gitignore diff --git a/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/.gitignore b/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/.gitignore new file mode 100644 index 0000000000..ae3c172604 --- /dev/null +++ b/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/.gitignore @@ -0,0 +1 @@ +/bin/ From 2d87167e4a56def4f78f0556cabc2ebe1b9c8d2a Mon Sep 17 00:00:00 2001 From: xiaozi Date: Sun, 12 Mar 2017 20:54:01 +0800 Subject: [PATCH 4/4] This is my first week's work. --- .../xiaozi123/coding2017/basic/.gitignore | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/.gitignore b/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/.gitignore index ae3c172604..2c93a035dc 100644 --- a/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/.gitignore +++ b/group24/1054283210/src/com/github/xiaozi123/coding2017/basic/.gitignore @@ -1 +1,27 @@ -/bin/ +*.class +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +#ide config +.metadata +.recommenders +.idea/ +*.iml +rebel.* +.rebel.* + +# Idea +*.iml +*.ipr +*.iws +.idea + +target