diff --git a/.gitignore b/.gitignore index 2a5296f902..7f06ac1c28 100644 --- a/.gitignore +++ b/.gitignore @@ -7,15 +7,25 @@ *.war *.ear +*.iml +*.idea + + # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* #ide config .metadata .recommenders + + +#macOS +.DS_Store + .idea/ *.iml rebel.* .rebel.* target + diff --git a/group16/1012075117/DataStructure219/.classpath b/group16/1012075117/DataStructure219/.classpath new file mode 100644 index 0000000000..fceb4801b5 --- /dev/null +++ b/group16/1012075117/DataStructure219/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/group16/1012075117/DataStructure219/.project b/group16/1012075117/DataStructure219/.project new file mode 100644 index 0000000000..567baae65f --- /dev/null +++ b/group16/1012075117/DataStructure219/.project @@ -0,0 +1,17 @@ + + + DataStructure219 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/group16/1012075117/DataStructure219/.settings/org.eclipse.jdt.core.prefs b/group16/1012075117/DataStructure219/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..3a21537071 --- /dev/null +++ b/group16/1012075117/DataStructure219/.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/group16/1012075117/DataStructure219/src/com/stackwei/DataStructure/ArrayList.java b/group16/1012075117/DataStructure219/src/com/stackwei/DataStructure/ArrayList.java new file mode 100644 index 0000000000..a1d46a21d8 --- /dev/null +++ b/group16/1012075117/DataStructure219/src/com/stackwei/DataStructure/ArrayList.java @@ -0,0 +1,94 @@ +package com.stackwei.DataStructure; + +/** + * + * @author stackwei -2017.2.25 + * + */ +public class ArrayList implements List { + + private int flag = -1; + private static final int DEFAULT_CAPACITY = 1; + private Object[] elementData = new Object[DEFAULT_CAPACITY]; + + @Override + public void add(Object element) { + // 当要添加数据的位置已经超过数组长度时,增长数组长度 + if (size() + 1 == elementData.length) { + grow(); + } + elementData[flag + 1] = element; + flag++; + } + + @Override + public void add(int index, Object element) { + if (index < 0 || index > getFlag() + 1) { + System.out.println("在--" + index + "--添加的--" + element + "--无效,因为越界了!"); + return; + } + // 数组长度永远比已存数据大一个。 + if (size() + 1 == elementData.length) { + grow(); + } + elementData[index] = element; + if (index > getFlag()) { + flag++; + } + } + + @Override + public Object get(int index) { + if (index < 0 || index > getFlag()) { + System.out.print("在--" + index + "--的get无效,因为越界了!"); + return null; + } + return elementData[index]; + } + + @Override + public Object remove(int index) { + if (index < 0 || index > getFlag()) { + System.out.println("在--" + index + "--的remove无效,因为越界了!"); + return null; + } + Object oldValue = elementData[index]; + elementData[index] = null; + // 将删除处后面的数据往前移一格。 + Object[] data2 = new Object[elementData.length - 1]; + System.arraycopy(elementData, 0, data2, 0, getFlag()); + elementData = data2; + flag--; + return oldValue; + } + + @Override + public int size() { + return getFlag() + 1; + } + + public int getFlag() { + return flag; + } + + private void grow() { + Object[] data2 = new Object[elementData.length + 1]; + System.arraycopy(elementData, 0, data2, 0, getFlag() + 2);// 最后一个参数是需要复制的数据的数量。 + elementData = data2; + } + + /** + * 测试用例 + * + * @param args + */ + public static void main(String[] args) { + ArrayList al = new ArrayList(); + al.add(0, 99); + al.add(1, 100); + System.out.println(al.get(1)); + al.remove(1); + System.out.println(al.get(1)); + System.out.println(al.size()); + } +} \ No newline at end of file diff --git a/group16/1012075117/DataStructure219/src/com/stackwei/DataStructure/LinkedList.java b/group16/1012075117/DataStructure219/src/com/stackwei/DataStructure/LinkedList.java new file mode 100644 index 0000000000..a1c728f0a1 --- /dev/null +++ b/group16/1012075117/DataStructure219/src/com/stackwei/DataStructure/LinkedList.java @@ -0,0 +1,194 @@ +package com.stackwei.DataStructure; + +/** + * + * @author stackwei -2017.2.25 + * + */ +public class LinkedList implements List { + + private Node head = null; + private Node last = null; + private int size = 0; + + private static class Node { + Object item; + Node prev; + Node next; + + public Node(Node prev, Object item, Node next) { + this.prev = prev; + this.item = item; + this.next = next; + } + } + + @Override + public void add(Object element) { + addLast(element); + } + + @Override + public void add(int index, Object element) { + if (index < 0 || index > size) { + System.out.println("操作无效,越界了"); + return; + } + if (index == 0) { + addFirst(element); + return; + } + if (index == size) { + addLast(element); + return; + } + Node indexNode = node(index); + Node newNode = new Node(indexNode.prev, element, indexNode); + indexNode.prev.next = newNode; + indexNode.prev = newNode; + size++; + } + + @Override + public Object get(int index) { + if (index < 0 || index >= size) { + System.out.println("查询无效,越界了"); + return null; + } + if (index == 0) { + return head.item; + } + return node(index).item; + } + + @Override + public Object remove(int index) { + if (index < 0 || index > size) { + System.out.println("是空的,无法删除"); + return null; + } + if (index == 0) { + return removeFirst(); + } + if (index == size - 1) { + return removeLast(); + } + Node x = node(index); + final Object element = x.item; + final Node next = x.next; + final Node prev = x.prev; + + if (prev == null) { + head = next; + } else { + prev.next = next; + x.prev = null; + } + + if (next == null) { + last = prev; + } else { + next.prev = prev; + x.next = null; + } + + x.item = null; + size--; + return element; + } + + @Override + public int size() { + return size; + } + + private void addFirst(Object element) { + final Node f = head; + Node newNode = new Node(null, element, f); + head = newNode; + if (f == null) + last = newNode; + else + f.prev = newNode; + size++; + } + + public void addLast(Object element) { + if (head == null) { + addFirst(element); + } else { + Node newNode = new Node(last, element, null); + last.next = newNode; + last = newNode; + size++; + } + } + + public Object removeFirst() { + if (head == null) { + System.out.println("是空的,无法删除"); + return null; + } else { + Node x = head; + Node next = head.next; + Object element = x.item; + x.item = null; + x.next = null; + head = next; + if (next == null) + last = null; + else + x.prev = null; + size--; + return element; + } + } + + public Object removeLast() { + if (last == null) { + System.out.println("是空的,无法删除"); + return null; + } else { + final Node l = last; + final Object element = l.item; + final Node p = l.prev; + l.item = null; + l.prev = null; + last = p; + if (p == null) + head = null; + else + p.next = null; + size--; + return element; + } + } + + Node node(int index) { + if (index < (size >> 1)) { + Node x = head; + for (int i = 0; i < index; i++) + x = x.next; + return x; + } else { + Node x = last; + for (int i = size - 1; i > index; i--) + x = x.prev; + return x; + } + } + + /** + * 测试用例 + * + * @param args + */ + public static void main(String[] args) { + LinkedList ll = new LinkedList(); + ll.add(0, "xxx"); + ll.add(1, 111); + System.out.println(ll.size()); + System.out.println(ll.get(2)); + + } +} \ No newline at end of file diff --git a/group16/1012075117/DataStructure219/src/com/stackwei/DataStructure/List.java b/group16/1012075117/DataStructure219/src/com/stackwei/DataStructure/List.java new file mode 100644 index 0000000000..5226796141 --- /dev/null +++ b/group16/1012075117/DataStructure219/src/com/stackwei/DataStructure/List.java @@ -0,0 +1,13 @@ +package com.stackwei.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/group16/1012075117/DataStructure219/src/com/stackwei/DataStructure/Queue.java b/group16/1012075117/DataStructure219/src/com/stackwei/DataStructure/Queue.java new file mode 100644 index 0000000000..4a227495e9 --- /dev/null +++ b/group16/1012075117/DataStructure219/src/com/stackwei/DataStructure/Queue.java @@ -0,0 +1,52 @@ +package com.stackwei.DataStructure; + +/** + * + * @author stackwei -2017.2.25 + * + */ +public class Queue { + + private LinkedList ll = new LinkedList(); + + /** + * 在队尾添加数据 + * @param element + */ + public void enQueue(Object element) { + ll.addLast(element); + } + + /** + * 删除队头数据 + * @return + */ + public Object deQueue() { + return ll.removeFirst(); + } + + /** + * 队列是否为空 + * @return + */ + public boolean isEmpty() { + if (ll.size() > 0) { + return false; + } + return true; + } + + /** + * 测试用例 + * @param args + */ + public static void main(String[] args) { + Queue q = new Queue(); + q.enQueue(97); + q.enQueue(98); + q.enQueue(99); + System.out.println(q.isEmpty()); + System.out.println(q.deQueue()); + } + +} diff --git a/group16/1012075117/DataStructure219/src/com/stackwei/DataStructure/Stack.java b/group16/1012075117/DataStructure219/src/com/stackwei/DataStructure/Stack.java new file mode 100644 index 0000000000..1b047ffafd --- /dev/null +++ b/group16/1012075117/DataStructure219/src/com/stackwei/DataStructure/Stack.java @@ -0,0 +1,59 @@ +package com.stackwei.DataStructure; + +/** + * + * @author stackwei -2017.2.25 + * + */ +public class Stack { + + private ArrayList al = new ArrayList(); + + /** + * 进栈 + * @param item + */ + public void push(Object item) { + al.add(item); + } + + /** + * 出栈 + * @return + */ + public Object pop() { + return al.remove(al.getFlag()); + } + + /** + * 获取栈顶元素 + * @return + */ + public Object peek() { + return al.get(al.getFlag()); + } + + /** + * 栈是否为空 + * @return + */ + public boolean isEmpty() { + if (al.getFlag() >= 0) { + return false; + } + return true; + } + + /** + * 测试用例 + * @param args + */ + public static void main(String[] args) { + Stack s = new Stack(); + s.push(98); + s.push(99); + s.pop(); + System.out.println(s.peek()); + } + +} diff --git a/group16/1154151360/.classpath b/group16/1154151360/.classpath new file mode 100644 index 0000000000..fb5011632c --- /dev/null +++ b/group16/1154151360/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/group16/1154151360/.gitignore b/group16/1154151360/.gitignore new file mode 100644 index 0000000000..ae3c172604 --- /dev/null +++ b/group16/1154151360/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/group16/1154151360/.project b/group16/1154151360/.project new file mode 100644 index 0000000000..f88388f6d7 --- /dev/null +++ b/group16/1154151360/.project @@ -0,0 +1,17 @@ + + + DataStructure2 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/group16/1154151360/.settings/org.eclipse.core.resources.prefs b/group16/1154151360/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000000..99f26c0203 --- /dev/null +++ b/group16/1154151360/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/group16/1154151360/src/com/list/ArrayList.java b/group16/1154151360/src/com/list/ArrayList.java new file mode 100644 index 0000000000..733dc0f341 --- /dev/null +++ b/group16/1154151360/src/com/list/ArrayList.java @@ -0,0 +1,93 @@ +package com.list; + + +//ArrayList +public class ArrayList { + + private int size; + + private Object [] elementData = new Object[10]; + + public boolean add(Object data){ + + getRow(size+1); + elementData[size++] = data; + return true; + } + + public boolean add(int index, Object data){ + if (index < 0 || index > elementData.length){ + throw new IndexOutOfBoundsException("�±�Խ��"); + } + getRow(size + 1); + Object object = elementData [index]; + System.arraycopy(elementData, index,elementData , index + 1,size - index ); + elementData[index] = data; + size++; + return true; + } + + public Object get(int index){ + if (index < 0 || index > elementData.length){ + throw new IndexOutOfBoundsException("下标越界"); + } + return elementData[index]; + } + + public Object remove(int index){ + if (index < 0 || index > elementData.length){ + throw new IndexOutOfBoundsException("下标越界"); + } + Object object = elementData [index]; + System.arraycopy(elementData, index + 1 , elementData, index, size - 1 - index); + elementData[size--]= null; + return object; + } + + + private void getRow(int num){ + if (num > elementData.length ){ + int oldLength = elementData.length; + int newLength = ((num + elementData.length) * 3) >> 2; + Object [] oldelements = elementData; + elementData = new Object[newLength]; + System.arraycopy(oldelements, 0, elementData, 0, size); + } + } + + public int size(){ + return size; + } + + public int length(){ + return elementData.length; + } + public static void main(String[] args) { + ArrayList list = new ArrayList(); + + list.add("A"); + list.add("B"); + list.add("C"); + list.add("D"); + list.add("E"); + list.add("F"); + list.add("G"); + list.add("H"); + list.add("I"); + list.add("J"); + list.add("K"); + list.add("L"); + list.add(2, 1); + System.out.println("elementsData.Length: "+list.length()); + System.out.println("elementsData.size: "+list.size()); + for (int i = 0; i < list.size; i++){ + System.out.print(list.get(i)+ " "); + } + System.out.println(" "); + list.remove(2); + + for (int i = 0; i < list.size; i++){ + System.out.print(list.get(i)+ " "); + } + } +} diff --git a/group16/1154151360/src/com/list/LinkedList.java b/group16/1154151360/src/com/list/LinkedList.java new file mode 100644 index 0000000000..46f61fb667 --- /dev/null +++ b/group16/1154151360/src/com/list/LinkedList.java @@ -0,0 +1,158 @@ +package com.list; + +public class LinkedList { + + private int size; + + private Node head;//头节点 + + Node current; //当前节点 + + public LinkedList(){ + this.head = current = new Node(null); + this.size = 0; + } + + + private boolean add(Object object){ + addAfter(object); + size++; + return true; + } + + + private boolean add(int index,Object object) throws Exception{ + index(index - 1); + current.nextNode = new Node(object,current.nextNode.nextNode); + size++; + return true; + } + + + private boolean addFirst(Object object){ + Node node = new Node(object,null); + current = head.nextNode; + head.nextNode = node; + node.nextNode = current; + size++; + return true; + } + + + private boolean addLast(Object object){ + add(object); + return true; + } + + + private Object get(int index) throws Exception{ + index(index); + return current.object; + } + + + private Object remove(int index) throws Exception{ + + if (index == size - 1){ + Object object = removeLast(); + return object; + } + index(index - 1); + Object object = current.nextNode.object; + + current.nextNode = current.nextNode.nextNode; + size--; + return object; + } + + private Object removeFirst(){ + Object object = null; + if (size > 0){ + current = head.nextNode; + object = current.object; + head.nextNode = head.nextNode.nextNode; + size--; + } + return object; + } + + private Object removeLast() throws Exception{ + Object object = null; + if (size > 0){ + int j = 0; + current = head.nextNode; + + while (current != null){ + current = current.nextNode; + j++; + } + index(j - 1); + object = current.nextNode.object; + current.nextNode = null; + size--; + } + return object; + } + private void index (int index) throws Exception{ + + if (index < -1 || index > size){ + + throw new Exception(" "); + } + + if (index == -1){ + return; + } + current = head.nextNode; + int j = 0; + while (current != null && j < index){ + current = current.nextNode; + j++; + } + } + + + private void addAfter(Object object){ + + if (head.nextNode == null){ + + Node newNode = new Node(object,null); + }else{ + current = head.nextNode; + while (current.nextNode == null){ + current = current.nextNode; + } + current.setNode(new Node(object,null)); + } + + + } + + + + + private static class Node{ + + Object object; + + Node nextNode; + + + Node (Node nextNode){ + this.nextNode = nextNode; + } + + + Node (Object object, Node nextNode){ + this.nextNode = nextNode; + this.object = object; + } + + private void setNode(Node node){ + this.nextNode = node; + } + + } + + +} diff --git a/group16/1154151360/src/com/list/Queue.java b/group16/1154151360/src/com/list/Queue.java new file mode 100644 index 0000000000..faa3e87381 --- /dev/null +++ b/group16/1154151360/src/com/list/Queue.java @@ -0,0 +1,51 @@ +package com.list; +//队列 +public class Queue { + + Object [] element; + + private static int DEFAULT_SIZE = 10; + + int front;//头指针 + + int rear;//尾指针 + + public Queue(){ + this(DEFAULT_SIZE); + } + public Queue(int size){ + element = new Object[size]; + this.front = 0; + this.rear = 0; + } + + public boolean enQueue(Object object){ + + if ((rear + 1) % element.length == front){ + return false; + }else{ + element[rear] = object; + rear = (rear + 1) % element.length; + return true; + } + } + + public Object deQueue(){ + if (front == rear){ + return null; + }else{ + Object object = element[front]; + front = (front + 1) % element.length; + return object; + } + + } + + public int size(){ + return (rear -front) & (element.length - 1); + } + + public boolean isEmpty(){ + return rear == front; + } +} diff --git a/group16/1154151360/src/com/list/Stack.java b/group16/1154151360/src/com/list/Stack.java new file mode 100644 index 0000000000..f92a9e731c --- /dev/null +++ b/group16/1154151360/src/com/list/Stack.java @@ -0,0 +1,35 @@ +package com.list; + +import java.util.ArrayList; +import java.util.EmptyStackException; + +public class Stack { + + ArrayList elelmentData = new ArrayList(); + + //压入栈 + public void push(Object object){ + elelmentData.add(object); + } + + //弹出栈 + public Object pop(){ + if (isEmpty()){ throw new EmptyStackException();} + return elelmentData.remove(elelmentData.size() - 1); + } + + //取栈顶元素 + public Object peek(){ + if (isEmpty()){return null;} + return elelmentData.get(elelmentData.size() - 1); + } + + public boolean isEmpty(){ + return elelmentData.isEmpty(); + } + + public int size(){ + if (isEmpty()){throw new EmptyStackException();} + return elelmentData.size(); + } +} diff --git a/group16/1287642108/0226/src/com/coding/basic/ArrayList.java b/group16/1287642108/0226/src/com/coding/basic/ArrayList.java new file mode 100644 index 0000000000..e287419dc0 --- /dev/null +++ b/group16/1287642108/0226/src/com/coding/basic/ArrayList.java @@ -0,0 +1,63 @@ +package com.coding.basic; + +public class ArrayList implements List { + + private int size = 0; + + private Object[] elementData = new Object[100]; + + public void add(Object o) { + IncrementsCapacity(size + 1); + elementData[size++] = o; + + } + + public void add(int index, Object o) { + checkIndex(index); + IncrementsCapacity(size + 1); + System.arraycopy(elementData, index, elementData, index + 1, size - index); + elementData[index] = o; + size++; + } + + public Object get(int index) { + checkIndex(index); + return elementData[index]; + } + + public Object remove(int index) { + checkIndex(index); + Object o = elementData[index]; + System.arraycopy(elementData, index + 1, elementData, index, size - index - 1); + elementData[--size] = null; + return o; + } + + public int size() { + return size; + } + + public int length() { + return elementData.length; + } + + // ���� + private void IncrementsCapacity(int num) { + if (num > elementData.length) { + int oldCapacity = elementData.length; // ��ǰ���鳤�� + int newCapacity = ((num + oldCapacity) * 3) >> 2; // ��ǰ���鳤�ȵ�1.5�� + if (newCapacity - num < 0) { + newCapacity = num; // �����������Dz���,ֱ����Ϊ����ֵ + } + Object[] oldelements = elementData; + elementData = new Object[newCapacity]; + System.arraycopy(oldelements, 0, elementData, 0, size); + } + } + + // �±�Խ���ж� + private void checkIndex(int index) { + if (index >= size || index < 0) + throw new IndexOutOfBoundsException("�����±�Խ��"); + } +} diff --git a/group16/1287642108/0226/src/com/coding/basic/Iterator.java b/group16/1287642108/0226/src/com/coding/basic/Iterator.java new file mode 100644 index 0000000000..e7cbd474ec --- /dev/null +++ b/group16/1287642108/0226/src/com/coding/basic/Iterator.java @@ -0,0 +1,6 @@ +package com.coding.basic; + +public interface Iterator { + public boolean hasNext(); + public Object next(); +} diff --git a/group16/1287642108/0226/src/com/coding/basic/LinkedList.java b/group16/1287642108/0226/src/com/coding/basic/LinkedList.java new file mode 100644 index 0000000000..99c92fb9f1 --- /dev/null +++ b/group16/1287642108/0226/src/com/coding/basic/LinkedList.java @@ -0,0 +1,101 @@ +package com.coding.basic; + +public class LinkedList implements List { + + private Node head; + private Node tail; + private int size = 0 ; + + public void add(Object o){ + addLast(o); + } + + public void add(int index, Object o) { + if (index == 0) { + addFirst(o); + } else if (index >= size) { + addLast(o); + } else { + Node node = new Node(); + node.data = o; + node.next = getNode(index); + getNode(index - 1).next = node; + size++; + } + } + + public Object get(int index) { + Node node = getNode(index); + return node.data; + } + + public Object remove(int index){ + Node currentNode = getNode(index); + Node prevNode = getNode(index - 1); + Node lastNode = getNode(index + 1); + prevNode.next = lastNode; + size--; + return currentNode.data; + } + + public int size(){ + return size; + } + + public void addFirst(Object o){ + Node node=new Node(); + node.data = o; + node.next = head; + head = node; + size++; + } + public void addLast(Object o){ + Node node=new Node(); + node.data = o; + node.next = null; + Node lastNode = getNode(size-1); + lastNode.next = node; + size++; + } + public Object removeFirst(){ + Object obj = getNode(0).data; + Node node = getNode(1); + node.next = head; + size--; + return obj; + } + public Object removeLast(){ + Object obj = getNode(size - 1).data; + Node node = getNode(size - 2); + node.next = null; + size--; + return obj; + } + + //��ȡ�ڵ� + public Node getNode(int index){ + checkIndex(index); + if(index == 0 ){ + return head; + }else if(index == size -1 ){ + return tail; + }else{ + Node node = head; + for(int i=0;i= size || index < 0) + throw new IndexOutOfBoundsException("�����±�Խ��"); + } + + private static class Node { + Object data; + Node next; + } +} diff --git a/group16/1287642108/0226/src/com/coding/basic/List.java b/group16/1287642108/0226/src/com/coding/basic/List.java new file mode 100644 index 0000000000..10d13b5832 --- /dev/null +++ b/group16/1287642108/0226/src/com/coding/basic/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/group16/1287642108/0226/src/com/coding/basic/Queue.java b/group16/1287642108/0226/src/com/coding/basic/Queue.java new file mode 100644 index 0000000000..95dee3d81b --- /dev/null +++ b/group16/1287642108/0226/src/com/coding/basic/Queue.java @@ -0,0 +1,28 @@ +package com.coding.basic; + +public class Queue { + private LinkedList elementData = new LinkedList(); + + public void enQueue(Object o){ + elementData.addLast(o); + } + + public Object deQueue(){ + if (isEmpty()) { + return null; + }else{ + return elementData.removeFirst(); + } + } + + public boolean isEmpty(){ + if (elementData.size() == 0) { + return true; + } + return false; + } + + public int size(){ + return elementData.size(); + } +} diff --git a/group16/1287642108/0226/src/com/coding/basic/Stack.java b/group16/1287642108/0226/src/com/coding/basic/Stack.java new file mode 100644 index 0000000000..c0b7da89f8 --- /dev/null +++ b/group16/1287642108/0226/src/com/coding/basic/Stack.java @@ -0,0 +1,38 @@ +package com.coding.basic; + +public class Stack { + private ArrayList elementData = new ArrayList(); + + public void push(Object o) { + if (isEmpty()) { + elementData.add(elementData.length() - 1, o); + } + elementData.add(elementData.length() - elementData.size() - 1, o); + } + + public Object pop() { + if (isEmpty()) { + return null; + } + return elementData.remove(elementData.length() - elementData.size() - 1); + } + + public Object peek() { + if (isEmpty()) { + return null; + } + return elementData.get(elementData.length() - elementData.size() - 1); + } + + public boolean isEmpty() { + if (elementData.size() == 0) { + return true; + } + return false; + } + + public int size() { + return elementData.size(); + } + +} diff --git a/group16/1325756593/.classpath b/group16/1325756593/.classpath new file mode 100644 index 0000000000..3e0fb272a8 --- /dev/null +++ b/group16/1325756593/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/group16/1325756593/.gitignore b/group16/1325756593/.gitignore new file mode 100644 index 0000000000..ae3c172604 --- /dev/null +++ b/group16/1325756593/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/group16/1325756593/.project b/group16/1325756593/.project new file mode 100644 index 0000000000..e3d07b6899 --- /dev/null +++ b/group16/1325756593/.project @@ -0,0 +1,17 @@ + + + DongqiHomeWork + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/group16/1325756593/dongqihust.readme b/group16/1325756593/dongqihust.readme new file mode 100644 index 0000000000..e69de29bb2 diff --git a/group16/1325756593/src/com/dong/week1/ArrayList.java b/group16/1325756593/src/com/dong/week1/ArrayList.java new file mode 100644 index 0000000000..a700aecfb5 --- /dev/null +++ b/group16/1325756593/src/com/dong/week1/ArrayList.java @@ -0,0 +1,109 @@ +package com.dong.week1; + +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){ + elementData = Arrays.copyOf(elementData, elementData.length*2+1); + } + elementData[size++]=o; + + } + public void add(int index, Object o){ + if(index >size || index < 0 ){ + throw new ArrayIndexOutOfBoundsException("����Խ��,��ǰ���鳤����"+size+",��������Ԫ�ص�������:"+index); + } + /** + * �����Ѿ����ˣ������� + */ + if(size==elementData.length){ + elementData = Arrays.copyOf(elementData, elementData.length*2+1); + } + Object[] elementDataClone = elementData.clone(); + System.arraycopy(elementData, index, elementDataClone, index+1, size-index); + elementDataClone[index++]=o; + size++; + elementData = elementDataClone; + } + + + public Object get(int index){ + if(index >=size || index < 0 ){ + throw new ArrayIndexOutOfBoundsException("����Խ��,��ǰ���鳤����"+size+",��������Ԫ�ص�������:"+index); + } + return elementData[index]; + } + + public Object remove(int index){ + if(index >=size || index < 0 ){ + throw new ArrayIndexOutOfBoundsException("����Խ��,��ǰ���鳤����"+size+",����ɾ��Ԫ�ص�������:"+index); + } + elementData[index]=null; + size--; + Object[] elementDataClone = elementData.clone(); + System.arraycopy(elementData, index+1, elementDataClone, index, size-index-1); + elementData = elementDataClone; + return elementData[index]; + } + + public int size(){ + return size; + } + + public Iterator iterator(){ + return new IteratorArrayList(this); + } + @Override + public String toString() { + return "ArrayList [size=" + size + ", elementData=" + Arrays.toString(elementData) + "]"; + } + + + private class IteratorArrayList implements Iterator{ + + private ArrayList arrayList; + private int index=0; + + + public IteratorArrayList(ArrayList arrayList) { + super(); + this.arrayList = arrayList; + } + + @Override + public boolean hasNext() { + // TODO Auto-generated method stub + return this.arrayList.size() >index; + } + + @Override + public Object next() { + // TODO Auto-generated method stub + if(hasNext()){ + return this.arrayList.get(index++); + } + return null; + } + + } + + public static void main(String[] args) { + ArrayList arrayList= new ArrayList(); + + Iterator iterator= arrayList.iterator(); + while(iterator.hasNext()){ + System.out.println(iterator.next()); + } + } + + +} diff --git a/group16/1325756593/src/com/dong/week1/ArrayListTest.java b/group16/1325756593/src/com/dong/week1/ArrayListTest.java new file mode 100644 index 0000000000..128130cfb2 --- /dev/null +++ b/group16/1325756593/src/com/dong/week1/ArrayListTest.java @@ -0,0 +1,63 @@ +package com.dong.week1; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class ArrayListTest { + + //@Test + public void testAddObject() { + ArrayList arrayList = new ArrayList(); + for(int i=0;i<=200;i++){ + arrayList.add(i); + } + System.out.println(arrayList); + } + + //@Test + public void testAddIntObject() { + ArrayList arrayList = new ArrayList(); + for(int i=0;i<=2;i++){ + arrayList.add(i); + } + arrayList.add(1,100); + arrayList.add(1, 1000); + System.out.println(arrayList); + } + +// @Test + public void testGet() { + ArrayList arrayList = new ArrayList(); + for(int i=0;i<=200;i++){ + arrayList.add(i); + } + //System.out.println(arrayList.get(-1)); + //System.out.println(arrayList.get(50)); + System.out.println(arrayList.get(200)); + //System.out.println(arrayList.get(300)); + + + } + + @Test + public void testRemove() { + ArrayList arrayList = new ArrayList(); + for(int i=0;i<=10;i++){ + arrayList.add(i); + } + arrayList.remove(1); + arrayList.remove(1); + System.out.println(arrayList); + } + +// @Test + public void testSize() { + ArrayList arrayList = new ArrayList(); + for(int i=0;i<=10;i++){ + arrayList.add(i); + } + System.out.println(arrayList.size()); + } + +} diff --git a/group16/1325756593/src/com/dong/week1/BinaryTreeNode.java b/group16/1325756593/src/com/dong/week1/BinaryTreeNode.java new file mode 100644 index 0000000000..ef41ced8df --- /dev/null +++ b/group16/1325756593/src/com/dong/week1/BinaryTreeNode.java @@ -0,0 +1,39 @@ +package com.dong.week1; + +public class BinaryTreeNode { + private TreeNode node; + + private static class TreeNode{ + private int key=0; + private TreeNode leftChild=null; + private TreeNode rightChild=null; + + public TreeNode(){} + + /** + * @param key ������� + * @param data ������ + */ + public TreeNode(int key){ + this.key=key; + this.leftChild=null; + this.rightChild=null; + } + + + } + + + + public TreeNode insert(TreeNode o){ + if(node == null){ + return o; + } + if(node.key > o.key){ + return insert(o.leftChild); + }else{ + return insert(node.leftChild); + } + } + +} diff --git a/group16/1325756593/src/com/dong/week1/Iterator.java b/group16/1325756593/src/com/dong/week1/Iterator.java new file mode 100644 index 0000000000..9147ab8264 --- /dev/null +++ b/group16/1325756593/src/com/dong/week1/Iterator.java @@ -0,0 +1,7 @@ +package com.dong.week1; + +public interface Iterator { + public boolean hasNext(); + public Object next(); + +} diff --git a/group16/1325756593/src/com/dong/week1/LinkedList.java b/group16/1325756593/src/com/dong/week1/LinkedList.java new file mode 100644 index 0000000000..339b5862ee --- /dev/null +++ b/group16/1325756593/src/com/dong/week1/LinkedList.java @@ -0,0 +1,208 @@ +package com.dong.week1; + +public class LinkedList implements List { + + private int size = 0; + private Node head; + private Node tail; + + + public void add(Object o){ + //����һ��Ԫ�ص��߼��dz��򵥣�ֻ��Ҫ�ж�head�Ƿ�Ϊ�ա���Ϊ�գ�����ֱ�ӼӼ��� + Node node = new Node(o,null); + if(head ==null){ + head =node; + }else{ + tail.next=node; + } + tail=node; + size++; + + } + public void add(int index , Object o){ + if(index < 0){ + throw new ArrayIndexOutOfBoundsException("index����Ϊ����"); + } + if(index > size){ + throw new ArrayIndexOutOfBoundsException("��ǰlist����Ϊ"+size+",��ȡ�����ǣ�"+index); + } + if(size==0){ + head=new Node(o, null); + tail=head; + return; + } + if(index==0){ + Node curNode =head; + Node newNode =new Node(o, curNode); + head=newNode; + return; + } + Node curNode =head; + Object retVal = null; + for(int i=0;i= size){ + throw new ArrayIndexOutOfBoundsException("��ǰlist����Ϊ"+size+",�Ƴ������ǣ�"+index); + } + Node curNode = head; + for(int i=0;i= size){ + throw new ArrayIndexOutOfBoundsException("��ǰlist����Ϊ"+size+",��ȡ�����ǣ�"+index); + } + Object retVal = null; + if(index==0){ + retVal =head.data; + head=head.next; + return retVal; + } + Node curNode =head; + + for(int i=0;iindex; + } + + @Override + public Object next() { + // TODO Auto-generated method stub + if(hasNext()){ + return this.list.get(index++); + } + return null; + } +} + public static void main(String[] args) { + + LinkedList arrayList= new LinkedList(); + + Iterator iterator= arrayList.iterator(); + while(iterator.hasNext()){ + System.out.println(iterator.next()); + } + +} + +} diff --git a/group16/1325756593/src/com/dong/week1/List.java b/group16/1325756593/src/com/dong/week1/List.java new file mode 100644 index 0000000000..adc694241a --- /dev/null +++ b/group16/1325756593/src/com/dong/week1/List.java @@ -0,0 +1,9 @@ +package com.dong.week1; + +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/group16/1325756593/src/com/dong/week1/Queue.java b/group16/1325756593/src/com/dong/week1/Queue.java new file mode 100644 index 0000000000..445390a168 --- /dev/null +++ b/group16/1325756593/src/com/dong/week1/Queue.java @@ -0,0 +1,24 @@ +package com.dong.week1; + +public class Queue { + private ArrayList elementData = new ArrayList(); + + public void enQueue(Object o){ + elementData.add(elementData.size(), o); + } + + public Object deQueue(){ + if(elementData.size()==0){ + throw new IndexOutOfBoundsException("����Ϊ��"); + } + return elementData.remove(0); + } + + public boolean isEmpty(){ + return elementData.size()==0; + } + + public int size(){ + return elementData.size(); + } +} diff --git a/group16/1325756593/src/com/dong/week1/Stack.java b/group16/1325756593/src/com/dong/week1/Stack.java new file mode 100644 index 0000000000..1dea6cdfd9 --- /dev/null +++ b/group16/1325756593/src/com/dong/week1/Stack.java @@ -0,0 +1,31 @@ +package com.dong.week1; + +public class Stack { + private ArrayList elementData = new ArrayList(); + + public void push(Object o){ + elementData.add(o); + } + + + public Object pop(){ + if(elementData.size()==0){ + throw new IndexOutOfBoundsException("ջΪ��"); + } + return elementData.remove(elementData.size()-1); + + } + + public Object peek(){ + if(elementData.size()==0){ + throw new IndexOutOfBoundsException("ջΪ��"); + } + return elementData.get(elementData.size()-1); + } + public boolean isEmpty(){ + return elementData.size()==0; + } + public int size(){ + return elementData.size(); + } +} diff --git a/group16/1924332561/.classpath b/group16/1924332561/.classpath new file mode 100644 index 0000000000..fb5011632c --- /dev/null +++ b/group16/1924332561/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/group16/1924332561/.project b/group16/1924332561/.project new file mode 100644 index 0000000000..5f960262bc --- /dev/null +++ b/group16/1924332561/.project @@ -0,0 +1,17 @@ + + + 1924332561Learning + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/group16/1924332561/.settings/org.eclipse.core.resources.prefs b/group16/1924332561/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000000..99f26c0203 --- /dev/null +++ b/group16/1924332561/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/group16/1924332561/src/com/coding/basic/ArrayList.java b/group16/1924332561/src/com/coding/basic/ArrayList.java new file mode 100644 index 0000000000..3fc0960e08 --- /dev/null +++ b/group16/1924332561/src/com/coding/basic/ArrayList.java @@ -0,0 +1,41 @@ +package com.coding.basic; + +public class ArrayList implements List{ + private int size = 0; + + private Object[] elementDate = new Object[100]; + + + @Override + public void add(Object o) { + + this.elementDate[this.size]=o; + this.size++; + } + + @Override + public void add(int index, Object o) { + + } + + @Override + public Object get(int dex) { + + return null; + } + + @Override + public Object remove(int index) { + return null; + } + + @Override + public int size() { + return -1; + } + + public Iterator iterator(){ + return null; + } + +} diff --git a/group16/1924332561/src/com/coding/basic/BinaryTreeNode.java b/group16/1924332561/src/com/coding/basic/BinaryTreeNode.java new file mode 100644 index 0000000000..e7d9e43e24 --- /dev/null +++ b/group16/1924332561/src/com/coding/basic/BinaryTreeNode.java @@ -0,0 +1,29 @@ +package com.coding.basic; + +public class BinaryTreeNode { + private Object date; + private BinaryTreeNode left; + private BinaryTreeNode right; + public Object getDate() { + return date; + } + public void setDate(Object date) { + this.date = date; + } + 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/group16/1924332561/src/com/coding/basic/Iterator.java b/group16/1924332561/src/com/coding/basic/Iterator.java new file mode 100644 index 0000000000..e7cbd474ec --- /dev/null +++ b/group16/1924332561/src/com/coding/basic/Iterator.java @@ -0,0 +1,6 @@ +package com.coding.basic; + +public interface Iterator { + public boolean hasNext(); + public Object next(); +} diff --git a/group16/1924332561/src/com/coding/basic/LinkedList.java b/group16/1924332561/src/com/coding/basic/LinkedList.java new file mode 100644 index 0000000000..d39557be29 --- /dev/null +++ b/group16/1924332561/src/com/coding/basic/LinkedList.java @@ -0,0 +1,62 @@ +package com.coding.basic; + +public class LinkedList implements List { + + private static class Node{ + Object date; + Node next; + } + + private Node head; + + + @Override + public void add(Object o) { + + } + + @Override + public void add(int index, Object o) { + + } + + @Override + public Object get(int dex) { + return null; + } + + @Override + public Object remove(int index) { + return null; + } + + @Override + public int size() { + + return 0; + } + + 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; + } + +} diff --git a/group16/1924332561/src/com/coding/basic/List.java b/group16/1924332561/src/com/coding/basic/List.java new file mode 100644 index 0000000000..d48b1f4827 --- /dev/null +++ b/group16/1924332561/src/com/coding/basic/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/group16/1924332561/src/com/coding/basic/Queue.java b/group16/1924332561/src/com/coding/basic/Queue.java new file mode 100644 index 0000000000..7dc7b4820a --- /dev/null +++ b/group16/1924332561/src/com/coding/basic/Queue.java @@ -0,0 +1,23 @@ +package com.coding.basic; + +public class Queue { + + public void enQueue(){ + + + } + public Object deQueue(){ + + return null; + } + + public boolean isEmpty(){ + + return false; + } + + public int size(){ + + return -1; + } +} diff --git a/group16/1924332561/src/com/coding/basic/Stack.java b/group16/1924332561/src/com/coding/basic/Stack.java new file mode 100644 index 0000000000..7a49c48279 --- /dev/null +++ b/group16/1924332561/src/com/coding/basic/Stack.java @@ -0,0 +1,29 @@ +package com.coding.basic; + +public class Stack { + private ArrayList elementDate = 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/group16/214074094/readme.txt b/group16/214074094/readme.txt new file mode 100644 index 0000000000..c1b06ddcc2 --- /dev/null +++ b/group16/214074094/readme.txt @@ -0,0 +1 @@ +I am 北京-Shane diff --git a/group16/214074094/src/com/coding/basic/ArrayList.java b/group16/214074094/src/com/coding/basic/ArrayList.java new file mode 100644 index 0000000000..158c866d45 --- /dev/null +++ b/group16/214074094/src/com/coding/basic/ArrayList.java @@ -0,0 +1,165 @@ +package coding.basic; + + +import java.util.Arrays; +import java.util.NoSuchElementException; + +/** + * @Author shane + * @Time 2017/2/25 13:06 + * @Email stevenchenguang@gmail.com + * @Desc OwnArrayList + */ +public class ArrayList implements List { + + private int size = 0; + + private final static Object[] EMPTY_ELEMENTDATA = {}; + + /** + * 默认容量 + */ + private static int DEFAULT_CAPACITY = 10; + + private Object[] elementData; + + public ArrayList() { + this.elementData = EMPTY_ELEMENTDATA; + } + + @Override + public void add(Object o) { + if (elementData == EMPTY_ELEMENTDATA) { + elementData = Arrays.copyOf(elementData, DEFAULT_CAPACITY); + elementData[0] = o; + } else if (size < elementData.length) { + elementData[size] = o; + } else { + _grow(); + elementData[size] = o; + } + size++; + _analyze(); + } + + @Override + public void add(int index, Object o) { + if (index < 0) { + throw new IndexOutOfBoundsException("Index:" + index + ", Size:" + size); + } + if (elementData == EMPTY_ELEMENTDATA) { + if (index != 0) { + throw new IndexOutOfBoundsException("Index:" + index + ", Size:" + size); + } else { + elementData = new Object[DEFAULT_CAPACITY]; + elementData[0] = o; + } + } else if (index > size) { + throw new IndexOutOfBoundsException("Index:" + index + ", Size:" + size); + } else if (index == size) { + _grow(); + elementData[size] = o; + size++; + } else { + if (elementData.length == size) { + _grow(); + } + System.arraycopy(elementData, index, elementData, index + 1, size - index); + elementData[index] = o; + size++; + } + _analyze(); + } + + @Override + public Object get(int index) { + if (index < 0 || index > size) { + throw new IndexOutOfBoundsException("Index:" + index + ", Size:" + size); + } + return elementData[index]; + } + + @Override + public Object remove(int index) { + + if (index < 0 || index > size) { + throw new IndexOutOfBoundsException("Index:" + index + ", Size:" + size); + } + Object oldValue = elementData[index]; + //需要复制的长度 + int needMoveLength = size - index - 1; + //如果该长度小于0, 说明只有一个元素, 直接置空即可 + if (needMoveLength > 0) { + System.arraycopy(elementData, index + 1, elementData, index, needMoveLength); + } + elementData[--size] = null; + _analyze(); + return oldValue; + } + + @Override + public int size() { + return size; + } + + public Iterator iterator() { + return new ArrayListItrator(); + } + + /** + * @Author: shane + * @Time: 2017/2/25 20:18 + * @Email: stevenchenguang@gmail.com + * @param: + * @Return: + * @Throw: + * @Desc: 返回真实长度的数组数据 + */ + private void _analyze() { + if (size < elementData.length) { + elementData = Arrays.copyOf(elementData, size); + } + } + + /** + * @Author: shane + * @Time: 2017/2/25 20:19 + * @Email: stevenchenguang@gmail.com + * @param: + * @Return: + * @Throw: + * @Desc: 将数组的长度扩容至2倍 + */ + private void _grow() { + elementData = Arrays.copyOf(elementData, elementData.length << 1); + } + + @Override + public String toString() { + return Arrays.toString(elementData); + } + + public boolean isEmpty() { + return size == 0; + } + + private class ArrayListItrator implements Iterator { + + private int position = 0; + + @Override + public boolean hasNext() { + return position != size; + } + + @Override + public Object next() { + int i = position; + if (i >= size) { + throw new NoSuchElementException(); + } + position = i + 1; + return elementData[i]; + } + } +} diff --git a/group16/214074094/src/com/coding/basic/BinaryTreeNode.java b/group16/214074094/src/com/coding/basic/BinaryTreeNode.java new file mode 100644 index 0000000000..b40066ebe1 --- /dev/null +++ b/group16/214074094/src/com/coding/basic/BinaryTreeNode.java @@ -0,0 +1,39 @@ +package 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/group16/214074094/src/com/coding/basic/Iterator.java b/group16/214074094/src/com/coding/basic/Iterator.java new file mode 100644 index 0000000000..1acc5349a4 --- /dev/null +++ b/group16/214074094/src/com/coding/basic/Iterator.java @@ -0,0 +1,9 @@ +package coding.basic; + +public interface Iterator { + + boolean hasNext(); + + Object next(); + +} diff --git a/group16/214074094/src/com/coding/basic/LinkedList.java b/group16/214074094/src/com/coding/basic/LinkedList.java new file mode 100644 index 0000000000..9108c2b6fe --- /dev/null +++ b/group16/214074094/src/com/coding/basic/LinkedList.java @@ -0,0 +1,222 @@ +package coding.basic; + +/** + * @Author shane + * @Time 2017/2/25 21:01 + * @Email stevenchenguang@gmail.com + * @Desc OwnLinkedList + */ +public class LinkedList implements List { + + private int size = 0; + + private Node first; + + private Node last; + + public void add(Object o) { + if (size == 0) { + first = new Node(null, o, null); + last = first; + size++; + } else { + addLast(o); + } + } + + public void add(int index, Object o) { + _checkIndex(index); + if (index == size - 1) { + addLast(o); + } else { + Node prev = _node(index); + Node next = _node(index + 1); + Node newNode = new Node(prev, o, next); + prev.next = newNode; + next.prev = newNode; + size++; + } + } + + public Object get(int index) { + _checkIndex(index); + return node(index); + } + + public Object remove(int index) { + _checkIndex(index); + if (index == 0) { + return removeFirst(); + } else if (index == size - 1) { + return removeLast(); + } + Node curr = _node(index); + Object data = curr.data; + final Node prev = curr.prev; + final Node next = curr.next; + + prev.next = next; + next.prev = prev; + curr = null; + size--; + + return data; + } + + private Object removeFirst() { + Node oldFirst = first; + Object data = first.data; + final Node oldSecond = oldFirst.next; + if (null == oldSecond) { + first = null; + last = null; + } else { + oldSecond.prev = null; + first = oldSecond; + oldFirst = null; + } + size--; + return data; + } + + private Object removeLast() { + Node oldLast = last; + Object data = last.data; + final Node oldLastButOne = last.prev; + if (null == oldLastButOne) { + first = null; + last = null; + } else { + oldLastButOne.next = null; + last = oldLastButOne; + oldLast = null; + } + size--; + return data; + } + + public void addFirst(Object o) { + final Node oldFirst = first; + final Node param = new Node(null, o, null); + if (null == oldFirst) { + first = param; + } else { + oldFirst.prev = param; + param.next = oldFirst; + first = param; + } + size++; + } + + public void addLast(Object o) { + final Node n = last; + final Node newNode = new Node(n, o, null); + last = newNode; + n.next = newNode; + size++; + } + + public int size() { + return size; + } + + public Iterator iterator() { + return null; + } + + public boolean isEmpty() { + return size == 0; + } + + private static class Node { + Node prev; + Object data; + Node next; + + public Node(Node prev, Object data, Node next) { + this.prev = prev; + this.data = data; + this.next = next; + } + } + + /** + * @Author: shane + * @Time: 2017/2/25 22:44 + * @Email: stevenchenguang@gmail.com + * @param: int index + * @Return: Node + * @Throw: + * @Desc: 根据下标获取节点元素上的数据 + */ + private Object node(int index) { + //如果下标在左一半, 从左往右取 + if (index < size >> 1) { + Node tmp = first; + for (int i = 0; i < index; i++) { + tmp = tmp.next; + } + return tmp.data; + } else { + Node tmp = last; + for (int i = size - 1; i > index; i--) { + tmp = tmp.prev; + } + return tmp.data; + } + } + + /** + * @Author: shane + * @Time: 2017/2/25 22:44 + * @Email: stevenchenguang@gmail.com + * @param: int index + * @Return: Node + * @Throw: + * @Desc: 根据下标获取节点元素 + */ + private Node _node(int index) { + //如果下标在左一半, 从左往右取 + if (index < size >> 1) { + Node tmp = first; + for (int i = 0; i < index; i++) { + tmp = tmp.next; + } + return tmp; + } else { + Node tmp = last; + for (int i = size - 1; i > index; i--) { + tmp = tmp.prev; + } + return tmp; + } + } + + /** + * @Author: shane + * @Time: 2017/2/25 22:43 + * @Email: stevenchenguang@gmail.com + * @param: int index + * @Return: + * @Throw: IndexOutOfBoundsException + * @Desc: 校验下标是否合法 + */ + private void _checkIndex(int index) { + if (index < 0 || index >= size) { + throw new IndexOutOfBoundsException("Index:" + index + ", Size:" + size); + } + } + + @Override + public String toString() { + if (0 == size) { + return "[]"; + } + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < this.size; i++) { + sb.append(get(i)).append(", "); + } + String tmp = sb.substring(0, sb.length() - 2); + return "[" + tmp + "]"; + } +} \ No newline at end of file diff --git a/group16/214074094/src/com/coding/basic/List.java b/group16/214074094/src/com/coding/basic/List.java new file mode 100644 index 0000000000..5da9b0d4c6 --- /dev/null +++ b/group16/214074094/src/com/coding/basic/List.java @@ -0,0 +1,15 @@ +package coding.basic; + +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/group16/214074094/src/com/coding/basic/Queue.java b/group16/214074094/src/com/coding/basic/Queue.java new file mode 100644 index 0000000000..869d0f7333 --- /dev/null +++ b/group16/214074094/src/com/coding/basic/Queue.java @@ -0,0 +1,36 @@ +package coding.basic; + +/** + * @Author shane + * @Time 2017/2/26 17:19 + * @Email stevenchenguang@gmail.com + * @Desc Own Queue + */ +public class Queue { + + private LinkedList elementData = new LinkedList(); + + public void enQueue(Object o) { + elementData.add(o); + } + + public Object deQueue() { + if (isEmpty()) { + throw new RuntimeException("Queue is empty"); + } + return elementData.remove(0); + } + + public boolean isEmpty() { + return elementData.isEmpty(); + } + + public int size() { + return elementData.size(); + } + + @Override + public String toString() { + return elementData.toString(); + } +} diff --git a/group16/214074094/src/com/coding/basic/Stack.java b/group16/214074094/src/com/coding/basic/Stack.java new file mode 100644 index 0000000000..7ef1c9ad06 --- /dev/null +++ b/group16/214074094/src/com/coding/basic/Stack.java @@ -0,0 +1,37 @@ +package coding.basic; + +/** + * @Author shane + * @Time 2017/2/26 16:55 + * @Email stevenchenguang@gmail.com + * @Desc Own Stack + */ +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.isEmpty(); + } + + public int size() { + return elementData.size(); + } + + @Override + public String toString() { + return elementData.toString(); + } +} diff --git a/group16/214074094/src/com/reading/blog_test.txt b/group16/214074094/src/com/reading/blog_test.txt new file mode 100644 index 0000000000..b7e5cbfe14 --- /dev/null +++ b/group16/214074094/src/com/reading/blog_test.txt @@ -0,0 +1 @@ +just test new fork \ No newline at end of file diff --git a/group16/214074094/src/test/coding/basic/AbstractTest.java b/group16/214074094/src/test/coding/basic/AbstractTest.java new file mode 100644 index 0000000000..80eaaa6fe5 --- /dev/null +++ b/group16/214074094/src/test/coding/basic/AbstractTest.java @@ -0,0 +1,19 @@ +package coding.basic; + +/** + * @Author shane + * @Time 2017/2/25 13:06 + * @Email stevenchenguang@gmail.com + * @Desc 测试基类 + */ +public class AbstractTest { + + protected void printStar() { + System.out.println("********************************************"); + } + + protected void printHyphen() { + System.out.println("--------------------------------------------"); + } + +} diff --git a/group16/214074094/src/test/coding/basic/ArrayListTest.java b/group16/214074094/src/test/coding/basic/ArrayListTest.java new file mode 100644 index 0000000000..2f03342d61 --- /dev/null +++ b/group16/214074094/src/test/coding/basic/ArrayListTest.java @@ -0,0 +1,81 @@ +package coding.basic; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * @Author shane + * @Time 2017/2/25 13:02 + * @Email stevenchenguang@gmail.com + * @Desc ... + */ + +public class ArrayListTest extends AbstractTest { + + private static ArrayList list; + + @Before + public void before() { + + list = new ArrayList(); + list.add("a"); + list.add("b"); + list.add("c"); + list.add("d"); + list.add("e"); + + printStar(); + System.out.println("Before Test data :" + list); + printHyphen(); + } + + @After + public void after() { + printHyphen(); + System.out.println("After Test data : " + list); + printStar(); + } + + @Test + public void testAddI() { + int index = list.size(); + list.add(index, "test add i"); + Assert.assertEquals(list.get(index), "test add i"); + } + + @Test + public void test() { + java.util.ArrayList list = new java.util.ArrayList(); + list.add("a"); + list.add("b"); + java.util.Iterator it = list.iterator(); + while (it.hasNext()) { + + } + System.out.println(it.next()); + System.out.println(it.next()); + System.out.println(it.next()); + } + + @Test + public void testSize() { + Assert.assertEquals(5, list.size()); + } + + @Test + public void testRemove() { + list.remove(5); + Assert.assertEquals(list.get(3), "d"); + } + + @Test + public void testIterator() { + Iterator it = list.iterator(); + while (it.hasNext()) { + System.out.println(it.next()); + } + } + +} diff --git a/group16/214074094/src/test/coding/basic/LinkedListTest.java b/group16/214074094/src/test/coding/basic/LinkedListTest.java new file mode 100644 index 0000000000..bc78728a25 --- /dev/null +++ b/group16/214074094/src/test/coding/basic/LinkedListTest.java @@ -0,0 +1,63 @@ +package coding.basic; + +import junit.framework.Assert; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * @Author shane + * @Time 2017/2/25 23:32 + * @Email stevenchenguang@gmail.com + * @Desc ... + */ +public class LinkedListTest extends AbstractTest { + + private static LinkedList list; + + @Before + public void before() { + list = new LinkedList(); + list.add("a"); + list.add("b"); + list.add("c"); + list.add("d"); + list.add("e"); + + printStar(); + System.out.println("Before Test data :" + list); + printHyphen(); + } + + @After + public void after() { + printHyphen(); + System.out.println("After Test data : " + list); + printStar(); + } + + @Test + public void testAddIndex() { + list.add(0, "after a"); + Assert.assertEquals("after a", list.get(1)); + + list.add(3, "after c"); + Assert.assertEquals("after c", list.get(4)); + + list.add(6, "after e"); + Assert.assertEquals("after e", list.get(7)); + } + + @Test + public void testRemove() { + list.remove(0); + Assert.assertEquals("b", list.get(0)); + + list.remove(list.size() - 1); + Assert.assertEquals("d", list.get(list.size() - 1)); + + Object obj = list.remove(1); + Assert.assertEquals("c", obj); + Assert.assertEquals(2, list.size()); + } +} diff --git a/group16/214074094/src/test/coding/basic/QueueTest.java b/group16/214074094/src/test/coding/basic/QueueTest.java new file mode 100644 index 0000000000..12302783b3 --- /dev/null +++ b/group16/214074094/src/test/coding/basic/QueueTest.java @@ -0,0 +1,62 @@ +package coding.basic; + +import junit.framework.Assert; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * @Author shane + * @Time 2017/2/26 17:24 + * @Email stevenchenguang@gmail.com + * @Desc ... + */ +public class QueueTest extends AbstractTest { + + private static Queue queue; + + @Before + public void before() { + queue = new Queue(); + + queue.enQueue("a"); + queue.enQueue("b"); + queue.enQueue("c"); + queue.enQueue("d"); + queue.enQueue("e"); + + printStar(); + System.out.println("Before Test data :" + queue); + printHyphen(); + } + + @After + public void after() { + printHyphen(); + System.out.println("After Test data : " + queue); + printStar(); + } + + @Test + public void testDeQueueAndIsEmpty() { + Assert.assertEquals("a", queue.deQueue()); + + queue.deQueue(); + queue.deQueue(); + queue.deQueue(); + queue.deQueue(); + + Assert.assertEquals(true, queue.isEmpty()); + + try { + queue.deQueue(); + } catch (RuntimeException e) { + Assert.assertEquals("Queue is empty", e.getMessage()); + } + } + + @Test + public void testSize() { + Assert.assertEquals(5, queue.size()); + } +} diff --git a/group16/214074094/src/test/coding/basic/StackTest.java b/group16/214074094/src/test/coding/basic/StackTest.java new file mode 100644 index 0000000000..f289744a67 --- /dev/null +++ b/group16/214074094/src/test/coding/basic/StackTest.java @@ -0,0 +1,68 @@ +package coding.basic; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * @Author shane + * @Time 2017/2/26 16:58 + * @Email stevenchenguang@gmail.com + * @Desc ... + */ +public class StackTest extends AbstractTest { + + private static Stack stack; + + @Before + public void before() { + stack = new Stack(); + + stack.push("a"); + stack.push("b"); + stack.push("c"); + stack.push("d"); + stack.push("e"); + + printStar(); + System.out.println("Before Test data :" + stack); + printHyphen(); + } + + @After + public void after() { + printHyphen(); + System.out.println("After Test data : " + stack); + printStar(); + } + + @Test + public void testPop() { + Assert.assertEquals("e", stack.pop()); + } + + @Test + public void testPeek() { + Assert.assertEquals("e", stack.peek()); + } + + @Test + public void testIsEmpty() { + Assert.assertEquals(false, stack.isEmpty()); + + stack.pop(); + stack.pop(); + stack.pop(); + stack.pop(); + stack.pop(); + + Assert.assertEquals(true, stack.isEmpty()); + } + + @Test + public void testSize() { + Assert.assertEquals(5, stack.size()); + } + +} diff --git a/group16/214074094/target/production/214074094/reading/blog_test.txt b/group16/214074094/target/production/214074094/reading/blog_test.txt new file mode 100644 index 0000000000..b7e5cbfe14 --- /dev/null +++ b/group16/214074094/target/production/214074094/reading/blog_test.txt @@ -0,0 +1 @@ +just test new fork \ No newline at end of file diff --git a/group16/2562124714/.idea/dictionaries/zhangwj.xml b/group16/2562124714/.idea/dictionaries/zhangwj.xml new file mode 100644 index 0000000000..d07fd80ae1 --- /dev/null +++ b/group16/2562124714/.idea/dictionaries/zhangwj.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/group16/2562124714/.idea/misc.xml b/group16/2562124714/.idea/misc.xml new file mode 100644 index 0000000000..e97ef03f44 --- /dev/null +++ b/group16/2562124714/.idea/misc.xml @@ -0,0 +1,22 @@ + + + + + + + + + + 1.7 + + + + + + + + \ No newline at end of file diff --git a/group16/2562124714/.idea/modules.xml b/group16/2562124714/.idea/modules.xml new file mode 100644 index 0000000000..c3fdba38f0 --- /dev/null +++ b/group16/2562124714/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/group16/2562124714/.idea/workspace.xml b/group16/2562124714/.idea/workspace.xml new file mode 100644 index 0000000000..d357c0f9a1 --- /dev/null +++ b/group16/2562124714/.idea/workspace.xml @@ -0,0 +1,780 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + binaryTree.PriOder + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1487640652721 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/group16/2562124714/2562124714.iml b/group16/2562124714/2562124714.iml new file mode 100644 index 0000000000..3a8ffcf1f5 --- /dev/null +++ b/group16/2562124714/2562124714.iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/group16/2562124714/src/Test/ArrayListTest.java b/group16/2562124714/src/Test/ArrayListTest.java new file mode 100644 index 0000000000..9bd8f2aeca --- /dev/null +++ b/group16/2562124714/src/Test/ArrayListTest.java @@ -0,0 +1,70 @@ +package Test; + +import com.coding.basic.ArrayList; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by zhangwj on 2017/2/23. + */ +public class ArrayListTest { + private static ArrayList arraylist = new ArrayList(); + @BeforeClass + public static void setUp() throws Exception { + + System.out.println("初始化变量"); + for (Integer i = 0; i < 5; i++) + { + arraylist.add(i); + } + + + } + + @After + public void tearDown() throws Exception { + + } + + @Test + public void add() throws Exception { + Integer i = arraylist.size(); + Integer AddElement = 999; + arraylist.add(AddElement); + assertEquals(i + 1, arraylist.size()); + assertEquals(AddElement, arraylist.get(arraylist.size())); + arraylist.remove(arraylist.size()); + } + + @Test + public void add1() throws Exception { + Integer AddElement = 999; + arraylist.add(1, AddElement); + assertEquals(AddElement, arraylist.get(1)); + arraylist.remove(1); + } + + @Test + public void get() throws Exception { + assertEquals(null, arraylist.get(9999)); + } + + @Test + public void remove() throws Exception { + Integer i = (Integer)arraylist.get(1); + assertEquals(i, arraylist.remove(1)); + arraylist.add(1, i); + + } + + @Test + public void size() throws Exception { + assertEquals(5, arraylist.size()); + + } + +} \ No newline at end of file diff --git a/group16/2562124714/src/Test/BinaryTreeNodeTest.java b/group16/2562124714/src/Test/BinaryTreeNodeTest.java new file mode 100644 index 0000000000..7d8f4fdd01 --- /dev/null +++ b/group16/2562124714/src/Test/BinaryTreeNodeTest.java @@ -0,0 +1,100 @@ +package Test; + +import com.coding.basic.BinaryTreeNode; +import com.coding.basic.TreeData; +import com.sun.org.apache.bcel.internal.generic.NEW; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by zhangwj on 2017/2/23. + */ +public class BinaryTreeNodeTest { + private BinaryTreeNode binaryTree = new BinaryTreeNode(); + @Before + public void setUp() throws Exception { + //System.out.println("初始化二叉树,5, 4, 7"); + TreeData element = new TreeData(); + element.setT((Integer)5); + binaryTree.insert(element); + TreeData element2 = new TreeData(); + element2.setT((Integer)4); + binaryTree.insert(element2); + TreeData element3 = new TreeData(); + element3.setT((Integer)7); + binaryTree.insert(element3); +// binaryTree.PriOder(this.binaryTree); + } + + @Test + public void getData() throws Exception { + assertEquals(5, binaryTree.getData().getT()); + + } + + @Test + public void setData() throws Exception { + TreeData element = new TreeData(); + element.setT(6); + binaryTree.setData(element); + assertEquals(6, binaryTree.getData().getT()); +// binaryTree.PriOder(this.binaryTree); + + } + + @Test + public void getLeft() throws Exception { + assertEquals(4, binaryTree.getLeft().getData().getT()); + + } + + @Test + public void setLeft() throws Exception { + TreeData element = new TreeData(); + element.setT(2); + BinaryTreeNode NewTreeNode = new BinaryTreeNode(); + NewTreeNode.setData(element); + binaryTree.setLeft(NewTreeNode); + assertEquals(2, binaryTree.getLeft().getData().getT()); +// binaryTree.PriOder(this.binaryTree); + } + + @Test + public void getRight() throws Exception { + assertEquals(7, binaryTree.getRight().getData().getT()); + + } + + @Test + public void setRight() throws Exception { + TreeData element = new TreeData(); + element.setT(9); + BinaryTreeNode NewTreeNode = new BinaryTreeNode(); + NewTreeNode.setData(element); + binaryTree.setRight(NewTreeNode); + assertEquals(9, binaryTree.getRight().getData().getT()); + } + + @Test + public void priOder() throws Exception { + + + } + + @Test + public void insert() throws Exception { + TreeData element = new TreeData(); + element.setT(2); + binaryTree.insert(element); + binaryTree.PriOder(this.binaryTree); + element.setT(9); + binaryTree.insert(element); + binaryTree.PriOder(this.binaryTree); + element.setT(8); +// binaryTree.PriOder(this.binaryTree); + + } + +} \ No newline at end of file diff --git a/group16/2562124714/src/Test/LinkedListTest.java b/group16/2562124714/src/Test/LinkedListTest.java new file mode 100644 index 0000000000..276b389f15 --- /dev/null +++ b/group16/2562124714/src/Test/LinkedListTest.java @@ -0,0 +1,81 @@ +package Test; + +import com.coding.basic.LinkedList; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by zhangwj on 2017/2/23. + */ +public class LinkedListTest { + private LinkedList linkedlist = new LinkedList(); + + @Before + public void Init() + { + System.out.println("初始化"); + linkedlist.add(9.9); + linkedlist.add(9.99); + } + + + @Test + public void add() throws Exception { + linkedlist.add(8.8); + assertEquals(3, linkedlist.size()); + System.out.println("after add size is " + linkedlist.size()); + System.out.println("after add last element is " + linkedlist.get(linkedlist.size())); + + } + + @Test + public void add1() throws Exception { + linkedlist.add(2, 7.7); + assertEquals(3, linkedlist.size()); + System.out.println("after add in 2th size is " + linkedlist.size()); + System.out.println("after add 2th element is " + linkedlist.get(2)); + } + + @Test + public void get() throws Exception { + assertEquals(9.9, linkedlist.get(1)); + } + + @Test + public void remove() throws Exception { + assertEquals(9.9, linkedlist.remove(1)); + } + + @Test + public void size() throws Exception { + assertEquals(2, linkedlist.size()); + + } + + @Test + public void addFirst() throws Exception { + linkedlist.addFirst(3.3); + assertEquals(3.3, linkedlist.get(1)); +// System.out.println(); + } + + @Test + public void addLast() throws Exception { + linkedlist.addLast(3.3); + assertEquals(3.3, linkedlist.get(linkedlist.size())); + + } + + @Test + public void removeFirst() throws Exception { + assertEquals(9.9, linkedlist.removeFirst()); + } + + @Test + public void removeLast() throws Exception { + assertEquals(9.99, linkedlist.removeLast()); + } + +} \ No newline at end of file diff --git a/group16/2562124714/src/Test/QueueTest.java b/group16/2562124714/src/Test/QueueTest.java new file mode 100644 index 0000000000..3f0557f262 --- /dev/null +++ b/group16/2562124714/src/Test/QueueTest.java @@ -0,0 +1,58 @@ +package Test; + +import com.coding.basic.Queue; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by zhangwj on 2017/2/23. + */ +public class QueueTest { + private Queue queue = new Queue(); + @Before + public void setUp() throws Exception { + System.out.println("初始化队列,元素为a,b,c,d"); + + String[] s = {"a", "b","c","d"}; + for (String a:s + ) { + queue.enQueue(a); + } + + } + + @After + public void tearDown() throws Exception { + + } + + @Test + public void enQueue() throws Exception { + queue.enQueue("dasdas"); + assertEquals(5, queue.size()); +// assertEquals("dasdas", queue.); + } + + @Test + public void deQueue() throws Exception { + assertEquals("a",queue.deQueue()); + assertEquals(3, queue.size()); + + } + + @Test + public void isEmpty() throws Exception { + assertEquals(false, queue.isEmpty()); + + } + + @Test + public void size() throws Exception { + assertEquals(4, queue.size()); + + } + +} \ No newline at end of file diff --git a/group16/2562124714/src/Test/StackTest.java b/group16/2562124714/src/Test/StackTest.java new file mode 100644 index 0000000000..0a36d4dc0f --- /dev/null +++ b/group16/2562124714/src/Test/StackTest.java @@ -0,0 +1,57 @@ +package Test; + +import com.coding.basic.Stack; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Created by zhangwj on 2017/2/23. + */ +public class StackTest { + private Stack stack = new Stack(); + @Before + public void setUp() throws Exception { + System.out.println("初始化栈,元素为a,b,c,d"); + + String[] s = {"a", "b","c","d"}; + for (String a:s + ) { + stack.push(a); + } + + } + + @Test + public void push() throws Exception { + stack.push("aaa"); + assertEquals(5, stack.size()); + assertEquals("aaa", stack.peek()); + + } + + @Test + public void pop() throws Exception { + assertEquals("d", stack.pop()); + assertEquals(3, stack.size()); + + } + + @Test + public void peek() throws Exception { + assertEquals("d", stack.peek()); + assertEquals(4, stack.size()); + } + + @Test + public void isEmpty() throws Exception { + assertEquals(false, stack.isEmpty()); + } + + @Test + public void size() throws Exception { + assertEquals(4, stack.size()); + } + +} \ No newline at end of file diff --git a/group16/2562124714/src/Test/TestRunner.java b/group16/2562124714/src/Test/TestRunner.java new file mode 100644 index 0000000000..2bf465f832 --- /dev/null +++ b/group16/2562124714/src/Test/TestRunner.java @@ -0,0 +1,19 @@ +package Test; + +import org.junit.runner.JUnitCore; +import org.junit.runner.notification.Failure; + +import javax.xml.transform.Result; + +/** + * Created by zhangwj on 2017/2/23. 调用测试类 可重复使用 + */ +public class TestRunner { + public static void main(String[] args) { + org.junit.runner.Result result = JUnitCore.runClasses(BinaryTreeNodeTest.class); + for (Failure failure:result.getFailures()) { + System.out.println(failure.toString()); + } + System.out.println(result.wasSuccessful()); + } +} diff --git a/group16/2562124714/src/com/coding/basic/ArrayList.java b/group16/2562124714/src/com/coding/basic/ArrayList.java new file mode 100644 index 0000000000..f1d5a9fdd9 --- /dev/null +++ b/group16/2562124714/src/com/coding/basic/ArrayList.java @@ -0,0 +1,100 @@ +package com.coding.basic; + +public class ArrayList implements List { + + private int size = 0; + + private int Scale; //每次扩展大小 + + private Object[] elementData = new Object[100]; + + public ArrayList() + { + this.Scale = 10; + } + + public ArrayList(int i) + { + this.Scale = i; + } + + public void add(Object o){ + if (this.size == elementData.length) + { + DoEnlage(); + } + elementData[size] = o; + this.size++; + } + + private void DoEnlage() + { + if (this.Scale >= 1 && this.Scale <= 10000) + { + Object[] NewElementData = new Object[this.elementData.length + this.Scale]; + System.arraycopy(this.elementData,0,NewElementData,0,this.elementData.length); + + this.elementData = NewElementData; + } + + } + + //index从1开始 位置1,2,3,4,5,6 + public void add(int index, Object o){ + if (this.size == elementData.length) + { + DoEnlage(); + } + int i = 0; + //遍历赋值 + for(i = this.size; i >= index;i--) + { + this.elementData[i] = this.elementData[i - 1]; + } + + this.elementData[i] = o; + this.size++; + + } + + public Object get(int index){ + if (index >= 1 && index <= this.size) + { + return this.elementData[index - 1]; + } + else { + return null; + } + + + } + + public Object remove(int index){ + if (index >= 1 && index <= this.size) + { + int i = 0; + Object DelElement = this.elementData[index - 1]; + for(i = index; i <= this.size; i++) + { + this.elementData[i - 1] = this.elementData[i]; + } + this.elementData[i] = null; + this.size--; + + return DelElement; + + } + else { + return null; + } + } + + public int size(){ + return this.size; + } + + public Iterator iterator(){ + return null; + } + +} diff --git a/group16/2562124714/src/com/coding/basic/BinaryTreeNode.java b/group16/2562124714/src/com/coding/basic/BinaryTreeNode.java new file mode 100644 index 0000000000..a703ad3165 --- /dev/null +++ b/group16/2562124714/src/com/coding/basic/BinaryTreeNode.java @@ -0,0 +1,94 @@ +package com.coding.basic; + +import java.util.Properties; + +public class BinaryTreeNode { + + private TreeData treeData; + //private Object data; + private BinaryTreeNode left; + private BinaryTreeNode right; + + public TreeData getData() { + return treeData; + } + public void setData(TreeData data) { + this.treeData = 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 void PriOder(BinaryTreeNode Node) + { + if (Node.treeData != null) + { + System.out.println(Node.treeData.getT()); + if (Node.left != null) + { + PriOder(Node.left); + } + if (Node.right != null) + { + PriOder(Node.right); + } + } + + } + + + public BinaryTreeNode insert(TreeData o){ + if (this.treeData == null && this.left == null && this.right == null) + { + this.treeData = o; + this.left = null; + this.right = null; + return null; + } + + //遍历寻找元素应该插入的位置 + if (o.compareTo(this.treeData) <= 0) + { + if (this.left != null) + { + this.left.insert(o); + } + else + { + BinaryTreeNode NewNode = new BinaryTreeNode(); + NewNode.setData(o); + NewNode.setLeft(null); + NewNode.setRight(null); + this.left = NewNode; + } + } + else + { + if (this.right != null) + { + this.right.insert(o); + } + else + { + BinaryTreeNode NewNode = new BinaryTreeNode(); + NewNode.setData(o); + NewNode.setLeft(null); + NewNode.setRight(null); + this.right = NewNode; + } + } + + + return null; + } + +} diff --git a/group16/2562124714/src/com/coding/basic/Iterator.java b/group16/2562124714/src/com/coding/basic/Iterator.java new file mode 100644 index 0000000000..06ef6311b2 --- /dev/null +++ b/group16/2562124714/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/group16/2562124714/src/com/coding/basic/LinkedList.java b/group16/2562124714/src/com/coding/basic/LinkedList.java new file mode 100644 index 0000000000..f1de0a6839 --- /dev/null +++ b/group16/2562124714/src/com/coding/basic/LinkedList.java @@ -0,0 +1,200 @@ +package com.coding.basic; + +import com.sun.org.apache.bcel.internal.generic.NEW; + +import java.awt.*; + +public class LinkedList implements List { + public LinkedList() + { + head = null; + this.Size = 0; + } + + private Node head; + private int Size; + + public void add(Object o){ + Node NewNode = new Node(o); + + if (this.head == null) + { + head = NewNode; + } + else + { + Node node; + for (node = head; node.next != null; node = node.next) + { + } + node.next = NewNode; + } + this.Size++; + + } + //index为位置1,2,3,4,5,6,7 + public void add(int index , Object o){ + Node NewNode = new Node(o); + + if (1 == index) + { + NewNode.next = head; + head = NewNode; + } + else { + Node node; + int i = 0; + for (i = 1, node = head; i < index - 1; i++, node = node.next) { + } + NewNode.next = node.next; + node.next = NewNode; + } + this.Size++; + + } + public Object get(int index){ + Node node; + int i = 0; + + for (i = 1, node = head; i < index ; i++, node = node.next) { + } + + return node.data; +// return null; + } + public Object remove(int index){ + Node node; + int i = 0; + + if (1 == index) + { + if (head.next == null) + { + Object DelData = head.data; + head = null; + this.Size--; + return DelData; + } + else + { + Node DelNode = head; + head = DelNode.next; + DelNode.next = null; + this.Size--; + return DelNode.data; + + } + } + else { + + for (i = 1, node = head; i < index - 1; i++, node = node.next) { + } + Node DelNode = node.next; + node.next = DelNode.next; + DelNode.next = null; + this.Size--; + return DelNode.data; + } + } + + public int size(){ + + return this.Size; + } + + public void addFirst(Object o){ + Node NewNode = new Node(o); + + if (null == this.head) + { + NewNode.next = null; + head = NewNode; + } + else + { + NewNode.next = head; + head = NewNode; + } + + this.Size++; + + } + public void addLast(Object o){ + Node NewNode = new Node(o); + + if (this.Size == 0) + { + NewNode.next = null; + head = NewNode; + } + else + { +// int i = 0; + Node node; + for (node = head; node.next != null; node = node.next) { + + } + node.next = NewNode; + } + + this.Size++; + + } + public Object removeFirst(){ + Node DelFirst; + + if (1 == this.Size) + { + DelFirst = this.head; + DelFirst.next = null; + head = null; + } + else + { + DelFirst = this.head; + head = head.next; + DelFirst.next = null; + } + this.Size--; + + return DelFirst.data; + } + public Object removeLast(){ + Node DelLast; + + if (1 == this.Size) + { + DelLast = head; + DelLast.next = null; + head = null; + } + else + { + Node node; + for (node = head; node.next.next != null; node = node.next) { + + } + DelLast = node.next; + node.next = null; + } + this.Size--; + + return DelLast.data; + } + public Iterator iterator(){ + return null; + } + + + private static class Node{ + Object data; + Node next; + + public Node(Object o) + { + this.data = o; + this.next = null; + } + + } +} diff --git a/group16/2562124714/src/com/coding/basic/List.java b/group16/2562124714/src/com/coding/basic/List.java new file mode 100644 index 0000000000..10d13b5832 --- /dev/null +++ b/group16/2562124714/src/com/coding/basic/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/group16/2562124714/src/com/coding/basic/Queue.java b/group16/2562124714/src/com/coding/basic/Queue.java new file mode 100644 index 0000000000..40b8f22607 --- /dev/null +++ b/group16/2562124714/src/com/coding/basic/Queue.java @@ -0,0 +1,24 @@ +package com.coding.basic; + +public class Queue { + private ArrayList elementData = new ArrayList(); + + public void enQueue(Object o){ + elementData.add(o); + } + + public Object deQueue(){ + + + return elementData.get(1); + } + + public boolean isEmpty(){ + + return elementData.size() == 0 ? true : false; + } + + public int size(){ + return elementData.size(); + } +} diff --git a/group16/2562124714/src/com/coding/basic/Stack.java b/group16/2562124714/src/com/coding/basic/Stack.java new file mode 100644 index 0000000000..9dba3befa5 --- /dev/null +++ b/group16/2562124714/src/com/coding/basic/Stack.java @@ -0,0 +1,34 @@ +package com.coding.basic; + +public class Stack { + private ArrayList elementData = new ArrayList(); + +// public Stack() +// { +// elementData +// } + + public void push(Object o){ + elementData.add(o); + } + + public Object pop(){ + Object o = elementData.remove(elementData.size()); + return o; + } + + public Object peek(){ + Object o = elementData.get(elementData.size()); + return o; + } + public boolean isEmpty(){ + if (elementData.size() == 0) + { + return true; + } + return false; + } + public int size(){ + return elementData.size(); + } +} diff --git a/group16/2562124714/src/com/coding/basic/TestJunit.java b/group16/2562124714/src/com/coding/basic/TestJunit.java new file mode 100644 index 0000000000..59ef43a992 --- /dev/null +++ b/group16/2562124714/src/com/coding/basic/TestJunit.java @@ -0,0 +1,17 @@ +package com.coding.basic; +import org.junit.Test; +import static org.junit.Assert.assertEquals; + +/** + * Created by zhangwj on 2017/2/23. + */ +public class TestJunit { + @Test + + public void testAdd() + { + String str = "Junit is working fine"; + assertEquals("Junit is working fine", str); + } + +} diff --git a/group16/2562124714/src/com/coding/basic/TestRunner.java b/group16/2562124714/src/com/coding/basic/TestRunner.java new file mode 100644 index 0000000000..625ace52c6 --- /dev/null +++ b/group16/2562124714/src/com/coding/basic/TestRunner.java @@ -0,0 +1,25 @@ +package com.coding.basic; + +import com.sun.net.httpserver.Authenticator; +import org.junit.runner.JUnitCore; +import org.junit.runner.notification.Failure; +import org.junit.runners.model.TestClass; + +import javax.xml.transform.Result; + +/** + * Created by zhangwj on 2017/2/23. + */ +public class TestRunner { + public static void main(String[] args) + { + org.junit.runner.Result result = JUnitCore.runClasses(TestJunit.class); + + for (Failure failure : result.getFailures()) + { + System.out.println(failure.toString()); + } + + System.out.println(result.wasSuccessful()); + } +} diff --git a/group16/2562124714/src/com/coding/basic/TreeData.java b/group16/2562124714/src/com/coding/basic/TreeData.java new file mode 100644 index 0000000000..e79b7bd450 --- /dev/null +++ b/group16/2562124714/src/com/coding/basic/TreeData.java @@ -0,0 +1,28 @@ +package com.coding.basic; + +/** + * Created by zhangwj on 2017/2/22. + */ +public class TreeData> implements Comparable>{ + private int s; + private T t; + + public T getT() + { + return t; + } + + public void setT(T o) { t = o;} + + @Override + public int compareTo(TreeData o) { + return getT().compareTo(o.getT()); + } + +// public int compareTo(TreeData o) +// { +// +// } + + +} diff --git a/group16/313001956/.classpath b/group16/313001956/.classpath new file mode 100644 index 0000000000..b42037dde2 --- /dev/null +++ b/group16/313001956/.classpath @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/group16/313001956/.gitignore b/group16/313001956/.gitignore new file mode 100644 index 0000000000..84c048a73c --- /dev/null +++ b/group16/313001956/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/group16/313001956/.project b/group16/313001956/.project new file mode 100644 index 0000000000..16d7526efa --- /dev/null +++ b/group16/313001956/.project @@ -0,0 +1,36 @@ + + + assignment + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/group16/313001956/.settings/.jsdtscope b/group16/313001956/.settings/.jsdtscope new file mode 100644 index 0000000000..92e666d77d --- /dev/null +++ b/group16/313001956/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/group16/313001956/.settings/org.eclipse.jdt.core.prefs b/group16/313001956/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..c537b63063 --- /dev/null +++ b/group16/313001956/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/group16/313001956/.settings/org.eclipse.wst.common.component b/group16/313001956/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000000..2a267dc19d --- /dev/null +++ b/group16/313001956/.settings/org.eclipse.wst.common.component @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/group16/313001956/.settings/org.eclipse.wst.common.project.facet.core.xml b/group16/313001956/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000000..611d2dfa73 --- /dev/null +++ b/group16/313001956/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/group16/313001956/.settings/org.eclipse.wst.jsdt.ui.superType.container b/group16/313001956/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000000..3bd5d0a480 --- /dev/null +++ b/group16/313001956/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/group16/313001956/.settings/org.eclipse.wst.jsdt.ui.superType.name b/group16/313001956/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000000..05bd71b6ec --- /dev/null +++ b/group16/313001956/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/group16/313001956/WebContent/META-INF/MANIFEST.MF b/group16/313001956/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..254272e1c0 --- /dev/null +++ b/group16/313001956/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/group16/313001956/src/com/coding/basic/ArrayList.java b/group16/313001956/src/com/coding/basic/ArrayList.java new file mode 100644 index 0000000000..eaaa690fa6 Binary files /dev/null and b/group16/313001956/src/com/coding/basic/ArrayList.java differ diff --git a/group16/502059278/.classpath b/group16/502059278/.classpath new file mode 100644 index 0000000000..fb5011632c --- /dev/null +++ b/group16/502059278/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/group16/502059278/.gitignore b/group16/502059278/.gitignore new file mode 100644 index 0000000000..ae3c172604 --- /dev/null +++ b/group16/502059278/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/group16/502059278/.project b/group16/502059278/.project new file mode 100644 index 0000000000..72a951f7c1 --- /dev/null +++ b/group16/502059278/.project @@ -0,0 +1,17 @@ + + + DataStructure + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git "a/group16/502059278/homework/\350\256\241\347\256\227\346\234\272\346\274\253\350\260\210_\344\275\234\344\270\232.docx" "b/group16/502059278/homework/\350\256\241\347\256\227\346\234\272\346\274\253\350\260\210_\344\275\234\344\270\232.docx" new file mode 100644 index 0000000000..31dfe4c14b Binary files /dev/null and "b/group16/502059278/homework/\350\256\241\347\256\227\346\234\272\346\274\253\350\260\210_\344\275\234\344\270\232.docx" differ diff --git a/group16/502059278/src/cn/mark/MyArrayList.java b/group16/502059278/src/cn/mark/MyArrayList.java new file mode 100644 index 0000000000..9e0e406274 --- /dev/null +++ b/group16/502059278/src/cn/mark/MyArrayList.java @@ -0,0 +1,144 @@ +package cn.mark; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * 自定义实现ArrayList的数据结构 + * @author hilih + * + */ +public class MyArrayList implements MyList{ + + private int size = 0; + + private Object[] elementData; + + public MyArrayList(){ + //默认容量初始化为10 + this(10); + } + + /** + * 初始即指定大小的构造方法 + * @param size 集合容量 + */ + public MyArrayList(int size){ + if ( size < 0 ){ + System.out.println("不合法的容量输入"); + return; + } + elementData = new Object[size]; + } + + /** + * 集合增容 + * @param minSize + */ + private void ensureSize(int minSize){ + int oldSize = elementData.length; + if(minSize > oldSize){ + int newSize = 3 * oldSize / 2 + 1; + if(minSize > newSize){ + newSize = minSize; + } + elementData = Arrays.copyOf(elementData, newSize); + } + } + + /** + * 下标范围判断 + * @param index + */ + private boolean rangeCheck(int index){ + if ( index >= size || index < 0 ){ + System.out.println("索引不合法!"); + return false; + } + return true; + } + + @Override + public boolean add(Object o) { + ensureSize(size+1); + elementData[size++] = o; + return true; + } + + @Override + public boolean add(int index, Object o) { + if (!rangeCheck(index)){ + return false; + } + ensureSize(size + 1); + System.arraycopy(elementData, index, elementData, index + 1, size - index); + elementData[index] = o; + size++; + return true; + } + + @Override + public Object get(int index) { + if (!rangeCheck(index)){ + return null; + } + Object o = elementData[index]; + return o; + } + + @Override + public Object remove(int index) { + if (!rangeCheck(index)){ + return null; + } + Object oldValue = elementData[index]; + int numMoved = size - index - 1; + if( numMoved > 0 ){ + System.arraycopy(elementData, index + 1, elementData, index, numMoved); + } + return oldValue; + } + + @Override + public int size() { + return size; + } + + + + @Override + public String toString() { + StringBuilder s = new StringBuilder(); + s.append("["); + for (int i = 0; i < size; i++){ + Object o = elementData[i]; + s.append(o.toString()); + if( i < size-1 ){ + s.append(","); + } + } + s.append("]"); + return s.toString(); + } + + /** + * 判断当前集合是否为空 + * @return + */ + public boolean isEmpty(){ + return size == 0; + } + + public static void main(String[] args) { + MyList list = new MyArrayList(); + list.add("a"); + list.add("b"); + list.add("c"); + list.add(2,"d"); + Object o = list.get(5); + System.out.println(o); + System.out.println(list.size()); + System.out.println(list); + } +} diff --git a/group16/502059278/src/cn/mark/MyLinkedList.java b/group16/502059278/src/cn/mark/MyLinkedList.java new file mode 100644 index 0000000000..7f9c3856a2 --- /dev/null +++ b/group16/502059278/src/cn/mark/MyLinkedList.java @@ -0,0 +1,67 @@ +package cn.mark; +/** + * 自定义实现LinkedList数据结构 + * @author hilih + * + */ +public class MyLinkedList implements MyList{ + + private Node head; + private int size;//集合的长度 + + /** + * 添加元素 + */ + @Override + public boolean add(Object o) { + //为空判断 + if ( o == null ){ + System.out.println("不允许null的元素插入!"); + return false; + } + if(head == null){ + head = new Node(); + head.data = o; + }else{ + + } + + return false; + } + + @Override + public boolean add(int index, Object o) { + // TODO Auto-generated method stub + return false; + } + + @Override + public Object get(int index) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Object remove(int index) { + // TODO Auto-generated method stub + return null; + } + + @Override + public int size() { + // TODO Auto-generated method stub + return 0; + } + + private static class Node{ + Object data; + Node next; + } + + + public static void main(String[] args) { + + + } + +} diff --git a/group16/502059278/src/cn/mark/MyList.java b/group16/502059278/src/cn/mark/MyList.java new file mode 100644 index 0000000000..19bc3f92fe --- /dev/null +++ b/group16/502059278/src/cn/mark/MyList.java @@ -0,0 +1,32 @@ +package cn.mark; + +public interface MyList { + /** + * 向集合中增加元素 + * @param o + */ + public boolean add(Object o); + /** + * 向集合指定的位置中增加元素 + * @param index 下标 + * @param o 元素 + */ + public boolean add(int index, Object o); + /** + * 从集合指定位置取出元素 + * @param index 下标 + * @return + */ + public Object get(int index); + /** + * 从集合中删除指定位置的元素 + * @param index 下标 + * @return + */ + public Object remove(int index); + /** + * 当前集合的元素个数 + * @return + */ + public int size(); +} \ No newline at end of file diff --git a/group16/542087872/src/com/coding/basic/ArrayList.java b/group16/542087872/src/com/coding/basic/ArrayList.java new file mode 100644 index 0000000000..1b10b441cf --- /dev/null +++ b/group16/542087872/src/com/coding/basic/ArrayList.java @@ -0,0 +1,88 @@ +package com.coding.basic; + +import java.util.Arrays; + +public class ArrayList implements List { + + private int size = 0; + + private Object[] elementData = new Object[10]; + + // 每次乘2增长 + private void grow() { + elementData = Arrays.copyOf(elementData, elementData.length * 2); + } + + + public void add(Object o){ + if (size >= elementData.length) { + this.grow(); + } + + elementData[size++] = o; + } + public void add(int index, Object o){ + if (size >= elementData.length) { + this.grow(); + } + System.arraycopy(elementData, index, elementData, index + 1, size - index); + + elementData[index] = o; + size++; + } + + public Object get(int index){ + if (index >= size) { + throw new IndexOutOfBoundsException(); + } + return elementData[index]; + } + + public Object remove(int index){ + if (index >= size) { + throw new IndexOutOfBoundsException(); + } + + Object el = elementData[index]; + System.arraycopy(elementData, index + 1, elementData, index, size - index - 1); + + size--; + return el; + } + + public int size(){ + return size; + } + + private class ArrIter implements Iterator { + int cursor = 0; + + @Override + public boolean hasNext() { + return cursor < size; + } + + @Override + public Object next() { + return elementData[cursor++]; + } + } + + public Iterator iterator(){ + return new ArrIter(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("["); + for (int i = 0; i < size; i++) { + sb.append(elementData[i]); + if (i < size - 1) { + sb.append(","); + } + } + sb.append("]"); + return sb.toString(); + } +} diff --git a/group16/542087872/src/com/coding/basic/BinaryTreeNode.java b/group16/542087872/src/com/coding/basic/BinaryTreeNode.java new file mode 100644 index 0000000000..df167343a0 --- /dev/null +++ b/group16/542087872/src/com/coding/basic/BinaryTreeNode.java @@ -0,0 +1,62 @@ +package com.coding.basic; + +public class BinaryTreeNode { + + private int data; + private BinaryTreeNode left; + private BinaryTreeNode right; + + public int getData() { + return data; + } + public void setData(int 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(int data) { + this.data = data; + } + + private BinaryTreeNode insertAt(BinaryTreeNode node, int o) { + if (o < node.getData()) { + if (node.getLeft() != null) { + return insertAt(node.getLeft(), o); + } else { + BinaryTreeNode nowNode = new BinaryTreeNode(o); + node.setLeft(nowNode); + + return nowNode; + } + } else { + if (node.getRight() != null) { + return insertAt(node.getRight(), o); + } else { + BinaryTreeNode nowNode = new BinaryTreeNode(o); + node.setRight(nowNode); + return nowNode; + } + } + } + + public BinaryTreeNode insert(int o){ + return insertAt(this, o); + } + + @Override + public String toString() { + return "data: " + data; + } +} diff --git a/group16/542087872/src/com/coding/basic/Iterator.java b/group16/542087872/src/com/coding/basic/Iterator.java new file mode 100644 index 0000000000..06ef6311b2 --- /dev/null +++ b/group16/542087872/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/group16/542087872/src/com/coding/basic/LinkedList.java b/group16/542087872/src/com/coding/basic/LinkedList.java new file mode 100644 index 0000000000..144af4ec8d --- /dev/null +++ b/group16/542087872/src/com/coding/basic/LinkedList.java @@ -0,0 +1,192 @@ +package com.coding.basic; + +public class LinkedList implements List { + + private Node head; + private Node tail; + + public void add(Object o){ + Node nowNode = new Node(o); + if (head == null) { + head = nowNode; + } else { + tail.next = nowNode; + } + tail = nowNode; + } + public void add(int index , Object o){ + int count = 0; + Node lastOne = null; + Node tpHead = head; + while (tpHead != null && count != index) { + count++; + lastOne = tpHead; + tpHead = tpHead.next; + } + if (count != index) { + throw new IndexOutOfBoundsException(); + } + + + Node nowNode = new Node(o); + if (lastOne == null) { + head = nowNode; + head.next = tpHead; + } else { + lastOne.next = nowNode; + nowNode.next = tpHead; + } + } + public Object get(int index){ + int count = 0; + Node tpHead = head; + while (tpHead != null && count != index) { + count++; + tpHead = tpHead.next; + } + if (count != index) { + throw new IndexOutOfBoundsException(); + } + + return tpHead.data; + } + public Object remove(int index){ + int count = 0; + Node lastOne = null; + Node tpHead = head; + while (tpHead != null && count != index) { + count++; + lastOne = tpHead; + tpHead = tpHead.next; + } + if (count != index) { + throw new IndexOutOfBoundsException(); + } + + if (lastOne == null) { + head = tpHead.next; + } else { + lastOne.next = tpHead.next; + } + + if (tpHead.next == null) { + tail = lastOne; + } + + return tpHead.data; + } + + public int size(){ + int count = 0; + Node tpHead = head; + while (tpHead != null) { + count ++; + tpHead = tpHead.next; + } + + return count; + } + + public void addFirst(Object o){ + Node nowNode = new Node(o); + if (head == null) { + head = nowNode; + tail = nowNode; + } else { + nowNode.next = head; + head = nowNode; + } + } + public void addLast(Object o){ + Node nowNode = new Node(o); + if (head == null) { + head = nowNode; + tail = nowNode; + } else { + tail.next = nowNode; + tail = nowNode; + } + } + public Object removeFirst(){ + if (head == null) { + throw new IndexOutOfBoundsException(); + } + + Node nowValue = head; + + Node nextNode = head.next; + if (nextNode == null) { + tail = null; + } + head = nextNode; + + return nowValue.data; + } + public Object removeLast(){ + if (head == null) { + throw new IndexOutOfBoundsException(); + } + + Node nowValue = tail; + + Node lastOne = null; + Node tpHead = head; + while (tpHead != tail) { + lastOne = tpHead; + tpHead = tpHead.next; + } + if (lastOne == null) { + head = null; + } else { + lastOne.next = null; + } + tail = lastOne; + + return nowValue.data; + } + + private class LinkIter implements Iterator { + + Node cursor = head; + + @Override + public boolean hasNext() { + return cursor != null; + } + + @Override + public Object next() { + Node ret = cursor; + cursor = cursor.next; + return ret.data; + } + } + + public Iterator iterator(){ + return new LinkIter(); + } + + + private static class Node{ + Object data; + Node next; + + public Node(Object data) { + this.data = data; + } + } + + @Override + public String toString() { + Node tpHead = head; + StringBuilder sb = new StringBuilder("["); + while (tpHead != null) { + sb.append(tpHead.data); + sb.append(","); + tpHead = tpHead.next; + } + sb.append("]"); + return sb.toString(); + } + +} diff --git a/group16/542087872/src/com/coding/basic/List.java b/group16/542087872/src/com/coding/basic/List.java new file mode 100644 index 0000000000..10d13b5832 --- /dev/null +++ b/group16/542087872/src/com/coding/basic/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/group16/542087872/src/com/coding/basic/Queue.java b/group16/542087872/src/com/coding/basic/Queue.java new file mode 100644 index 0000000000..8e4285464b --- /dev/null +++ b/group16/542087872/src/com/coding/basic/Queue.java @@ -0,0 +1,22 @@ +package com.coding.basic; + +public class Queue { + + private LinkedList linkedList = new LinkedList(); + + public void enQueue(Object o){ + linkedList.addLast(o); + } + + public Object deQueue(){ + return linkedList.removeFirst(); + } + + public boolean isEmpty(){ + return linkedList.size() == 0; + } + + public int size(){ + return linkedList.size(); + } +} diff --git a/group16/542087872/src/com/coding/basic/Stack.java b/group16/542087872/src/com/coding/basic/Stack.java new file mode 100644 index 0000000000..bfe98dd8b7 --- /dev/null +++ b/group16/542087872/src/com/coding/basic/Stack.java @@ -0,0 +1,25 @@ +package com.coding.basic; + +public class Stack { + private ArrayList elementData = new ArrayList(); + + public void push(Object o){ + elementData.add(o); + } + + public Object pop(){ + Object o = elementData.get(elementData.size() - 1); + elementData.remove(elementData.size() - 1); + return o; + } + + public Object peek(){ + return elementData.get(elementData.size() - 1); + } + public boolean isEmpty(){ + return elementData.size() == 0; + } + public int size(){ + return elementData.size(); + } +} diff --git a/group16/542087872/src/com/coding/basic/Test.java b/group16/542087872/src/com/coding/basic/Test.java new file mode 100644 index 0000000000..2db5b2f9ab --- /dev/null +++ b/group16/542087872/src/com/coding/basic/Test.java @@ -0,0 +1,166 @@ +package com.coding.basic; + + +/** + * Created by xiaoyuan on 25/02/2017. + */ +public class Test { + public static void main(String[] args) { + + testArrayList(); + testLinkedList(); + + testQueue(); + testStack(); + + + testBinaryTreeNode(); + } + + private static void testBinaryTreeNode() { + + BinaryTreeNode binaryTreeNode = new BinaryTreeNode(10); + binaryTreeNode.insert(5); + binaryTreeNode.insert(4); + binaryTreeNode.insert(6); + binaryTreeNode.insert(11); + + traverse(binaryTreeNode); + + } + + private static void traverse(BinaryTreeNode node) { + if (node.getLeft() != null) { + traverse(node.getLeft()); + } + + System.out.println("-- " + node.getData() + " --"); + + if (node.getRight() != null) { + traverse(node.getRight()); + } + + } + + + static void testStack() { + + Stack stack = new Stack(); + stack.push(1); + stack.push(2); + stack.push(3); + stack.push(4); + + System.out.println(stack.size()); + System.out.println(stack.isEmpty()); + + System.out.println(stack.pop()); + System.out.println(stack.pop()); + System.out.println(stack.pop()); + System.out.println(stack.pop()); + + System.out.println(stack.isEmpty()); + + } + + static void testQueue() { + Queue queue = new Queue(); + queue.enQueue(1); + queue.enQueue(2); + + System.out.println(queue.size()); + System.out.println(queue.deQueue()); + System.out.println(queue.deQueue()); + System.out.println(queue.size()); + } + static void testLinkedList() { + LinkedList linkedList = new LinkedList(); + linkedList.add(1); + linkedList.add(2); + + System.out.println(linkedList.size()); + System.out.println(linkedList); + + linkedList.add(4); + linkedList.add(5); + System.out.println(linkedList.size()); + System.out.println(linkedList); + + + linkedList.add(0, 10); + linkedList.add(0, 9); + System.out.println(linkedList.size()); + System.out.println(linkedList); + + System.out.println(linkedList.get(3)); + + linkedList.remove(0); + System.out.println(linkedList.size()); + System.out.println(linkedList); + + + linkedList.addFirst(100); + linkedList.addLast(8888); + System.out.println(linkedList.size()); + System.out.println(linkedList); + + + linkedList.removeFirst(); + linkedList.removeLast(); + System.out.println(linkedList.size()); + System.out.println(linkedList); + + Iterator iterator = linkedList.iterator(); + while (iterator.hasNext()) { + System.out.println(iterator.next()); + } + + } + + static void testArrayList() { + ArrayList arrayList = new ArrayList(); + arrayList.add("1"); + arrayList.add("2"); + // test size and add + System.out.println(arrayList.size()); + System.out.println(arrayList); + + + arrayList.add("3"); + arrayList.add("4"); + arrayList.add("5"); + arrayList.add("6"); + arrayList.add("7"); + arrayList.add("8"); + arrayList.add("9"); + arrayList.add("10"); + arrayList.add("11"); + arrayList.add("12"); + arrayList.add("13"); + + // test size + // test grow + System.out.println(arrayList.size()); + System.out.println(arrayList); + + // test add at index + arrayList.add(2, 100); + System.out.println(arrayList.size()); + System.out.println(arrayList); + + // test remove + arrayList.remove(0); + System.out.println(arrayList.size()); + System.out.println(arrayList); + arrayList.remove(2); + System.out.println(arrayList.size()); + System.out.println(arrayList); + + // test iterator + Iterator iterator = arrayList.iterator(); + while (iterator.hasNext()) { + System.out.println(iterator.next()); + } + + } +} diff --git a/group16/out/production/214074094/com/reading/blog_test.txt b/group16/out/production/214074094/com/reading/blog_test.txt new file mode 100644 index 0000000000..b7e5cbfe14 --- /dev/null +++ b/group16/out/production/214074094/com/reading/blog_test.txt @@ -0,0 +1 @@ +just test new fork \ No newline at end of file diff --git a/group16/out/production/214074094/readme.txt b/group16/out/production/214074094/readme.txt new file mode 100644 index 0000000000..c1b06ddcc2 --- /dev/null +++ b/group16/out/production/214074094/readme.txt @@ -0,0 +1 @@ +I am 北京-Shane diff --git a/group16/out/production/214074094/src/com/reading/blog_test.txt b/group16/out/production/214074094/src/com/reading/blog_test.txt new file mode 100644 index 0000000000..b7e5cbfe14 --- /dev/null +++ b/group16/out/production/214074094/src/com/reading/blog_test.txt @@ -0,0 +1 @@ +just test new fork \ No newline at end of file