From a8dd0846b77eeeb0b5592318071b4ffe33355d83 Mon Sep 17 00:00:00 2001 From: shaofriend <452472201@qq.com> Date: Sun, 26 Feb 2017 15:43:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/SinglyLinkedList/LinkedList0.java | 75 ------ .../src/SinglyLinkedList2/LinkedList1.java | 242 ------------------ group20/286166752/.gitignore | 4 - .../liven/code/dataStructures/ArrayList.java | 86 ------- .../liven/code/dataStructures/LinkedList.java | 40 --- .../wiki/liven/code/dataStructures/List.java | 14 - .../wiki/liven/code/dataStructures/Queue.java | 7 - .../wiki/liven/code/dataStructures/Stack.java | 7 - .../src/wiki/liven/code/test/SomeDemos.java | 15 -- .../src/com/coding/basic/ArrayList.java | 32 --- .../src/com/coding/basic/BinaryTreeNode.java | 32 --- .../src/com/coding/basic/Iterator.java | 7 - .../src/com/coding/basic/LinkedList.java | 46 ---- .../423184723/src/com/coding/basic/List.java | 9 - .../423184723/src/com/coding/basic/Queue.java | 19 -- .../423184723/src/com/coding/basic/Stack.java | 22 -- .../src/com/coding/basic/ArrayList.java | 34 ++- .../src/com/coding/basic/LinkedList.java | 32 ++- .../452472201/src/com/coding/basic/Queue.java | 3 +- .../452472201/src/com/coding/basic/Stack.java | 27 +- ...2\345\256\242\351\223\276\346\216\245.txt" | 1 + 21 files changed, 70 insertions(+), 684 deletions(-) delete mode 100644 group20/1040154728/1040154728Learning/src/SinglyLinkedList/LinkedList0.java delete mode 100644 group20/1040154728/1040154728Learning/src/SinglyLinkedList2/LinkedList1.java delete mode 100644 group20/286166752/.gitignore delete mode 100644 group20/286166752/src/wiki/liven/code/dataStructures/ArrayList.java delete mode 100644 group20/286166752/src/wiki/liven/code/dataStructures/LinkedList.java delete mode 100644 group20/286166752/src/wiki/liven/code/dataStructures/List.java delete mode 100644 group20/286166752/src/wiki/liven/code/dataStructures/Queue.java delete mode 100644 group20/286166752/src/wiki/liven/code/dataStructures/Stack.java delete mode 100644 group20/286166752/src/wiki/liven/code/test/SomeDemos.java delete mode 100644 group20/423184723/src/com/coding/basic/ArrayList.java delete mode 100644 group20/423184723/src/com/coding/basic/BinaryTreeNode.java delete mode 100644 group20/423184723/src/com/coding/basic/Iterator.java delete mode 100644 group20/423184723/src/com/coding/basic/LinkedList.java delete mode 100644 group20/423184723/src/com/coding/basic/List.java delete mode 100644 group20/423184723/src/com/coding/basic/Queue.java delete mode 100644 group20/423184723/src/com/coding/basic/Stack.java create mode 100644 "group20/452472201/src/com/coding/basic/\345\215\232\345\256\242\351\223\276\346\216\245.txt" diff --git a/group20/1040154728/1040154728Learning/src/SinglyLinkedList/LinkedList0.java b/group20/1040154728/1040154728Learning/src/SinglyLinkedList/LinkedList0.java deleted file mode 100644 index 7cdf1e7f26..0000000000 --- a/group20/1040154728/1040154728Learning/src/SinglyLinkedList/LinkedList0.java +++ /dev/null @@ -1,75 +0,0 @@ -package SinglyLinkedList; - -/** - * Created by Honoka on 2/16/2017. - */ -public class LinkedList0 { - //Node class represents a list node - private class Node - { - String value; - Node next; - /** - * Constructor - * @param val The element to store in this node. - * @param n The reference to the next node. - */ - Node (String val, Node n) - { - value = val; - next = n; - } - - /** - * Constructor - * @param val The element to store in this node. - */ - Node(String val) - { - value = val; - next = null; - } - } - //Reference to the first node in the list - private Node first = null; - /** - * Constructor - * Builds a linked list - */ - public LinkedList0() - { - //test - first = new Node("Apple"); - first.next = new Node("Peach"); - first.next.next = new Node("Kiwi"); - first = new Node("Blueberry",first); - - //Using an array to add elements into list - String[] fruits = {"Banana", "Cherry"}; - for (String f : fruits) - { - first = new Node(f, first); - } - } - /** - * print method - * traverses the list and prints all elements - */ - public void print() - { - Node reference = first; - while(reference != null) - { - System.out.println(reference.value + " "); - reference = reference.next; - } - } - - //Main test method - public static void main(String [] args) - { - LinkedList0 list = new LinkedList0(); - System.out.println("The elements inside this list are "); - list.print(); - } -} diff --git a/group20/1040154728/1040154728Learning/src/SinglyLinkedList2/LinkedList1.java b/group20/1040154728/1040154728Learning/src/SinglyLinkedList2/LinkedList1.java deleted file mode 100644 index 8c93bbc640..0000000000 --- a/group20/1040154728/1040154728Learning/src/SinglyLinkedList2/LinkedList1.java +++ /dev/null @@ -1,242 +0,0 @@ -package SinglyLinkedList2; -/** - * Created by Honoka on 2/16/2017. - */ -public class LinkedList1 { - private class Node - { - String value; - Node next; - - Node(String val, Node n) - { - value = val; - next = n; - } - Node(String val) - { - //Call the other(daddy(or sister(whatever))) constructor. - this(val, null); - } - } - - private Node first; // head - private Node last; //the last element in list - - public LinkedList1() - { - first = null; - last = null; - } - - /**This method checks to see - * if the list is empty - * @return true if list is empty - */ - public boolean isEmpty() - { - return first == null; - } - - /** - * size method returns the length of the list - * @return The number of the elements in the list - */ - public int size() - { - int counter = 0; - Node p = first; - while (p != null) - { - counter ++; - p = p.next; - } - return counter; - } - - /** - * add method add an element to the end of the list - * @param element the value to add - */ - public void add(String element) - { - if (isEmpty()) - { - //Obviously, add the element to the first position in the list - first = new Node(element); - last = first; - } - else - { - //add to the end of existing list - last.next = new Node(element); - last = last.next; - } - } - - /** - * add method, or you might call it insert method since it can - * add element to a specific position - * @param index The position at which to add the element - * @param element you should know what is this - */ - public void add (int index, String element) - { - if (index < 0 || index > size()) - { - String message = String.valueOf(index); - throw new IndexOutOfBoundsException(message); - } - - //index is at least 0 - if(index == 0) - { - //new element add to the head - first = new Node(element, first); - if (last == null) - { - last = first; - } - return; - } - //set a reference predecessor to point to the node that - //will be the predecessor of the new node - Node predecessor = first; - for (int k = 1; k <= index - 1; k++) - { - predecessor = predecessor.next; - } - //Splice in a node containing the new element - predecessor.next = new Node(element, predecessor.next); - - //if there is a new last element - if(predecessor.next.next == null) - last = predecessor.next; - } - - /** - * toString method, like print method, hopefully it will display the contents of the list - * @return say something I'm giving up on you( - */ - public String toString() - { - StringBuffer strBuilder = new StringBuffer(); - //Use p to walk down the list - Node p = first; - while (p != null) - { - strBuilder.append(p.value + "\n"); - p = p.next; - } - return strBuilder.toString(); - } - - /** - * remove method removes the element with the position you want - * @param index the position of the element that you want to remove - * @return the removed element - */ - public String remove (int index) - { - /* Index out of bounds */ - if (index < 0 || index >= size()) - { - String message = String.valueOf(index); - throw new IndexOutOfBoundsException(message); - } - String element = null; - if(index == 0) - { - //Removal of first item in the list - element = first.value; - first = first.next; - if (first == null) - { - last = null; - } - } - else - { - /* find the predecessor of the element to be removed */ - Node predecessor = first; - - /* Move predecessor forward index - 1 times */ - for (int k = 1; k <= index - 1; k++) - { - predecessor = predecessor.next; - /* Store the value to return */ - element = predecessor.next.value; - /* Route link around the node to be removed */ - predecessor.next = predecessor.next.next; - /* Check if predecessor is now last */ - if(predecessor.next == null) - { - last = predecessor; - } - } - } - return element; - } - - /** - * The remove method removes an element - * @param element the element to remove - * @return true if the remove succeeded - */ - public boolean remove(String element) - { - if (isEmpty()) - { - return false; - } - - if (element.equals(first.value)) - { - //Removal of first element in the list - first = first.next; - if(first == null) - { - last = null; - } - return true; - } - - /* Find the predecessor of the element to remove */ - Node predecessor = first; - while (predecessor.next != null && - !predecessor.next.value.equals(element)) - { - predecessor = predecessor.next; - } - /* predecessor.next == null OR predecessor.next.value is element */ - if(predecessor.next == null) - { - return false; - } - /* predecessor.next.value is element */ - predecessor.next = predecessor.next.next; - - /* check if predecessor is now last */ - if (predecessor.next == null) - { - last = predecessor; - } - return true; - } - - public static void main (String [] args) - { - LinkedList1 testList = new LinkedList1(); - testList.add("Apple"); - testList.add("Banana"); - testList.add(0,"Blueberry"); - testList.add(2,"Cherry"); - testList.add(4,"Peach"); - System.out.println("The list has : "); - System.out.println(testList); - testList.remove("Cherry"); - testList.remove(2); - System.out.println("The list has : "); - System.out.println(testList); - } -} diff --git a/group20/286166752/.gitignore b/group20/286166752/.gitignore deleted file mode 100644 index d120d1749d..0000000000 --- a/group20/286166752/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.idea/ -286166752.iml -out/ - diff --git a/group20/286166752/src/wiki/liven/code/dataStructures/ArrayList.java b/group20/286166752/src/wiki/liven/code/dataStructures/ArrayList.java deleted file mode 100644 index 68444b87a9..0000000000 --- a/group20/286166752/src/wiki/liven/code/dataStructures/ArrayList.java +++ /dev/null @@ -1,86 +0,0 @@ -package wiki.liven.code.dataStructures; - -/** - * Created by leven on 2017/2/21. - */ -public class ArrayList implements List{ - - /** - * 列表中元素的个数 - */ - private int size = 0; - private int maxSize = 100; - /** - * 初始数组 - */ - private Object[] elementData = new Object[maxSize]; - - /** - * 在指定的位置i插入元素O - * 插入元素,判断当前列表中元素的个数, - * 当size==100,则需要扩张数组 - * 当size<100,则使用初始数组完成插入操作 - * 插入操作: - * 从最后一个元素开始,往后移动一位,直到到index为止. - * @param index - * @param o - */ - @Override - public void add(int index, Object o) { - if (size>=maxSize){ - Object[] targt = new Object[++maxSize]; - System.arraycopy(elementData,0,targt,0,maxSize); - for (int j = targt.length;j>=index;j--){ - targt[j-1] = targt[j-2]; - } - targt[index] = o; - size++; - }else if(size=index;j--){ - elementData[j-1] = elementData[j-2]; - } - elementData[index] = o; - size++; - } - } - - /** - * 追加元素 - * @param o - */ - @Override - public void add(Object o) { - if (size>=maxSize){ - Object[] targt = new Object[++maxSize]; - System.arraycopy(elementData,0,targt,0,maxSize); - targt[maxSize-1] = o; - size++; - }else if(sizesize-1;i++){ - elementData[i] = elementData[i+1]; - } - return temp; - } - - @Override - public int size() { - return size; - } - - - - -} diff --git a/group20/286166752/src/wiki/liven/code/dataStructures/LinkedList.java b/group20/286166752/src/wiki/liven/code/dataStructures/LinkedList.java deleted file mode 100644 index b2cc5f8668..0000000000 --- a/group20/286166752/src/wiki/liven/code/dataStructures/LinkedList.java +++ /dev/null @@ -1,40 +0,0 @@ -package wiki.liven.code.dataStructures; - -/** - * Created by leven on 2017/2/21. - */ -public class LinkedList implements List{ - - private Node head; - - private static class Node{ - Object data; - Node next; - } - - - @Override - public void add(int index, Object o) { - - } - - @Override - public void add(Object o) { - - } - - @Override - public Object get(int index) { - return null; - } - - @Override - public Object remove(int index) { - return null; - } - - @Override - public int size() { - return 0; - } -} diff --git a/group20/286166752/src/wiki/liven/code/dataStructures/List.java b/group20/286166752/src/wiki/liven/code/dataStructures/List.java deleted file mode 100644 index 2d1840ef0f..0000000000 --- a/group20/286166752/src/wiki/liven/code/dataStructures/List.java +++ /dev/null @@ -1,14 +0,0 @@ -package wiki.liven.code.dataStructures; - -/** - * Created by leven on 2017/2/21. - */ -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/group20/286166752/src/wiki/liven/code/dataStructures/Queue.java b/group20/286166752/src/wiki/liven/code/dataStructures/Queue.java deleted file mode 100644 index b8c8430daa..0000000000 --- a/group20/286166752/src/wiki/liven/code/dataStructures/Queue.java +++ /dev/null @@ -1,7 +0,0 @@ -package wiki.liven.code.dataStructures; - -/** - * Created by leven on 2017/2/21. - */ -public class Queue { -} diff --git a/group20/286166752/src/wiki/liven/code/dataStructures/Stack.java b/group20/286166752/src/wiki/liven/code/dataStructures/Stack.java deleted file mode 100644 index 59cb18c416..0000000000 --- a/group20/286166752/src/wiki/liven/code/dataStructures/Stack.java +++ /dev/null @@ -1,7 +0,0 @@ -package wiki.liven.code.dataStructures; - -/** - * Created by leven on 2017/2/21. - */ -public class Stack { -} diff --git a/group20/286166752/src/wiki/liven/code/test/SomeDemos.java b/group20/286166752/src/wiki/liven/code/test/SomeDemos.java deleted file mode 100644 index 90a74edc35..0000000000 --- a/group20/286166752/src/wiki/liven/code/test/SomeDemos.java +++ /dev/null @@ -1,15 +0,0 @@ -package wiki.liven.code.test; - -/** - * Created by leven on 2017/2/21. - */ -public class SomeDemos { - - public static void main(String[] args){ - int[] a = new int[10]; - a[0] = 4; - System.out.println(a.length); - - } - -} diff --git a/group20/423184723/src/com/coding/basic/ArrayList.java b/group20/423184723/src/com/coding/basic/ArrayList.java deleted file mode 100644 index 1f185736f9..0000000000 --- a/group20/423184723/src/com/coding/basic/ArrayList.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.coding.basic; - -public class ArrayList implements List { - - private int size = 0; - - private Object[] elementData = new Object[100]; - - 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 Iterator iterator(){ - return null; - } - -} diff --git a/group20/423184723/src/com/coding/basic/BinaryTreeNode.java b/group20/423184723/src/com/coding/basic/BinaryTreeNode.java deleted file mode 100644 index d7ac820192..0000000000 --- a/group20/423184723/src/com/coding/basic/BinaryTreeNode.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.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/group20/423184723/src/com/coding/basic/Iterator.java b/group20/423184723/src/com/coding/basic/Iterator.java deleted file mode 100644 index 06ef6311b2..0000000000 --- a/group20/423184723/src/com/coding/basic/Iterator.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.coding.basic; - -public interface Iterator { - public boolean hasNext(); - public Object next(); - -} diff --git a/group20/423184723/src/com/coding/basic/LinkedList.java b/group20/423184723/src/com/coding/basic/LinkedList.java deleted file mode 100644 index e2c4e5e795..0000000000 --- a/group20/423184723/src/com/coding/basic/LinkedList.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.coding.basic; - -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; - - } -} diff --git a/group20/423184723/src/com/coding/basic/List.java b/group20/423184723/src/com/coding/basic/List.java deleted file mode 100644 index 10d13b5832..0000000000 --- a/group20/423184723/src/com/coding/basic/List.java +++ /dev/null @@ -1,9 +0,0 @@ -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/group20/423184723/src/com/coding/basic/Queue.java b/group20/423184723/src/com/coding/basic/Queue.java deleted file mode 100644 index 36e516e266..0000000000 --- a/group20/423184723/src/com/coding/basic/Queue.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.coding.basic; - -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/group20/423184723/src/com/coding/basic/Stack.java b/group20/423184723/src/com/coding/basic/Stack.java deleted file mode 100644 index a5a04de76d..0000000000 --- a/group20/423184723/src/com/coding/basic/Stack.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.coding.basic; - -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/group20/452472201/src/com/coding/basic/ArrayList.java b/group20/452472201/src/com/coding/basic/ArrayList.java index 1af26ce934..80746f1675 100644 --- a/group20/452472201/src/com/coding/basic/ArrayList.java +++ b/group20/452472201/src/com/coding/basic/ArrayList.java @@ -4,10 +4,9 @@ public class ArrayList implements List { private int size=0; - private Object[] elementData =new Object[10]; + private Object[] elementData =new Object[5]; - //数组扩容 private void ensureCapacityInternal(){ if(size==elementData.length){ Object[] newArray = new Object[size*2]; @@ -33,8 +32,8 @@ public void add(int index, Object o){ } System.arraycopy(elementData, index, elementData, index+1,size-index ); - elementData[index]=o; - size++; + elementData[index]=o; + size++; } public Object get(int index){ @@ -75,24 +74,41 @@ public int size(){ private class Iter implements Iterator { - //计数器 + private int coursor=-1; - //判断是否存在下一个 + public boolean hasNext(){ return coursor+1