diff --git a/group14/352504906/test/.classpath b/group14/352504906/test/.classpath new file mode 100644 index 0000000000..18d70f02cb --- /dev/null +++ b/group14/352504906/test/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/group14/352504906/test/.project b/group14/352504906/test/.project new file mode 100644 index 0000000000..b0299dbe76 --- /dev/null +++ b/group14/352504906/test/.project @@ -0,0 +1,17 @@ + + + test + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/group14/352504906/test/.settings/org.eclipse.core.resources.prefs b/group14/352504906/test/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000000..e2d1bdfc9f --- /dev/null +++ b/group14/352504906/test/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,6 @@ +#Sun Feb 26 15:56:36 CST 2017 +eclipse.preferences.version=1 +encoding//src/com/coding/basic=UTF-8 +encoding//src/com/coding/basic/SimpleArrayList.java=UTF-8 +encoding/=UTF-8 +encoding/src=UTF-8 diff --git a/group14/352504906/test/.settings/org.eclipse.jdt.core.prefs b/group14/352504906/test/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..06bffba000 --- /dev/null +++ b/group14/352504906/test/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Sun Feb 26 15:31:53 CST 2017 +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.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +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.6 diff --git a/group14/352504906/test/src/com/coding/basic/SimpleArrayList.java b/group14/352504906/test/src/com/coding/basic/SimpleArrayList.java new file mode 100644 index 0000000000..931d0af3aa --- /dev/null +++ b/group14/352504906/test/src/com/coding/basic/SimpleArrayList.java @@ -0,0 +1,118 @@ +package com.coding.basic; + +import java.util.Arrays; + + +/** + * @Description 简单实现ArrayList + */ +public class SimpleArrayList implements SimpleList{ + private int size = 0; + private Object[] elementData = new Object[10]; + /** + * 插入元素o + * @param o 待插入元素 + */ + public void add(Object o){ + //扩容 + if(elementData.length < size + 1){ + grow(size+1); + } + elementData[size++] = o; + } + /** + * 数组扩容 + * @param capacity 数组实际长度 + */ + private void grow(int capacity) { + int oldCapacity = elementData.length; + int newCapacity = oldCapacity + (oldCapacity >> 1);//扩容50% + if(capacity > newCapacity){ + newCapacity = capacity; + } + elementData = Arrays.copyOf(elementData, newCapacity); + } + /** + * 在指定索引初插入元素 + * @param index 索引 + * @param o 待插入元素 + */ + public void add(int index,Object o){ + rangeCheckForAdd(index); + if(elementData.length size || index <0){ + throw new IndexOutOfBoundsException("数组越界异常"); + } + } + /** + * 索引越界处理 + * @param index 索引 + */ + private void rangeCheck(int index) { + if(index >= size || index <0) + throw new IndexOutOfBoundsException("数组越界异常"); + } + /** + * 移除该索引处元素 + * @param index 索引位置 + * @return 移除元素 + */ + public Object remove(int index){ + rangeCheck(index); + Object oldObject = elementData[index]; + if(size > index +1){ + System.arraycopy(elementData, index +1 , elementData, index, size-index-1); + } + elementData[--size] = null; + return oldObject; + } + /** + * 返回集合长度 + * @return 长度 + */ + public int size(){ + return this.size; + } + /** + * 返回指定索引元素 + * @param index 索引 + * @return Object 元素 + */ + public Object get(int index){ + rangeCheck(index); + return elementData[index]; + } + private class ArrayListIterator implements SimpleIterator{ + SimpleArrayList l = null; + private int iteratorIndex = 0; + + private ArrayListIterator(SimpleArrayList arrayList){ + this.l = arrayList; + } + + @Override + public boolean hasNext() { + return iteratorIndex < size; + } + + @Override + public Object next() { + if (iteratorIndex >= size) { + throw new RuntimeException("数组越界异常"); + } + return elementData[iteratorIndex++]; + } + + } +} diff --git a/group14/352504906/test/src/com/coding/basic/SimpleIterator.java b/group14/352504906/test/src/com/coding/basic/SimpleIterator.java new file mode 100644 index 0000000000..fd8db0aa8f --- /dev/null +++ b/group14/352504906/test/src/com/coding/basic/SimpleIterator.java @@ -0,0 +1,11 @@ +package com.coding.basic; + +/** + *简单迭代器接口 + * + */ +public interface SimpleIterator { + public Object next(); + public boolean hasNext(); + +} diff --git a/group14/352504906/test/src/com/coding/basic/SimpleLinkedList.java b/group14/352504906/test/src/com/coding/basic/SimpleLinkedList.java new file mode 100644 index 0000000000..692fd23f62 --- /dev/null +++ b/group14/352504906/test/src/com/coding/basic/SimpleLinkedList.java @@ -0,0 +1,126 @@ +package com.coding.basic; +/** + * @Description 简单实现linkedList + */ +public class SimpleLinkedList implements SimpleList{ + private Node head; + + private int size = 0; + /** + * 返回集合长度 + * @return 长度 + */ + public int size(){ + return this.size; + } + /** + * 返回指定索引出元素 + * @param index 索引 + * @return Object 元素 + */ + public Object get(int index){ + rangeCheck(index); + Node current = head; + for(int i =0;i size || index < 0){ + throw new RuntimeException("找不到该节点"); + } + } + //头插法 + public void addFirst(Object o){ + Node newNode = new Node(o); + newNode.next = head; + head = newNode; + size++; + } + //尾插法 + public void addLast(Object o){ + Node newNode = new Node(o); + Node current = head;//设定一个当前节点,便于遍历 + while(current.next!=null){ + current = current.next; + } + if(current.next == null)//尾节点 + { + current.next = newNode; + size++; + } + } + /** + * 移除该索引处元素 + * @param index 索引位置 + * @return 移除元素 + */ + public Object remove(int index){ + rangeCheck(index+1); + Node current = head; + if(index == 0){//头部删除 + Object removeObj = head.o; + head = head.next; + size --; + return removeObj; + } + int i; + for(i=0;i newCapacity){ + newCapacity = capacity; + } + elementData = Arrays.copyOf(elementData, newCapacity); + } + /** + * 移除并返回队列头部元素 + * @return 队列头部元素 + */ + public Object deQueue(){ + Object o = elementData[size-1]; + removeElement(0); + return o; + } + /** + * 删除指定索引处元素 + * @param index 索引 + */ + private void removeElement(int index) { + if(index >= 0){ + System.arraycopy(elementData, index+1, elementData, 0, size-index-1); + elementData[--size] = null; + } + } + /** + * 判断队列是否为空 + * @return Boolean + */ + public boolean isEmpty(){ + return size==0; + } + /** + * 返回队列长度 + * @return int 队列长度 + */ + public int size(){ + return this.size; + } +} diff --git a/group14/352504906/test/src/com/coding/basic/SimpleStack.java b/group14/352504906/test/src/com/coding/basic/SimpleStack.java new file mode 100644 index 0000000000..66d5e7dbe1 --- /dev/null +++ b/group14/352504906/test/src/com/coding/basic/SimpleStack.java @@ -0,0 +1,76 @@ +package com.coding.basic; + +import java.util.Arrays; +import java.util.EmptyStackException; + +/** + * @Description 简单实现stack + */ +public class SimpleStack { + private Object[] elementData = new Object[10]; + private int size; + /** + * 往栈顶添加新的元素 + * @param o 要添加的元素 + */ + public void push(Object o){ + //扩容 + if(elementData.length < size +1){ + grow(size+1); + } + elementData[size++] = o; + } + /** + * 数组扩容 + * @param capacity 数组实际长度 + */ + private void grow(int capacity) { + int oldCapacity = elementData.length; + int newCapacity = oldCapacity *2;//扩容2倍 + if(newCapacity < capacity){ + newCapacity = capacity; + } + elementData = Arrays.copyOf(elementData, newCapacity); + } + /** + * 移除并返回栈顶元素 + * @return Object 返回该移除的元素 + */ + public Object pop(){ + Object o = peek(); + removeElement(size-1); + return o; + } + /** + * 移除栈顶元素 + * @param length 栈的长度 + */ + private void removeElement(int length) { + elementData = Arrays.copyOf(elementData, length); + size --; + } + /** + * 返回栈顶元素 + * @return Object 栈顶元素 + */ + public Object peek(){ + if(size == 0){ + throw new EmptyStackException(); + } + return elementData[size-1]; + } + /** + * 查询并返回栈的长度 + * @return int 栈的长度 + */ + public int size(){ + return this.size; + } + /** + * 判断是否为空栈 + * @return boolean + */ + public boolean isEmpty(){ + return size==0; + } +} diff --git "a/group14/352504906/\346\265\205\350\260\210CPU\343\200\201\345\206\205\345\255\230\343\200\201\347\241\254\347\233\230\344\271\213\351\227\264\347\232\204\345\205\263\347\263\273.txt" "b/group14/352504906/\346\265\205\350\260\210CPU\343\200\201\345\206\205\345\255\230\343\200\201\347\241\254\347\233\230\344\271\213\351\227\264\347\232\204\345\205\263\347\263\273.txt" new file mode 100644 index 0000000000..d269d4a4ab --- /dev/null +++ "b/group14/352504906/\346\265\205\350\260\210CPU\343\200\201\345\206\205\345\255\230\343\200\201\347\241\254\347\233\230\344\271\213\351\227\264\347\232\204\345\205\263\347\263\273.txt" @@ -0,0 +1 @@ +���͵�ַ��http://www.cnblogs.com/superFish2016/articles/cpu.html \ No newline at end of file