diff --git a/.gitignore b/.gitignore index 6945ca9d30..77cdfba900 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,7 @@ rebel.* .rebel.* target +*.DS_Store +liuxin/.DS_Store +liuxin/src/.DS_Store diff --git a/group26/1515345281/src/Collection/ArrayList.java b/group26/1515345281/src/Collection/ArrayList.java index 017fac67e2..fb15e957f2 100644 --- a/group26/1515345281/src/Collection/ArrayList.java +++ b/group26/1515345281/src/Collection/ArrayList.java @@ -1,7 +1,6 @@ package Collection; public class ArrayList implements List { - private int size = 0; private Object[] elementData = new Object[100]; diff --git a/group26/1515345281/src/Collection/LinkedList.java b/group26/1515345281/src/Collection/LinkedList.java index 8a689e187a..3d4a4d496d 100644 --- a/group26/1515345281/src/Collection/LinkedList.java +++ b/group26/1515345281/src/Collection/LinkedList.java @@ -1,195 +1,210 @@ package Collection; public class LinkedList implements List { - - private int theSize=0;//表示该链表的长度 - private Node beginMarker;//链表的头元素 - private Node endMarker;//链表的尾元素 - - //链表的构造方法 - public LinkedList () { - beginMarker = new Node(null, null, null); - endMarker = new Node(null, beginMarker, null); - beginMarker.next=endMarker; - } - - public void add(Object o){ - add(size(),o); - } - public void add(int index , Object o){ - addBefore(getNode(index),o); - } - public Object get(int index){ - return getNode(index).data; - } - public Object remove(int index){ - return remove(getNode(index)); - } - - public int size(){ - return theSize; - } - - public void addFirst(Object o){ - addBefore(getNode(0),o); - } - public void addLast(Object o){ - addBefore(getNode(theSize),o); - } - public Object removeFirst(){ - return remove(getNode(0)); - } - public Object removeLast(){ - return remove(getNode(theSize-1)); - } - public Iterator iterator(){ - return new Itr(); - } - - private class Itr implements Iterator{ - - private Node cursor=beginMarker.next; - @Override - public boolean hasNext() { - - return cursor!=endMarker; - } - - @Override - public Object next() { - - Object o=cursor.data; - cursor=cursor.next; - - return o; - } - - } - private Object remove(Node node) { - node.prev.next=node.next; - node.next.prev=node.prev; - theSize--; - return node.data; - } - - private Node getNode(int index){ - Node p; - if(index<0 || index>size()){ - throw new IndexOutOfBoundsException(); - } - if(index==-1){ - return beginMarker; - }else if(index==theSize){ - return endMarker; - } - if(indexindex;i--){ - p=p.prev; - } - } - return p; - } - - private void addBefore(Node node,Object o){ - Node newNode=new Node(o,node.prev,node); - newNode.prev.next=newNode; - node.prev=newNode; - theSize++; - //nodeCount++; - } - - private static class Node{ - public Object data; - public Node next; - public Node prev; - public Node(Object data,Node prev,Node next){ - this.data=data; - this.prev=prev; - this.next=next; - } - } - - - //以下不用实现 - /** - * 把该链表逆置 - * 例如链表为 3->7->10 , 逆置后变为 10->7->3 - */ - public void reverse(){ - - } - - /** - * 删除一个单链表的前半部分 - * 例如:list = 2->5->7->8 , 删除以后的值为 7->8 - * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10 - - */ - public void removeFirstHalf(){ - - } - - /** - * 从第i个元素开始, 删除length 个元素 , 注意i从0开始 - * @param i - * @param length - */ - public void remove(int i, int length){ - - } - /** - * 假定当前链表和listB均包含已升序排列的整数 - * 从当前链表中取出那些listB所指定的元素 - * 例如当前链表 = 11->101->201->301->401->501->601->701 - * listB = 1->3->4->6 - * 返回的结果应该是[101,301,401,601] - * @param list - */ - public int[] getElements(LinkedList list){ - return null; - } - - /** - * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 - * 从当前链表中中删除在listB中出现的元素 - - * @param list - */ - - public void subtract(LinkedList list){ - - } - - /** - * 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。 - * 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同) - */ - public void removeDuplicateValues(){ - - } - - /** - * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 - * 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素) - * @param min - * @param max - */ - public void removeRange(int min, int max){ - - } - - /** - * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同) - * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列 - * @param list - */ - public LinkedList intersection( LinkedList list){ - return null; - } + + private int theSize = 0;//表示该链表的长度 + private Node beginMarker;//链表的头元素 + private Node endMarker;//链表的尾元素 + + //链表的构造方法 + public LinkedList() { + beginMarker = new Node(null, null, null); + endMarker = new Node(null, beginMarker, null); + beginMarker.next = endMarker; + } + + public void add(Object o) { + add(size(), o); + } + + public void add(int index, Object o) { + addBefore(getNode(index), o); + } + + public Object get(int index) { + return getNode(index).data; + } + + public Object remove(int index) { + return remove(getNode(index)); + } + + public int size() { + return theSize; + } + + public void addFirst(Object o) { + addBefore(getNode(0), o); + } + + public void addLast(Object o) { + addBefore(getNode(theSize), o); + } + + public Object removeFirst() { + return remove(getNode(0)); + } + + public Object removeLast() { + return remove(getNode(theSize - 1)); + } + + public Iterator iterator() { + return new Itr(); + } + + private class Itr implements Iterator { + + private Node cursor = beginMarker.next; + + @Override + public boolean hasNext() { + + return cursor != endMarker; + } + + @Override + public Object next() { + + Object o = cursor.data; + cursor = cursor.next; + + return o; + } + + } + + private Object remove(Node node) { + node.prev.next = node.next; + node.next.prev = node.prev; + theSize--; + return node.data; + } + + private Node getNode(int index) { + Node p; + if (index < 0 || index > size()) { + throw new IndexOutOfBoundsException(); + } + if (index == -1) { + return beginMarker; + } else if (index == theSize) { + return endMarker; + } + if (index < size() / 2) { + p = beginMarker.next; + for (int i = 0; i < index; i++) { + p = p.next; + } + } else { + p = endMarker.prev; + for (int i = size() - 1; i > index; i--) { + p = p.prev; + } + } + return p; + } + + private void addBefore(Node node, Object o) { + Node newNode = new Node(o, node.prev, node); + newNode.prev.next = newNode; + node.prev = newNode; + theSize++; + //nodeCount++; + } + + private static class Node { + public Object data; + public Node next; + public Node prev; + + public Node(Object data, Node prev, Node next) { + this.data = data; + this.prev = prev; + this.next = next; + } + } + + + //以下不用实现 + + /** + * 把该链表逆置 + * 例如链表为 3->7->10 , 逆置后变为 10->7->3 + */ + public void reverse() { + + } + + /** + * 删除一个单链表的前半部分 + * 例如:list = 2->5->7->8 , 删除以后的值为 7->8 + * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10 + */ + public void removeFirstHalf() { + + } + + /** + * 从第i个元素开始, 删除length 个元素 , 注意i从0开始 + * + * @param i + * @param length + */ + public void remove(int i, int length) { + + } + + /** + * 假定当前链表和listB均包含已升序排列的整数 + * 从当前链表中取出那些listB所指定的元素 + * 例如当前链表 = 11->101->201->301->401->501->601->701 + * listB = 1->3->4->6 + * 返回的结果应该是[101,301,401,601] + * + * @param list + */ + public int[] getElements(LinkedList list) { + return null; + } + + /** + * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 从当前链表中中删除在listB中出现的元素 + * + * @param list + */ + + public void subtract(LinkedList list) { + + } + + /** + * 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同) + */ + public void removeDuplicateValues() { + + } + + /** + * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素) + * + * @param min + * @param max + */ + public void removeRange(int min, int max) { + + } + + /** + * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同) + * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列 + * + * @param list + */ + public LinkedList intersection(LinkedList list) { + return null; + } } diff --git a/group26/1515345281/src/Collection/TestCollection.java b/group26/1515345281/src/Collection/TestCollection.java index 797ce419b5..9105cbe23b 100644 --- a/group26/1515345281/src/Collection/TestCollection.java +++ b/group26/1515345281/src/Collection/TestCollection.java @@ -2,6 +2,7 @@ import org.junit.Test; + public class TestCollection { @Test diff --git a/group26/2070509107/.gitignore b/group26/2070509107/.gitignore new file mode 100644 index 0000000000..68dd6977c1 --- /dev/null +++ b/group26/2070509107/.gitignore @@ -0,0 +1,5 @@ +.project +.settings +pom.xml +./target +.classpath diff --git a/group26/2070509107/src/basic/collections/ArrayList.java b/group26/2070509107/src/basic/collections/ArrayList.java new file mode 100644 index 0000000000..cdec1fdd01 --- /dev/null +++ b/group26/2070509107/src/basic/collections/ArrayList.java @@ -0,0 +1,92 @@ +package collections; + +/** + * + * @author Mahone Wu + * @data:2017-03-10 + * @description:ArrayList的自我实现,暂时没有自动扩展 + * @version:1.0.0 + */ + +public class ArrayList implements List { + + // 数组存储数据大小 + private int size = 0; + + int cap = 5; + + // 数组 + private Object[] elementData = new Object[cap]; + + /** + * 新增元素 + */ + public void add(Object o) { + elementData[size] = o; + size++; + } + + /** + * 指定位置新增数据 + */ + public void add(int index, Object o) { + // 保存现在该位置有的元素 + Object temp = elementData[index]; + + // 如果当前存放数据等于初始化数组大小,则数组需要进行扩容操作 + if (elementData.length == size) { + // TODO + } + // 如果没有超过大小,则把从插入开始点的数据都往后移一位 + for (int i = size; i > index; i--) { + elementData[i] = elementData[i - 1]; + } + // 将现在赋值的数据放到该位置 + elementData[index] = o; + size++; + } + + /** + * 获取数据 + */ + public Object get(int index) { + if (index > elementData.length) { + return null; + } + return elementData[index]; + } + + // 返回要删除的数据 + public Object remove(int index) { + // 要被删除的数据 + Object data = elementData[index]; + for (int i = index; i < size; i++) { + elementData[i] = elementData[i + 1]; + } + size--; + return data; + } + + public int size() { + return size; + } + + // TODO + /** + * 循环输出 + * + * @return + */ + public Iterator iterator() { + int current = 0; + if (hasNext(current)) { + // return elementData[current+1]; + } + return null; + } + + public boolean hasNext(int current) { + return current < size(); + } + +} diff --git a/group26/2070509107/src/basic/collections/BinaryTreeNode.java b/group26/2070509107/src/basic/collections/BinaryTreeNode.java new file mode 100644 index 0000000000..806ccf1d9e --- /dev/null +++ b/group26/2070509107/src/basic/collections/BinaryTreeNode.java @@ -0,0 +1,43 @@ +package collections; + +/** + * + * @author Mahone Wu + * @data:2017-03-10 + * @description:BinaryTreeNode的自我实现 @version:1.0.0 + */ +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/group26/2070509107/src/basic/collections/Iterator.java b/group26/2070509107/src/basic/collections/Iterator.java new file mode 100644 index 0000000000..94a2a9b129 --- /dev/null +++ b/group26/2070509107/src/basic/collections/Iterator.java @@ -0,0 +1,8 @@ +package collections; + +public interface Iterator { + public boolean hasNext(); + + public Object next(); + +} diff --git a/group26/2070509107/src/basic/collections/LinkedList.java b/group26/2070509107/src/basic/collections/LinkedList.java new file mode 100644 index 0000000000..7a796daa3a --- /dev/null +++ b/group26/2070509107/src/basic/collections/LinkedList.java @@ -0,0 +1,196 @@ +package collections; + + +/** + * + * @author Mahone Wu + * @date:2017-03-11 + * @description:链表实现 + * @version:1.0.0 + */ +public class LinkedList implements List { + + //定义头节点 + private Node head; + + //最后一个节点 + private Node last; + + //链表大小 + private int size; + + /** + * 添加元素 + */ + public void add(Object o) { + addLast(o); + } + + /** + * 指定位置添加元素 + */ + public void add(int index, Object o) { + if(!(index >= 0 && index <= size)){ + //超出索引范围 + } + Node currentNode =null; + + + } + + + + + /** + * 获取指定元素 + */ + public Object get(int index) { + return null; + } + + public Object remove(int index) { + return null; + } + + public int size() { + return size; + } + + public void addFirst(Object o) { + Node fistNode = head; + Node newNode = new Node(null, o, head); + head = newNode; + if(null == fistNode){ + last = newNode; + }else{//将之前的头节点的前一个指向现在的头节点 + fistNode.prev = newNode; + } + size++; + } + + /** + * 向尾添加元素 + * @param o + */ + public void addLast(Object o) { + Node lastNode = last; + Node newNode = new Node(lastNode, o, null); + last = newNode;//将新增的节点设置为最后一个节点 + if(null == lastNode){//如果之前最后一个节点为空,则代表这是第一次增加节点,进行头节点设置 + head = newNode; + }else{ + lastNode.next = newNode; + } + size++; + } + + public Object removeFirst() { + return null; + } + + public Object removeLast() { + return null; + } + + public Iterator iterator() { + return null; + } + + //参照LinkedList源码实现 + private static class Node { + Object data; + Node prev; + Node next; + + Node(Node prev,Object object,Node next){ + this.prev = prev; + this.data = object; + this.next = next; + } + } + + /** + * 查找指定位置的Node节点 + * @param index + * @return + */ + Node findNode(int index){ + Node currentNode = head; + + + } + + /** + * 把该链表逆置 例如链表为 3->7->10 , 逆置后变为 10->7->3 + */ + public void reverse() { + + } + + /** + * 删除一个单链表的前半部分 例如:list = 2->5->7->8 , 删除以后的值为 7->8 如果list = 2->5->7->8->10 + * ,删除以后的值为7,8,10 + * + */ + public void removeFirstHalf() { + + } + + /** + * 从第i个元素开始, 删除length 个元素 , 注意i从0开始 + * + * @param i + * @param length + */ + public void remove(int i, int length) { + + } + + /** + * 假定当前链表和listB均包含已升序排列的整数 从当前链表中取出那些listB所指定的元素 例如当前链表 = + * 11->101->201->301->401->501->601->701 listB = 1->3->4->6 + * 返回的结果应该是[101,301,401,601] + * + * @param list + */ + public int[] getElements(LinkedList list) { + return null; + } + + /** + * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 从当前链表中中删除在listB中出现的元素 + * + * @param list + */ + + public void subtract(LinkedList list) { + + } + + /** + * 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同) + */ + public void removeDuplicateValues() { + + } + + /** + * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素) + * + * @param min + * @param max + */ + public void removeRange(int min, int max) { + + } + + /** + * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同) + * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列 + * + * @param list + */ + public LinkedList intersection(LinkedList list) { + return null; + } +} diff --git a/group26/2070509107/src/basic/collections/List.java b/group26/2070509107/src/basic/collections/List.java new file mode 100644 index 0000000000..8cc886f400 --- /dev/null +++ b/group26/2070509107/src/basic/collections/List.java @@ -0,0 +1,13 @@ +package collections; + +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/group26/2070509107/src/basic/collections/Queue.java b/group26/2070509107/src/basic/collections/Queue.java new file mode 100644 index 0000000000..47f4116e2f --- /dev/null +++ b/group26/2070509107/src/basic/collections/Queue.java @@ -0,0 +1,20 @@ +package collections; + +public class Queue { + + public void enQueue(Object o) { + + } + + public Object deQueue() { + return null; + } + + public boolean isEmpty() { + return false; + } + + public int size() { + return -1; + } +} diff --git a/group26/2070509107/src/basic/collections/Stack.java b/group26/2070509107/src/basic/collections/Stack.java new file mode 100644 index 0000000000..7665278d45 --- /dev/null +++ b/group26/2070509107/src/basic/collections/Stack.java @@ -0,0 +1,69 @@ +package collections; + +/** + * + * @author wuhao + * @date:2017-03-11 + * @description:栈的实现,栈是先进后出; + * @version:1.0.0 + * + */ +public class Stack { + + private ArrayList elementData = new ArrayList(); + + /** + * 存放元素 + * + * @param o + */ + public void push(Object o) { + elementData.add(o); + } + + /** + * 弹出元素,从最末尾弹出 + * + * @return + */ + public Object pop() { + if (elementData.size() == 0) { + return null; + } + return elementData.remove(elementData.size() - 1); + } + + /** + * 获取栈定元素 + * + * @return + */ + public Object peek() { + if (elementData.size() == 0) { + return null; + } + return elementData.get(elementData.size()); + } + + /** + * 判断是否为空 + * + * @return + */ + public boolean isEmpty() { + if (0 == elementData.size()) { + return false; + } + return true; + } + + /** + * 栈大小 + * + * @return + */ + public int size() { + return elementData.size(); + } + +} diff --git a/group26/2070509107/src/basic/collections/Test.java b/group26/2070509107/src/basic/collections/Test.java new file mode 100644 index 0000000000..0cc5316cfa --- /dev/null +++ b/group26/2070509107/src/basic/collections/Test.java @@ -0,0 +1,13 @@ +package collections; + +public class Test { + public static void main(String[] args) { + List list = new ArrayList(); + list.add(1); + list.add(1); + list.add(1); + list.add(1); + list.add(1); + System.out.println(list.size()); + } +} diff --git a/group26/2411685663/src/nishuibaichuan/homework/first/ArrayList.java b/group26/2411685663/src/nishuibaichuan/homework/first/ArrayList.java new file mode 100644 index 0000000000..efa9ee9bd1 --- /dev/null +++ b/group26/2411685663/src/nishuibaichuan/homework/first/ArrayList.java @@ -0,0 +1,123 @@ +package JEE_2411685663; + +import java.util.Arrays; +import java.util.NoSuchElementException; + +public class ArrayList implements List { + + private static int size = 0; //全局静态变量 + + private Object[] elementData = new Object[100]; + + public void add(Object o) { + isCapacity(size + 1);//判断是否扩容 + elementData[size++] = o; + } + + public void add(int index, Object o) { + checkRangeForAdd(index);//判断下标是否越界 + isCapacity(size + 1); + //使用arraycopy将index下标以后元素后移动 (size - index)长度 + System.arraycopy(elementData, index, elementData, index + 1, size - index); + elementData[index] = o; + size++; + } + + public Object get(int index) { + checkRangeForAdd(index); + return (Object)elementData[index]; + } + + public Object remove(int index) { + checkRangeForAdd(index); + Object oldValue = get(index); + int numMoved = size - index - 1; + if (numMoved > 0) + System.arraycopy(elementData, index+1, elementData, index, + numMoved); + elementData[--size] = null; // index后面数据依次往前移动,将最后一个位置赋值为0,让gc来回收空间。 + return oldValue; + } + + public int size() { + return size; + } + + /** + * 迭代器 + * @return + */ + public Iterator iterator() { + return new SubIterator(this); + } + + private static class SubIterator implements Iterator{ + + private ArrayList arrayList; + private static int ret = 0; + + private SubIterator(){} + + private SubIterator(ArrayList arrayList){ + this.arrayList = arrayList ; + } + + public boolean hasNext() { + return ret != size; + } + + public Object next() { + if (ret > size) { + throw new NoSuchElementException();//没有这样的元素异常 + } + return arrayList.elementData[ret++]; + } + + public void remove() { + arrayList.remove(ret--); + } + + } + + /** + * 下标是否越界 + * @param index + */ + public void checkRangeForAdd(int index){ + if (index < 0 || index > size) { + throw new ArrayIndexOutOfBoundsException("index下标越界" + ", Size: " + size + + ",Index: " + index); + } + } + + /** + * 是否扩容 + */ + public void isCapacity(int size){ + if (size > 100) { + Capacity(size); + } + /** + * size小于0主要是因为当size超过Integer.MAX_VALUE就会变成负数。 + */ + if (size < 0) { + throw new ArrayIndexOutOfBoundsException("数组长度溢出"); + } + } + + public void Capacity(int capacity){ + int newLength = elementData.length + 1000;//再原来基础上扩容1000 + if (newLength - capacity < 0) { + newLength = capacity; //得到最大长度 + } + /** + * 保留了数组的头部信息在数组中,因此实际存放数据的大小就是整数的最大值 - 8 + * 很难执行下面的判断 + */ + if (newLength > Integer.MAX_VALUE - 8) { + newLength = capacity > Integer.MAX_VALUE - 8 ? Integer.MAX_VALUE : Integer.MAX_VALUE - 8; + } + elementData = Arrays.copyOf(elementData, newLength);//获取扩容后的数组 + } + +} diff --git a/group26/2411685663/src/nishuibaichuan/homework/first/BinaryTreeNode.java b/group26/2411685663/src/nishuibaichuan/homework/first/BinaryTreeNode.java new file mode 100644 index 0000000000..17984ab8d1 --- /dev/null +++ b/group26/2411685663/src/nishuibaichuan/homework/first/BinaryTreeNode.java @@ -0,0 +1,37 @@ +package nishuibaichuan.homework.first; + +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/group26/2411685663/src/nishuibaichuan/homework/first/Iterator.java b/group26/2411685663/src/nishuibaichuan/homework/first/Iterator.java new file mode 100644 index 0000000000..a0d81a47ba --- /dev/null +++ b/group26/2411685663/src/nishuibaichuan/homework/first/Iterator.java @@ -0,0 +1,9 @@ +package nishuibaichuan.homework.first; + +public interface Iterator { + public boolean hasNext(); + + public Object next(); + + public void remove(); +} diff --git a/group26/2411685663/src/nishuibaichuan/homework/first/LinkedList.java b/group26/2411685663/src/nishuibaichuan/homework/first/LinkedList.java new file mode 100644 index 0000000000..bf38c91470 --- /dev/null +++ b/group26/2411685663/src/nishuibaichuan/homework/first/LinkedList.java @@ -0,0 +1,125 @@ +package nishuibaichuan.homework.first; + +public class LinkedList implements List { + + private Node head; + + public void add(Object o) { + + } + + public void add(int index, Object o) { + + } + + public Object get(int index) { + return null; + } + + public Object remove(int index) { + return null; + } + + public int size() { + return -1; + } + + public void addFirst(Object o) { + + } + + public void addLast(Object o) { + + } + + public Object removeFirst() { + return null; + } + + public Object removeLast() { + return null; + } + + public Iterator iterator() { + return null; + } + + private static class Node { + Object data; + Node next; + + } + + /** + * 把该链表逆置 例如链表为 3->7->10 , 逆置后变为 10->7->3 + */ + public void reverse() { + + } + + /** + * 删除一个单链表的前半部分 例如:list = 2->5->7->8 , 删除以后的值为 7->8 如果list = 2->5->7->8->10 + * ,删除以后的值为7,8,10 + */ + public void removeFirstHalf() { + + } + + /** + * 从第i个元素开始, 删除length 个元素 , 注意i从0开始 + * + * @param i + * @param length + */ + public void remove(int i, int length) { + + } + + /** + * 假定当前链表和list均包含已升序排列的整数 从当前链表中取出那些list所指定的元素 例如当前链表 = + * 11->101->201->301->401->501->601->701 listB = 1->3->4->6 + * 返回的结果应该是[101,301,401,601] + * + * @param list + */ + public static int[] getElements(LinkedList list) { + return null; + } + + /** + * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 从当前链表中中删除在list中出现的元素 + * + * @param list + */ + + public void subtract(LinkedList list) { + + } + + /** + * 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同) + */ + public void removeDuplicateValues() { + + } + + /** + * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素) + * + * @param min + * @param max + */ + public void removeRange(int min, int max) { + + } + + /** + * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同) + * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列 + * + * @param list + */ + public LinkedList intersection(LinkedList list) { + return null; + } +} diff --git a/group26/2411685663/src/nishuibaichuan/homework/first/List.java b/group26/2411685663/src/nishuibaichuan/homework/first/List.java new file mode 100644 index 0000000000..ca9279d5fc --- /dev/null +++ b/group26/2411685663/src/nishuibaichuan/homework/first/List.java @@ -0,0 +1,13 @@ +package nishuibaichuan.homework.first; + +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/group26/2411685663/src/nishuibaichuan/homework/first/Queue.java b/group26/2411685663/src/nishuibaichuan/homework/first/Queue.java new file mode 100644 index 0000000000..cf7798678d --- /dev/null +++ b/group26/2411685663/src/nishuibaichuan/homework/first/Queue.java @@ -0,0 +1,19 @@ +package nishuibaichuan.homework.first; + +public class Queue { + + public void enQueue(Object o) { + } + + public Object deQueue() { + return null; + } + + public boolean isEmpty() { + return false; + } + + public int size() { + return -1; + } +} diff --git a/group26/2411685663/src/nishuibaichuan/homework/first/Stack.java b/group26/2411685663/src/nishuibaichuan/homework/first/Stack.java new file mode 100644 index 0000000000..8d9a2f8a0a --- /dev/null +++ b/group26/2411685663/src/nishuibaichuan/homework/first/Stack.java @@ -0,0 +1,24 @@ +package nishuibaichuan.homework.first; + +public class Stack { + private ArrayList elementData = new ArrayList(); + + public void push(Object o) { + } + + public Object pop() { + return null; + } + + public Object peek() { + return null; + } + + public boolean isEmpty() { + return false; + } + + public int size() { + return -1; + } +} diff --git a/group26/2411685663/src/nishuibaichuan/homework/first/TestArrayList.java b/group26/2411685663/src/nishuibaichuan/homework/first/TestArrayList.java new file mode 100644 index 0000000000..b992de37ee --- /dev/null +++ b/group26/2411685663/src/nishuibaichuan/homework/first/TestArrayList.java @@ -0,0 +1,48 @@ +package nishuibaichuan.homework.first; + +import static org.junit.Assert.*; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @Desc: () + * @date: 2017年3月12日 下午7:00:22 + * @email:2411685663@qq.com + */ +@SuppressWarnings("unused") +public class TestArrayList { + + private ArrayList arrayList = new ArrayList(); + + @Test + public void testAll() { + arrayList.add(0); + arrayList.add(1); + arrayList.add(2); + arrayList.add(3); + arrayList.add(4); + arrayList.add(5); + arrayList.add(6); + + Assert.assertEquals(arrayList.size(), 7); + Assert.assertEquals(arrayList.get(1), 1); + System.out.println(arrayList.get(3)); + + arrayList.add(0, 100); + Assert.assertEquals(arrayList.size(), 8); + Assert.assertEquals(arrayList.get(0), 100); + + arrayList.remove(0); + Assert.assertEquals(arrayList.size(), 7); + Assert.assertEquals(arrayList.get(0), 0); + + Iterator iterator = arrayList.iterator(); + while(iterator.hasNext()){ + iterator.next(); + iterator.remove(); + } + Assert.assertEquals(arrayList.size(), 0); + } + +} diff --git "a/group26/26\347\273\204\346\203\205\345\206\265\347\273\237\350\256\241.md" "b/group26/26\347\273\204\346\203\205\345\206\265\347\273\237\350\256\241.md" index 8700b37aaf..a38b933f0f 100644 --- "a/group26/26\347\273\204\346\203\205\345\206\265\347\273\237\350\256\241.md" +++ "b/group26/26\347\273\204\346\203\205\345\206\265\347\273\237\350\256\241.md" @@ -1,10 +1,23 @@ -| | | | | | | | | | | | -| -------- | ---------------- | ----- | --------- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | -| 抓狂 | 作业1 | 作业2 | 作业3完成100% | | | | | | | | -| | 文章1 | | | | | | | | | | -| JEE-逆水百川 | 已完成 | 完成90% | | | | | | | | | -| | 百度 www.baidu.com | | | | | | | | | | -| | | | | | | | | | | | -| | | | | | | | | | | | -| | | | | | | | | | | | -| | | | | | | | | | | | \ No newline at end of file +| | | | | | | +| -------------------- | :--------------------------------------: | ---- | ---- | ---- | ---- | +| 抓狂 | 作业1 | | | | | +| | 文章1 | | | | | +| 723161901 | 已完成 | | | | | +| | | | | | | +| jiaxun1990(89460886) | 已完成 | | | | | +| | https://goo.gl/Wvz3Od | | | | | +| 1515345281 | 已完成 | | | | | +| | | | | | | +| 2070509107 | 已完成 | | | | | +| | | | | | | +| lizhy2017 | 部分完成 | | | | | +| | | | | | | +| JEE-逆水百川 | 部分完成 | | | | | +| | http://blog.csdn.net/u012759397/article/details/61618612 | | | | | +| | | | | | | +| | | | | | | +| | | | | | | +| | | | | | | +| | | | | | | +| | | | | | | +| | | | | | | \ No newline at end of file diff --git a/group26/mahone2017/123.txt b/group26/mahone2017/123.txt deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/ArrayList.java b/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/ArrayList.java new file mode 100644 index 0000000000..13c251ffe9 --- /dev/null +++ b/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/ArrayList.java @@ -0,0 +1,102 @@ +package zhuakuang.homework.first.Collection; + +import java.util.Arrays; + +public class ArrayList implements List, Iterable { + + private int size = 0; + + private Object[] elementData = new Object[10]; + + public void add(Object o) { + ensureCapacity(size + 1); + elementData[size] = o; + size++; + } + + /** + * 插入 + * + * @param index + * @param o + */ + public void add(int index, Object o) { + if (index > size || index < 0) { + throw new IndexOutOfBoundsException("index" + index + "越界"); + } + ensureCapacity(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 oldValue = elementData[index]; + + int numMoved = size - index - 1; + if (numMoved > 0) { + System.arraycopy(elementData, index + 1, elementData, index, + numMoved); + } + elementData[--size] = null;// GC + return oldValue; + } + + private void checkIndex(int index) { + if (index >= size || index < 0) { + throw new IndexOutOfBoundsException("index" + index + "越界"); + } + } + + public int size() { + return size; + } + + public Iterator iterator() { + return new Itr(); + } + + private class Itr implements Iterator { + int cursor = 0; + + @Override + public boolean hasNext() { + if (cursor < size) { + return true; + }// + return false; + } + + @Override + public Object next() { + int nowCursor = cursor; + cursor++; + return elementData[nowCursor]; + } + } + + + public void ensureCapacity(int minCapacity) { + int oldCapacity = elementData.length; + if (minCapacity > oldCapacity) { + int newCapacity = (oldCapacity * 3) / 2 + 1; // oldCapacity 的 1.5 倍(取整)+ 1 + if (newCapacity < minCapacity) { + newCapacity = minCapacity; + } + // Arrays.copyOf 功能:把一个数组复制到另一个数组,返回值就是另一个数组。 + // 第一参数是被拷贝参数,第二个参数是返回的新数组的长度。 + // 如果新数组的长度超过原数组的长度,则保留数组默认值。 + // 如果新数组的长度小于原数组的长度,则多出的部分不保留。 + elementData = Arrays.copyOf(elementData, newCapacity); + } + } + + +} diff --git a/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/BinaryTreeNode.java b/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/BinaryTreeNode.java new file mode 100644 index 0000000000..974f6418fb --- /dev/null +++ b/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/BinaryTreeNode.java @@ -0,0 +1,35 @@ +package zhuakuang.homework.first.Collection; + +/** + * 二叉树 + */ +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/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/Iterator.java b/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/Iterator.java new file mode 100644 index 0000000000..0f806b8788 --- /dev/null +++ b/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/Iterator.java @@ -0,0 +1,10 @@ +package zhuakuang.homework.first.Collection; + +public interface Iterator extends java.util.Iterator { + public boolean hasNext(); + public Object next(); + + + //void remove(); + +} diff --git a/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/LinkedList.java b/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/LinkedList.java new file mode 100644 index 0000000000..692951f698 --- /dev/null +++ b/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/LinkedList.java @@ -0,0 +1,134 @@ +package zhuakuang.homework.first.Collection; + +public class LinkedList implements List { + + private Node head; + private Node tail; + + public void add(Object o) { + + } + + public void add(int index, Object o) { + + } + + public Object get(int index) { + return null; + } + + public Object remove(int index) { + return null; + } + + public int size() { + return -1; + } + + public void addFirst(Object o) { + + } + + public void addLast(Object o) { + + } + + public Object removeFirst() { + return null; + } + + public Object removeLast() { + return null; + } + + public Iterator iterator() { + return null; + } + + + private static class Node { + Object data; + Node next; + + } + + /** + * 把该链表逆置 + * 例如链表为 3->7->10 , 逆置后变为 10->7->3 + */ + public void reverse() { + + } + + /** + * 删除一个单链表的前半部分 + * 例如:list = 2->5->7->8 , 删除以后的值为 7->8 + * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10 + */ + public void removeFirstHalf() { + + } + + /** + * 从第i个元素开始, 删除length 个元素 , 注意i从0开始 + * + * @param i + * @param length + */ + public void remove(int i, int length) { + + } + + /** + * 假定当前链表和listB均包含已升序排列的整数 + * 从当前链表中取出那些listB所指定的元素 + * 例如当前链表 = 11->101->201->301->401->501->601->701 + * listB = 1->3->4->6 + * 返回的结果应该是[101,301,401,601] + * + * @param list + */ + public int[] getElements(LinkedList list) { + return null; + } + + /** + * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 从当前链表中中删除在listB中出现的元素 + * + * @param list + */ + + public void subtract(LinkedList list) { + + } + + /** + * 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同) + */ + public void removeDuplicateValues() { + + } + + /** + * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素) + * + * @param min + * @param max + */ + public void removeRange(int min, int max) { + + } + + /** + * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同) + * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列 + * + * @param list + */ + public LinkedList intersection(LinkedList list) { + return null; + } +} diff --git a/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/List.java b/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/List.java new file mode 100644 index 0000000000..26b05377a6 --- /dev/null +++ b/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/List.java @@ -0,0 +1,10 @@ +package zhuakuang.homework.first.Collection; + +public interface List extends Iterable { + 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(); + Iterator iterator(); +} diff --git a/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/Queue.java b/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/Queue.java new file mode 100644 index 0000000000..7a1c8681a5 --- /dev/null +++ b/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/Queue.java @@ -0,0 +1,19 @@ +package zhuakuang.homework.first.Collection; + +public class Queue { + + public void enQueue(Object o) { + } + + public Object deQueue() { + return null; + } + + public boolean isEmpty() { + return false; + } + + public int size() { + return -1; + } +} diff --git a/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/Stack.java b/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/Stack.java new file mode 100644 index 0000000000..ed39665be1 --- /dev/null +++ b/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/Stack.java @@ -0,0 +1,22 @@ +package zhuakuang.homework.first.Collection; +import java.util.ArrayList; +public class Stack { + private ArrayList elementData = new ArrayList(); + + public void push(Object o){ + } + + public Object pop(){ + return null; + } + + public Object peek(){ + return null; + } + public boolean isEmpty(){ + return false; + } + public int size(){ + return -1; + } +} diff --git a/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/TestCollection.java b/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/TestCollection.java new file mode 100644 index 0000000000..9e953df486 --- /dev/null +++ b/group26/zhuakuang2017/src/zhuakuang/homework/first/Collection/TestCollection.java @@ -0,0 +1,41 @@ +package zhuakuang.homework.first.Collection; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Created by BlindingDark on 2017/3/11 0011. + */ +public class TestCollection { + @Test + public void arrayListTest() {//分开测试每一个方法 List test + ArrayList myArrayList = new ArrayList(); + + myArrayList.add("1"); + myArrayList.add("2"); + myArrayList.add("3"); + myArrayList.add("4"); + myArrayList.add("5"); + myArrayList.add("6"); + myArrayList.add("7"); + myArrayList.add("8"); + myArrayList.add("9"); + myArrayList.add("10"); + myArrayList.add("11"); + myArrayList.add("12"); + + myArrayList.add(2, "2.5"); + myArrayList.remove(1); + + String first = String.valueOf(Integer.valueOf((String) myArrayList.get(2)) - 2); + String[] strs = {first, "2.5", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}; + + Iterator itr = myArrayList.iterator(); + while (itr.hasNext()) { + for (int i = 0; i < myArrayList.size(); i++) { + assertEquals(strs[i], itr.next()); + } + } + } +} diff --git a/group26/zhuakuang2017/src/zhuakuang/homework/first/Main.java b/group26/zhuakuang2017/src/zhuakuang/homework/first/Main.java deleted file mode 100644 index 9f3d7e846c..0000000000 --- a/group26/zhuakuang2017/src/zhuakuang/homework/first/Main.java +++ /dev/null @@ -1,7 +0,0 @@ -package zhuakuang.homework.first; - -public class Main { - public static void main(String[] args) { - System.out.println(1); - } -}