From 18ad855f2b55d230141acccaac3091256a1d7c1d Mon Sep 17 00:00:00 2001 From: unknown <箜想> Date: Tue, 14 Mar 2017 14:18:47 +0800 Subject: [PATCH] =?UTF-8?q?77253242=5F=E6=8F=90=E4=BA=A4=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../77253242/coding2017/src/ArrayList.java | 74 ++++++ .../coding2017/src/BinaryTreeNode.java | 33 +++ group22/77253242/coding2017/src/Iterator.java | 9 + .../77253242/coding2017/src/LinkedList.java | 238 ++++++++++++++++++ group22/77253242/coding2017/src/List.java | 10 + group22/77253242/coding2017/src/Main.java | 9 + group22/77253242/coding2017/src/Queue.java | 25 ++ group22/77253242/coding2017/src/Stack.java | 34 +++ 9 files changed, 433 insertions(+) create mode 100644 group22/77253242/coding2017/src/ArrayList.java create mode 100644 group22/77253242/coding2017/src/BinaryTreeNode.java create mode 100644 group22/77253242/coding2017/src/Iterator.java create mode 100644 group22/77253242/coding2017/src/LinkedList.java create mode 100644 group22/77253242/coding2017/src/List.java create mode 100644 group22/77253242/coding2017/src/Main.java create mode 100644 group22/77253242/coding2017/src/Queue.java create mode 100644 group22/77253242/coding2017/src/Stack.java diff --git a/.gitignore b/.gitignore index 793b2e270c..a697b49249 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ target group22/1193590951/githubitem/.project *.prefs group22/1193590951/githubitem/bin/文章地址.txt +!.gitignore \ No newline at end of file diff --git a/group22/77253242/coding2017/src/ArrayList.java b/group22/77253242/coding2017/src/ArrayList.java new file mode 100644 index 0000000000..c911129893 --- /dev/null +++ b/group22/77253242/coding2017/src/ArrayList.java @@ -0,0 +1,74 @@ +import javax.swing.plaf.basic.BasicTreeUI; +import java.security.SignatureException; +import java.util.Arrays; + +/** + * Created by fantasy on 2017-03-13. + */ + +public class ArrayList implements List { + + private int size = 0; + + private Object[] elementData = new Object[10]; + + public void add(Object o) { + if(size >= elementData.length) + { + elementData= Arrays.copyOf(elementData, size+10); + } + elementData [++size] = o; + } + + public void add(int index, Object o) { + if(size >= elementData.length) + { + elementData = new Object[size + 10]; + } + if(size > index) + { + elementData[++size] = o; + } + else + { + for(int i = size;i>index;i--) + { + elementData [i + 1] = elementData [i]; + } + } + elementData [index] = o; + size++; + } + + public Object get(int index) { + if(index < 0 || index > size) + { + throw new IndexOutOfBoundsException("size:" + size + ",index:"+index); + } + return elementData[size]; + } + + public Object remove(int index) { + if(size > index) + { + Object OldValue = elementData[index]; + for(int i = index;i<= size;) + { + elementData[i] = elementData[++i]; + } + return OldValue; + } + throw new IndexOutOfBoundsException("size:"+ size + ",index:" + index); + } + + + public int size() { + return size; + } + + public Iterator iterator() { + return null; + } + + +} \ No newline at end of file diff --git a/group22/77253242/coding2017/src/BinaryTreeNode.java b/group22/77253242/coding2017/src/BinaryTreeNode.java new file mode 100644 index 0000000000..20b7dd99fb --- /dev/null +++ b/group22/77253242/coding2017/src/BinaryTreeNode.java @@ -0,0 +1,33 @@ +/** + * Created by fantasy on 2017-03-13. + */ +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/group22/77253242/coding2017/src/Iterator.java b/group22/77253242/coding2017/src/Iterator.java new file mode 100644 index 0000000000..5d970abec8 --- /dev/null +++ b/group22/77253242/coding2017/src/Iterator.java @@ -0,0 +1,9 @@ +/** + * Created by fantasy on 2017-03-13. + */ + +public interface Iterator { + public boolean hasNext(); + public Object next(); + +} diff --git a/group22/77253242/coding2017/src/LinkedList.java b/group22/77253242/coding2017/src/LinkedList.java new file mode 100644 index 0000000000..e9fd8547d7 --- /dev/null +++ b/group22/77253242/coding2017/src/LinkedList.java @@ -0,0 +1,238 @@ +import java.net.IDN; + +public class LinkedList implements List { + + private Node head; + + private Node firstNode; + private Node lastNode; + private int size = 0; + + + public void add(Object o){ + linkLast(o); + + } + public void add(int index , Object o){ + if(index > size()) + { + throw new IndexOutOfBoundsException("index:"+ index + ",size:"+ size()); + } + if(size == 0) + { + linkLast(o); + } + else + { + Node node = node(index); + Node newNode = new Node(o,node.prev,node); + node.setPrev(newNode); + } + ++size; + } + public Object get(int index){ + return node(index).getData(); + } + public Object remove(int index){ + if(index >size()) + { + throw new IndexOutOfBoundsException("index:"+ index + ",size:"+ size()); + } + Node node = node(index); + node.prev.next = node.next; + node.next.prev = node.prev; + --size; + return node; + } + + public int size(){ + return size; + } + + public void addFirst(Object o){ + linkLast(o); + } + public void addLast(Object o){ + if(lastNode == null) + { + lastNode = new Node(o,firstNode,null); + } + else + { + Node node = lastNode; + node.next = new Node(o,node,null); + lastNode = node.next; + } + ++size; + } + public Object removeFirst(){ + if(size > 0 ) + { + Node node = firstNode; + firstNode = node.next; + --size; + return node.getData(); + } + return null; + } + public Object removeLast(){ + if(size > 0 ) + { + Node node = lastNode; + lastNode = node.prev; + --size; + return node.getData(); + } + return null; + } + public Iterator iterator(){ + return null; + } + + LinkedList.Node node(int index) + { + if(index < size()) + { + Node node = firstNode; + for(int i=0;i7->10 , 逆置后变为 10->7->3 + */ + public void reverse(){ + for(int i=0;i5->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; + } +} \ No newline at end of file diff --git a/group22/77253242/coding2017/src/List.java b/group22/77253242/coding2017/src/List.java new file mode 100644 index 0000000000..c4e9df138a --- /dev/null +++ b/group22/77253242/coding2017/src/List.java @@ -0,0 +1,10 @@ +/** + * Created by fantasy on 2017-03-13. + */ +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/group22/77253242/coding2017/src/Main.java b/group22/77253242/coding2017/src/Main.java new file mode 100644 index 0000000000..1f5e6bdd9c --- /dev/null +++ b/group22/77253242/coding2017/src/Main.java @@ -0,0 +1,9 @@ +import java.util.*; +import java.util.LinkedList; + +public class Main { + + public static void main(String[] args) { + System.out.println("Hello World!"); + } +} diff --git a/group22/77253242/coding2017/src/Queue.java b/group22/77253242/coding2017/src/Queue.java new file mode 100644 index 0000000000..4e0fe62925 --- /dev/null +++ b/group22/77253242/coding2017/src/Queue.java @@ -0,0 +1,25 @@ +import java.awt.image.AreaAveragingScaleFilter; + +/** + * Created by fantasy on 2017-03-13. + */ +public class Queue { + ArrayList arrayList = new ArrayList(); + + + public void enQueue(Object o){ + arrayList.add(o); + } + + public Object deQueue(){ + return arrayList.remove(0); + } + + public boolean isEmpty(){ + return !(arrayList.size() >0); + } + + public int size(){ + return arrayList.size(); + } +} \ No newline at end of file diff --git a/group22/77253242/coding2017/src/Stack.java b/group22/77253242/coding2017/src/Stack.java new file mode 100644 index 0000000000..d203b6ba29 --- /dev/null +++ b/group22/77253242/coding2017/src/Stack.java @@ -0,0 +1,34 @@ +import java.util.EmptyStackException; + +/** + * Created by fantasy on 2017-03-13. + */ +public class Stack { + private ArrayList elementData = new ArrayList(); + + public void push(Object o){ + elementData.add(o); + } + + public Object pop(){ + if(elementData.size() == 0) + { + return elementData.remove(elementData.size() - 1 ); + } + return null; + } + + public Object peek(){ + if(elementData.size() == 0 ) + { + return elementData.get(elementData.size() - 1); + } + throw new EmptyStackException(); + } + public boolean isEmpty(){ + return !(elementData.size()>0); + } + public int size(){ + return elementData.size(); + } +}