diff --git a/group24/330657387/.classpath b/group24/330657387/.classpath new file mode 100644 index 0000000000..3e0fb272a8 --- /dev/null +++ b/group24/330657387/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/group24/330657387/.gitignore b/group24/330657387/.gitignore new file mode 100644 index 0000000000..e2e6235a8a --- /dev/null +++ b/group24/330657387/.gitignore @@ -0,0 +1,5 @@ +/bin/ + +#ide config +.settings/ + diff --git a/group24/330657387/.project b/group24/330657387/.project new file mode 100644 index 0000000000..fab8d7f04c --- /dev/null +++ b/group24/330657387/.project @@ -0,0 +1,17 @@ + + + 2017Learning + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/group24/330657387/src/com/coding/basic/ArrayList.java b/group24/330657387/src/com/coding/basic/ArrayList.java new file mode 100644 index 0000000000..1728a28291 --- /dev/null +++ b/group24/330657387/src/com/coding/basic/ArrayList.java @@ -0,0 +1,62 @@ +package com.coding.basic; + +import java.util.Arrays; + +public class ArrayList implements List { + + private int size = 0; + + private Object[] elementData = new Object[10]; + + public void ensureCapacity(int input) { + if (input > elementData.length) { + growCapacity(); + } + } + + private void growCapacity(){ + elementData = Arrays.copyOf(elementData, size * 2); + } + + public void add(Object o){ + ensureCapacity(size + 1); + elementData[size++] = o; + } + + + public void add(int index, Object o){ + rangeCheck(index); + ensureCapacity(size + 1); + System.arraycopy(elementData,index, elementData, index + 1, size - index); + elementData[index] = o; + size ++; + } + + private void rangeCheck(int index){ + if (index > size || index < 0){ + throw new IndexOutOfBoundsException(); + } + } + + public Object get(int index){ + rangeCheck(index); + return elementData[index]; + } + + public Object remove(int index){ + rangeCheck(index); + Object dest = elementData[index]; + System.arraycopy(elementData, index +1, elementData, index, size-index-1); + size --; + return dest; + } + + public int size(){ + return size; + } + + public Iterator iterator(){ + return null; + } + +} diff --git a/group24/330657387/src/com/coding/basic/BinaryTreeNode.java b/group24/330657387/src/com/coding/basic/BinaryTreeNode.java new file mode 100644 index 0000000000..d7ac820192 --- /dev/null +++ b/group24/330657387/src/com/coding/basic/BinaryTreeNode.java @@ -0,0 +1,32 @@ +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/group24/330657387/src/com/coding/basic/Iterator.java b/group24/330657387/src/com/coding/basic/Iterator.java new file mode 100644 index 0000000000..06ef6311b2 --- /dev/null +++ b/group24/330657387/src/com/coding/basic/Iterator.java @@ -0,0 +1,7 @@ +package com.coding.basic; + +public interface Iterator { + public boolean hasNext(); + public Object next(); + +} diff --git a/group24/330657387/src/com/coding/basic/LinkedList.java b/group24/330657387/src/com/coding/basic/LinkedList.java new file mode 100644 index 0000000000..8357e13254 --- /dev/null +++ b/group24/330657387/src/com/coding/basic/LinkedList.java @@ -0,0 +1,122 @@ +package com.coding.basic; + +import java.util.NoSuchElementException; + +public class LinkedList implements List { + + private Node head; + private int size = 0; + + public void add(Object o) { + if (isEmpty()) { + head = new Node(o); + } else { + Node tail = (Node)get(size-1); + Node node = new Node(o); + tail.next = node; + } + size++; + } + + public boolean isEmpty() { + return (size == 0) ? true : false; + } + + public void add(int index, Object o) { + rangeCheck(index); + if (index ==0) { + Node node = new Node(o); + node.next = head; + head = node; + } else { + Node pre = (Node)get(index-1); + Node node = new Node(o); + node.next = pre.next; + pre.next = node; + } + } + + private void rangeCheck(int index){ + if (index >= size || index <0){ + throw new IndexOutOfBoundsException(); + } + } + + public Object get(int index) { + rangeCheck(index); + Node dest = head; + for (int i = 0; i< index; i++){ + dest = dest.next; + } + return dest.data; + } + + public Object remove(int index) { + rangeCheck(index); + Node pre = (Node)get(index); + Node dest = pre.next; + pre.next = dest.next; + size --; + return dest; + } + + public int size() { + return size; + } + + public void addFirst(Object o) { + Node node = new Node(o); + node.next = head; + head = node; + size ++; + } + + public void addLast(Object o) { + Node last = (Node)get(size-1); + Node node = new Node(o); + last.next = node; + size++; + } + + public Object removeFirst() { + if (head == null) { + throw new NoSuchElementException(); + } + Node newhead = head; + head = head.next; + size --; + return newhead; + } + + public Object removeLast() { + if (head == null) { + throw new NoSuchElementException(); + } + if (head.next == null) { + Node tmp = head; + head = null; + size --; + return tmp; + } + Node newLastNode = (Node)get(size-2); + Node oldLastNode = newLastNode.next; + newLastNode.next = null; + size --; + return oldLastNode; + } + + public Iterator iterator() { + return null; + } + + private static class Node { + Object data; + Node next; + + Node(Object data) { + this.data = data; + next = null; + } + } + +} diff --git a/group24/330657387/src/com/coding/basic/List.java b/group24/330657387/src/com/coding/basic/List.java new file mode 100644 index 0000000000..10d13b5832 --- /dev/null +++ b/group24/330657387/src/com/coding/basic/List.java @@ -0,0 +1,9 @@ +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/group24/330657387/src/com/coding/basic/Queue.java b/group24/330657387/src/com/coding/basic/Queue.java new file mode 100644 index 0000000000..36e516e266 --- /dev/null +++ b/group24/330657387/src/com/coding/basic/Queue.java @@ -0,0 +1,19 @@ +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/group24/330657387/src/com/coding/basic/Stack.java b/group24/330657387/src/com/coding/basic/Stack.java new file mode 100644 index 0000000000..a5a04de76d --- /dev/null +++ b/group24/330657387/src/com/coding/basic/Stack.java @@ -0,0 +1,22 @@ +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; + } +}