From 28621ba8bfbc5f4807e384e4e81c698cb1fe4bdf Mon Sep 17 00:00:00 2001
From: Kilien <Linerator@163.com>
Date: Sun, 26 Feb 2017 10:39:36 +0800
Subject: [PATCH 1/2] Create test.txt

hello world
---
 group09/790466157/test.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 group09/790466157/test.txt

diff --git a/group09/790466157/test.txt b/group09/790466157/test.txt
new file mode 100644
index 0000000000..3b18e512db
--- /dev/null
+++ b/group09/790466157/test.txt
@@ -0,0 +1 @@
+hello world

From 3c803acdd0e35a2a5b62bb90c2a1c8f621a1e171 Mon Sep 17 00:00:00 2001
From: "LAPTOP-DBDFJEC7\\Liner" <Linerator@163.com>
Date: Sun, 26 Feb 2017 10:42:40 +0800
Subject: [PATCH 2/2] week01

---
 .../src/com/coding/basic/Iterator.java        |   7 +
 .../790466157/src/com/coding/basic/List.java  |   9 +
 .../src/com/coding/basic/MyArrayList.java     | 133 +++++++++++++++
 .../src/com/coding/basic/MyLinkedList.java    | 159 ++++++++++++++++++
 .../790466157/src/com/coding/basic/Queue.java |  68 ++++++++
 .../790466157/src/com/coding/basic/Stack.java |  73 ++++++++
 6 files changed, 449 insertions(+)
 create mode 100644 group09/790466157/src/com/coding/basic/Iterator.java
 create mode 100644 group09/790466157/src/com/coding/basic/List.java
 create mode 100644 group09/790466157/src/com/coding/basic/MyArrayList.java
 create mode 100644 group09/790466157/src/com/coding/basic/MyLinkedList.java
 create mode 100644 group09/790466157/src/com/coding/basic/Queue.java
 create mode 100644 group09/790466157/src/com/coding/basic/Stack.java

diff --git a/group09/790466157/src/com/coding/basic/Iterator.java b/group09/790466157/src/com/coding/basic/Iterator.java
new file mode 100644
index 0000000000..7c02cc6e51
--- /dev/null
+++ b/group09/790466157/src/com/coding/basic/Iterator.java
@@ -0,0 +1,7 @@
+package com.coding.basic;
+
+public interface Iterator {
+	public boolean hasNext();
+	public Object next();
+
+}
\ No newline at end of file
diff --git a/group09/790466157/src/com/coding/basic/List.java b/group09/790466157/src/com/coding/basic/List.java
new file mode 100644
index 0000000000..c86b745572
--- /dev/null
+++ b/group09/790466157/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();
+}
\ No newline at end of file
diff --git a/group09/790466157/src/com/coding/basic/MyArrayList.java b/group09/790466157/src/com/coding/basic/MyArrayList.java
new file mode 100644
index 0000000000..cf232c5b72
--- /dev/null
+++ b/group09/790466157/src/com/coding/basic/MyArrayList.java
@@ -0,0 +1,133 @@
+package com.coding.basic;
+import java.util.Arrays;
+import java.util.NoSuchElementException;
+
+import com.coding.basic.List;
+import com.coding.basic.Iterator;
+
+public class MyArrayList implements List {
+	
+	private int size = 0;
+	
+	private Object[] elementData = new Object[100];
+	
+	private final static int MAX_ARRAY_LENGTH = Integer.MAX_VALUE;
+
+	private static final int DEFAULT_CAPACITY = 10;
+
+
+	//ÎÞ³£¹¹Ôìº¯Êý
+	public MyArrayList(){
+		this(DEFAULT_CAPACITY);
+	}
+	
+	public MyArrayList(int size){
+		if (size < 0){
+			throw new IllegalArgumentException("Ä¬ÈÏµÄ´óÐ¡" + size);
+		}
+		else{
+			elementData = new Object[size];
+		}
+	}
+
+	public void add(Object o){
+		isCapacityEnough(size+1);
+		elementData[size++] = o;
+	}
+	
+	private void isCapacityEnough(int size){
+		//ÅÐ¶ÏÊÇ·ñ³¬¹ý³õÊ¼ÈÝÁ¿£¬ÊÇ·ñÐèÒªÀ©ÈÝ
+		if (size > DEFAULT_CAPACITY){
+			explicitCapacity(size);
+		}
+		if (size < 0){
+			throw new OutOfMemoryError();
+		}
+	}
+	
+	private void explicitCapacity(int capacity){
+		int oldCapacity = elementData.length;
+		//ÐÂÈÝÁ¿=¾ÉÈÝÁ¿ + £¨¾ÉÈÝÁ¿/2£© À©ÈÝ1.5±¶¡¾ÓÒÒÆ²Ù×÷·ûÏàµ±ÓÚ³ýÒÔ2¡¿
+		int newLength = oldCapacity + (oldCapacity >> 1);
+		if (newLength - capacity < 0){
+			newLength = capacity;
+		}
+		//ÅÐ¶ÏnewLengthµÄ³¤¶È
+		//Èç¹û³¬¹ýÉÏÃæ¶¨ÒåµÄÊý×é×î´ó³¤¶ÈÔòÅÐ¶ÏÒªÐèÒªµÄÀ©ÈÝ¿Õ¼äÊÇ·ñ´óÓÚÊý×é×î´ó³¤¶È
+		//Èç¹û´óÓÚÔònewLengthÎª MAX_VALUE £¬·ñÔòÎª MAX_ARRAY_LENGTH¡£
+		if (newLength > (MAX_ARRAY_LENGTH)){
+			newLength = (capacity > MAX_ARRAY_LENGTH ? Integer.MAX_VALUE : MAX_ARRAY_LENGTH);
+		}
+		//µ÷ÓÃcopyof½øÐÐÀ©ÈÝ
+		elementData = Arrays.copyOf(elementData, newLength);
+	}
+	
+	public void add(int index, Object o){
+		
+		checkRangeForAdd(index);
+		isCapacityEnough(size +1);
+		// ½« elementDataÖÐ´ÓIndexÎ»ÖÃ¿ªÊ¼¡¢³¤¶ÈÎªsize-indexµÄÔªËØ£¬  
+	    // ¿½±´µ½´ÓÏÂ±êÎªindex+1Î»ÖÃ¿ªÊ¼µÄÐÂµÄelementDataÊý×éÖÐ¡£  
+	    // ¼´½«µ±Ç°Î»ÓÚ¸ÃÎ»ÖÃµÄÔªËØÒÔ¼°ËùÓÐºóÐøÔªËØÓÒÒÆÒ»¸öÎ»ÖÃ¡£
+		System.arraycopy(elementData, index, elementData, index + 1, size - index);
+		elementData[index] = o;
+		size++;
+	}
+	
+	//ÅÐ¶ÏÊÇ·ñÔ½½ç
+	private void checkRangeForAdd(int index){
+		if (index < 0 || index > size){
+			throw new IndexOutOfBoundsException("Ö¸¶¨µÄindexÔ½½ç");
+		}
+	}
+	
+	// ·µ»Ø´ËÁÐ±íÖÐÖ¸¶¨Î»ÖÃÉÏµÄÔªËØ¡£ 
+	public Object get(int index){
+		checkRange(index);
+		return elementData[index];
+	}
+	
+	//ÅÐ¶ÏÊÇ·ñÔ½½ç
+	private void checkRange(int index){
+		if (index >= size || index < 0){
+			throw new IndexOutOfBoundsException("Ö¸¶¨µÄindexÔ½½ç");
+		}
+	}
+	
+	public Object remove(int index){
+		Object value = get(index);
+		int moveSize = size - index -1;
+		if (moveSize >0){
+			System.arraycopy(elementData, index +1, elementData, index, size - index -1);
+			
+		}
+		elementData[--size] = null;
+		return value;
+	}
+	
+	public int size(){
+		return size;
+	}
+	
+	//µü´úÆ÷
+	public Iterator iterator(Object o){
+		 return new ArrayListIterator();
+	}
+	
+	
+    private class ArrayListIterator implements Iterator{
+        private int currentIndex=0;
+        
+        public boolean hasNext() {
+			return currentIndex < size();
+        }
+
+        public Object next() {
+            if (!hasNext()){
+            	throw new NoSuchElementException();
+            }
+			return new Object[currentIndex + 1];
+        }
+    }
+	
+}
\ No newline at end of file
diff --git a/group09/790466157/src/com/coding/basic/MyLinkedList.java b/group09/790466157/src/com/coding/basic/MyLinkedList.java
new file mode 100644
index 0000000000..4727db3a89
--- /dev/null
+++ b/group09/790466157/src/com/coding/basic/MyLinkedList.java
@@ -0,0 +1,159 @@
+package com.coding.basic;
+
+public class MyLinkedList<E> {
+
+    private int size;
+
+    private Node<E> first;
+
+    private Node<E> last;
+
+
+    public boolean add(E element) {
+        addAtLast(element);
+        return true;
+    }
+
+    private void addAtLast(E element) {
+        Node<E> l = last;
+        Node<E> node = new Node<E>(element, null, l);
+        last = node;
+        if (l == null) {
+            first = node;
+        } else {
+            l.next = node;
+        }
+        size++;
+    }
+
+    public void add(int index, E element) {
+        checkRangeForAdd(index);
+        if (index == size) {
+            addAtLast(element);
+        } else {
+            Node<E> l = node(index);
+            addBeforeNode(element, l);
+        }
+    }
+
+    private void addBeforeNode(E element, Node<E> specifiedNode) {
+        Node<E> preNode = specifiedNode.prev;
+        Node<E> newNode = new Node<E>(element, specifiedNode, preNode);
+        if (preNode == null) {
+            first = newNode;
+        } else {
+            preNode.next = newNode;
+        }
+        specifiedNode.prev = newNode;
+        size++;
+    }
+
+
+    private Node<E> node(int index) {
+        if (index < (size << 1)) {
+            Node<E> cursor = first;
+            for (int i = 0; i < index; i++) {
+                cursor = cursor.next;
+            }
+            return cursor;
+        } else {
+            Node<E> cursor = last;
+            for (int i = size - 1; i > index; i--) {
+                cursor = cursor.prev;
+            }
+            return cursor;
+        }
+    }
+
+    private void checkRangeForAdd(int index) {
+        if (index > size || index < 0) {
+            throw new IndexOutOfBoundsException("Ö¸¶¨µÄindex³¬¹ý½çÏÞ");
+        }
+    }
+
+    public E get(int index) {
+        checkRange(index);
+        return node(index).item;
+    }
+
+    private void checkRange(int index) {
+        if (index >= size || index < 0) {
+            throw new IndexOutOfBoundsException("Ö¸¶¨index³¬¹ý½çÏÞ");
+        }
+    }
+
+    public int indexOf(Object element) {
+        Node<E> cursor = first;
+        int count = 0;
+        while (cursor != null) {
+            if (element != null) {
+                if (element.equals(cursor.item)) {
+                    return count;
+                }
+            }else{
+                if (cursor.item == null) {
+                    return count;
+                }
+            }
+            count ++;
+            cursor = cursor.next;
+        }
+        return -1;
+    }
+
+    public E remove(int index) {
+        checkRange(index);
+        return deleteLink(index);
+    }
+
+    public boolean remove(Object o) {
+        int index = indexOf(o);
+        if (index < 0){
+            return false;
+        }
+        deleteLink(index);
+        return true;
+    }
+
+    private E deleteLink(int index) {
+        Node<E> l = node(index);
+        E item = l.item;
+        Node<E> prevNode = l.prev;
+        Node<E> nextNode = l.next;
+
+        if (prevNode == null) {
+            first = nextNode;
+        }else{
+            prevNode.next = nextNode;
+            l.next = null;
+        }
+
+        if (nextNode == null) {
+            last = prevNode;
+        }else{
+            nextNode.prev = prevNode;
+            l.prev = null;
+        }
+        size--;
+        l.item = null;
+        return item;
+    }
+
+
+
+    public int size(){
+        return size;
+    }
+    private static class Node<E> {
+        E item;
+        Node<E> next;
+        Node<E> prev;
+
+        public Node(E item, Node<E> next, Node<E> prev) {
+            this.item = item;
+            this.next = next;
+            this.prev = prev;
+
+        }
+    }
+}
diff --git a/group09/790466157/src/com/coding/basic/Queue.java b/group09/790466157/src/com/coding/basic/Queue.java
new file mode 100644
index 0000000000..80d0dc9835
--- /dev/null
+++ b/group09/790466157/src/com/coding/basic/Queue.java
@@ -0,0 +1,68 @@
+package com.coding.basic;
+import java.util.Arrays;
+
+public class Queue {
+	private static final int CAPACITY = 10;
+	private static int capacity;
+	private static int front;
+	private static int tail;
+	private static Object[] array;
+	
+	public Queue(){
+		this.capacity = CAPACITY;
+		array = new Object[capacity];
+		front = tail = 0;
+	}
+	
+	public void enQueue(Object o) throws ExceptionQueueFull {
+		if (size() == capacity -1)
+			throw new ExceptionQueueFull("Queue is full");
+		array[tail] = o;
+		tail = (tail +1) % capacity;
+	}
+	
+	public Object deQueue() throws ExceptionQueueEmpty{
+		Object o;
+        if (isEmpty())
+            throw new ExceptionQueueEmpty("Queue is empty");
+        o = array[front];
+        front = (front + 1) % capacity;
+        return o;
+	}
+	
+	public boolean isEmpty(){
+		return (front == tail);
+	}
+	
+	public int size(){
+		if (isEmpty())
+			return 0;
+		else
+		return (capacity + tail - front) % capacity;
+	}
+	
+	public class ExceptionQueueEmpty extends Exception {
+	    // Constructor
+	    public ExceptionQueueEmpty() {
+
+	    }
+
+	    // Constructor with parameters
+	    public ExceptionQueueEmpty(String mag) {
+	        System.out.println(mag);
+	    }
+	}
+	
+	public class ExceptionQueueFull extends Exception {
+
+	    // Constructor
+	    public ExceptionQueueFull() {
+
+	    }
+
+	    // Constructor with parameters
+	    public ExceptionQueueFull(String mag) {
+	        System.out.println(mag);
+	    }
+	}
+}
\ No newline at end of file
diff --git a/group09/790466157/src/com/coding/basic/Stack.java b/group09/790466157/src/com/coding/basic/Stack.java
new file mode 100644
index 0000000000..324cc5639e
--- /dev/null
+++ b/group09/790466157/src/com/coding/basic/Stack.java
@@ -0,0 +1,73 @@
+package com.coding.basic;
+import java.util.Arrays;
+import com.coding.basic.MyArrayList;
+public class Stack {
+	private MyArrayList elementData = new MyArrayList();
+	private static final int CAPACITY = 10;
+	private static int capacity;
+	private static int top = -1;
+	Object[] array;
+	
+	public Stack(){
+		this.capacity = CAPACITY;
+        array = new Object[capacity];
+	}
+	public void push(Object o) throws ExceptionStackFull{		
+		if(size()== CAPACITY){
+            throw new ExceptionStackFull("Stack is full");
+        }
+        array[++ top] = o;
+	}
+	
+	public Object pop() throws ExceptionStackEmpty{
+		  if(isEmpty()){
+	            throw new ExceptionStackEmpty("Stack is empty");
+	        }
+	        return array[top --];
+	}
+	
+	public Object peek() throws ExceptionStackEmpty{
+		 if(isEmpty()){
+	            throw new ExceptionStackEmpty("Stack is empty");
+	        }
+	        return array[top];
+	}
+	
+	public boolean isEmpty(){
+		return (top < 0);
+	}
+	
+	public int size(){
+		if (isEmpty())
+			return 0;
+		else
+		return top + 1;
+		
+	}
+	
+	public class ExceptionStackEmpty extends Exception {
+
+	    //Constructor
+	    public ExceptionStackEmpty(){
+
+	    }
+
+	    //Define myself exception construct with parameters
+	    public ExceptionStackEmpty(String string){
+	        super(string);
+	    }
+	}
+	
+	public class ExceptionStackFull extends Exception {
+
+	    //Constructor
+	        public ExceptionStackFull(){
+
+	        }
+
+	        //Define myself exception construct with parameters
+	        public ExceptionStackFull(String string){
+	            super(string);
+	        }
+	}
+}
\ No newline at end of file
