diff --git a/coding2017/group02/447809161Learning/src/com/github/hwjcc969/coding2017/basic/ArrayList.java b/coding2017/group02/447809161Learning/src/com/github/hwjcc969/coding2017/basic/ArrayList.java new file mode 100644 index 0000000000..c2acf20e4d --- /dev/null +++ b/coding2017/group02/447809161Learning/src/com/github/hwjcc969/coding2017/basic/ArrayList.java @@ -0,0 +1,62 @@ +package com.github.hwjcc969.coding2017.basic; + +import javax.lang.model.element.Element; + +public class ArrayList implements List { + + private int size = 0; + + private Object[] elementData = new Object[100]; + + public void add(Object o){ + if (o == null){ + throw new NullPointerException("空对象"); + } + if (size >= 100){ + throw new RuntimeException("越界"); + } + elementData[size] = o; + size++; + } + public void add(int index, Object o){ + if (o == null){ + throw new NullPointerException("空对象"); + } + if (index >= 99){ + throw new RuntimeException("越界"); + } + for (int i = size; i >= index; i--) { + elementData[i + 1] = elementData[i]; + } + elementData[index] = o; + size++; + } + + public Object get(int index){ + if (index >= 100 || index < 0){ + throw new RuntimeException("越界"); + } + return elementData[index]; + } + + public Object remove(int index){ + if (index >= 100 || index < 0){ + throw new RuntimeException("越界"); + } + Object o = elementData[index]; + for (int i = index; i < size - 1; i++) { + elementData[i] = elementData[i + 1]; + } + size--; + return null; + } + + public int size(){ + return size; + } + + public Iterator iterator(){ + return null; + } + +} diff --git a/coding2017/group02/447809161Learning/src/com/github/hwjcc969/coding2017/basic/BinaryTreeNode.java b/coding2017/group02/447809161Learning/src/com/github/hwjcc969/coding2017/basic/BinaryTreeNode.java new file mode 100644 index 0000000000..0381f88c69 --- /dev/null +++ b/coding2017/group02/447809161Learning/src/com/github/hwjcc969/coding2017/basic/BinaryTreeNode.java @@ -0,0 +1,32 @@ +package com.github.hwjcc969.coding2017.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/coding2017/group02/447809161Learning/src/com/github/hwjcc969/coding2017/basic/Iterator.java b/coding2017/group02/447809161Learning/src/com/github/hwjcc969/coding2017/basic/Iterator.java new file mode 100644 index 0000000000..0e8394844b --- /dev/null +++ b/coding2017/group02/447809161Learning/src/com/github/hwjcc969/coding2017/basic/Iterator.java @@ -0,0 +1,7 @@ +package com.github.hwjcc969.coding2017.basic; + +public interface Iterator { + public boolean hasNext(); + public Object next(); + +} diff --git a/coding2017/group02/447809161Learning/src/com/github/hwjcc969/coding2017/basic/LinkedList.java b/coding2017/group02/447809161Learning/src/com/github/hwjcc969/coding2017/basic/LinkedList.java new file mode 100644 index 0000000000..d000967c19 --- /dev/null +++ b/coding2017/group02/447809161Learning/src/com/github/hwjcc969/coding2017/basic/LinkedList.java @@ -0,0 +1,117 @@ +package com.github.hwjcc969.coding2017.basic; + +public class LinkedList implements List { + + private Node head; + private int size; + + public void add(Object o){ + Node newNode = new Node(o); + if (head == null) { + head = newNode; + } + else{ + Node last = head.next; + while (last != null){ + last = last.next; + } + last = newNode; + } + size++; + + } + public void add(int index , Object o){ + Node dummy = new Node(); + dummy.next = head; + Node pre = dummy; + while (index > 0) { + pre = pre.next; + } + Node cur = new Node(o); + cur.next = pre.next; + pre.next = cur; + size++; + } + public Object get(int index){ + Node cur = head; + while (index > 0 && cur != null) { + cur = cur.next; + } + return cur; + } + public Object remove(int index){ + Node dummy = new Node(); + dummy.next = head; + Node pre = dummy; + while (index > 0) { + pre = pre.next; + } + Node cur = pre.next; + Node next = pre.next.next; + pre.next = next; + size--; + return cur; + + } + + public int size(){ + return size; + } + + public void addFirst(Object o){ + Node firstNode = new Node(o); + firstNode.next = head; + head = firstNode; + } + public void addLast(Object o){ + Node pre = new Node(); + while (pre.next != null){ + pre = pre.next; + } + Node lastNode = new Node(o); + pre.next = lastNode; + } + public Object removeFirst(){ + Node dummy = new Node(); + dummy.next = head; + dummy.next = head.next; + return dummy.next; + } + public Object removeLast(){ + Node pre = new Node(); + while (pre.next.next != null) { + pre = pre.next; + } + Node lastNode = pre.next.next; + pre.next = null; + return lastNode; + + } + public Iterator iterator(){ + return null; + } + + + private static class Node{ + public Node(Object o) { + // TODO Auto-generated constructor stub + } + public Node() { + // TODO Auto-generated constructor stub + } + Object data; + Node next; + + } + + + public boolean isEmpty() { + // TODO Auto-generated method stub + if (size() == 0){ + return false; + } + return true; + } + + +} diff --git a/coding2017/group02/447809161Learning/src/com/github/hwjcc969/coding2017/basic/List.java b/coding2017/group02/447809161Learning/src/com/github/hwjcc969/coding2017/basic/List.java new file mode 100644 index 0000000000..56d67bdf29 --- /dev/null +++ b/coding2017/group02/447809161Learning/src/com/github/hwjcc969/coding2017/basic/List.java @@ -0,0 +1,9 @@ +package com.github.hwjcc969.coding2017.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/coding2017/group02/447809161Learning/src/com/github/hwjcc969/coding2017/basic/Queue.java b/coding2017/group02/447809161Learning/src/com/github/hwjcc969/coding2017/basic/Queue.java new file mode 100644 index 0000000000..f7cb7b1ad4 --- /dev/null +++ b/coding2017/group02/447809161Learning/src/com/github/hwjcc969/coding2017/basic/Queue.java @@ -0,0 +1,27 @@ +package com.github.hwjcc969.coding2017.basic; + +public class Queue { + private LinkedList list = new LinkedList(); + public void enQueue(Object o){ + list.addLast(o); + } + + public Object deQueue(){ + if (!list.isEmpty()){ + return list.removeFirst(); + } + return "空队列"; + + } + + public boolean isEmpty(){ + if (list.size() == 0){ + return false; + } + return true; + } + + public int size(){ + return list.size(); + } +} diff --git a/coding2017/group02/447809161Learning/src/com/github/hwjcc969/coding2017/basic/Stack.java b/coding2017/group02/447809161Learning/src/com/github/hwjcc969/coding2017/basic/Stack.java new file mode 100644 index 0000000000..a4229a7d12 --- /dev/null +++ b/coding2017/group02/447809161Learning/src/com/github/hwjcc969/coding2017/basic/Stack.java @@ -0,0 +1,31 @@ +package com.github.hwjcc969.coding2017.basic; + +public class Stack { + private ArrayList elementData = new ArrayList(); + private int size = 0; + + public void push(Object o){ + if (elementData.size() <= 99) + elementData.add(o); + size++; + + } + + public Object pop(){ + size--; + return elementData.remove(elementData.size() - 1); + + } + + public Object peek(){ + return elementData.get(elementData.size() - 1); + } + public boolean isEmpty(){ + if (size == 0) + return false; + return true; + } + public int size(){ + return size; + } +}