Skip to content

Commit

Permalink
Merge pull request #6 from Kandde/master
Browse files Browse the repository at this point in the history
1094051862
  • Loading branch information
zhanglifeng authored Feb 26, 2017
2 parents 2ac4403 + 4f7b480 commit f75d55d
Show file tree
Hide file tree
Showing 13 changed files with 324 additions and 0 deletions.
7 changes: 7 additions & 0 deletions group05/1094051862/test01/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions group05/1094051862/test01/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
17 changes: 17 additions & 0 deletions group05/1094051862/test01/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>test01</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
12 changes: 12 additions & 0 deletions group05/1094051862/test01/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/ArrayList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.coding1094051862.basic;

import org.junit.Assert;
import org.junit.Test;

public class ArrayListTest {

@Test
public void test() {
ArrayList list = new ArrayList();
for(int i = 0; i < 10; i++) {
list.add(i);
}
Assert.assertEquals(10, list.size());
list.add(11);
list.add(3,99);
Assert.assertEquals(99, list.get(3));
Assert.assertEquals(12, list.size());
Assert.assertEquals(99, list.remove(3));
Assert.assertEquals(11, list.size());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.coding1094051862.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;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.coding1094051862.basic;

public interface Iterator {
public boolean hasNext();
public Object next();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package com.coding1094051862.basic;

public class LinkedList implements List {

private Node head;
private Node last;
private int size = 0;

public void add(Object o){
if (head == null) {
head = new Node(o, null);
size ++;
return;
}
Node n = new Node(o, null);
if (last == null) {
last = n;
head.next = last;
}
last.next = n;
last = n;
size ++;
}
public void add(int index , Object o){
if (index < 0 || index > size) {
System.out.println("linkedList.add: index < 0 || index > size");
return;
}
if (index == size) {
add(o);
return;
}
if (index == 0) {
addFirst(o);
return;
}
Node pre = head;
for (int i = 1; i < index; i++) {
pre = pre.next;
}
Node post = pre.next;
Node n = new Node(o,post);
pre.next = n;
size ++;
}
public Object get(int index){
if (index == 0) {
return head.data;
}
Node n = head;
for (int i = 1; i <= index; i++) {
n = n.next;
}
return n.data;
}
public Object remove(int index){
if (index < 0 || index >= size) {
System.out.println("remove :index < 0 || index >= size");
return null;
}
if (index == 0) {
return removeFirst();
}
if (index == size - 1) {
return removeLast();
}
Node pre = head;
for (int i = 1; i < index; i++) {
pre = pre.next;
}
Node n = pre.next;
Node post = n.next;
n.next = null;
pre.next = post;
size --;
return n.data;
}

public int size(){
return size;
}

public void addFirst(Object o){
Node n = new Node(o,head);
head = n;
size ++;
return;
}
public void addLast(Object o){
Node n = new Node(o,null);
last.next = n;
last = n;
size ++;
return;
}
public Object removeFirst(){
Object o = head.data;
Node n = head.next;
head.next = null;
head = n;
size --;
return o;
}
public Object removeLast(){
Node preLast = head;
for (int i = 1; i < size; i++) {
preLast = preLast.next;
}
preLast.next = null;
Object o = last.data;
last = preLast;
size --;
return o;
}
public Iterator iterator(){
return new Iterator() {
@Override
public Object next() {
// TODO Auto-generated method stub
return null;
}

@Override
public boolean hasNext() {
// TODO Auto-generated method stub
return false;
}
};
}


private static class Node {

Object data;
Node next;

public Node (Object data, Node next) {
this.data = data;
this.next = next;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.coding1094051862.basic;

import junit.framework.Assert;

import org.junit.Test;

public class LinkedListTest extends LinkedList {

@Test
public void test() {
List list = new LinkedList();
list.add(0);
list.add(1);
list.add(2);
list.add(3);
list.add(4);
list.add(5);
list.add(3, 33);
list.add(0, 100);
list.add(8,800);
Assert.assertEquals(9, list.size());
Assert.assertEquals(100, list.get(0));
Assert.assertEquals(0, list.get(1));
Assert.assertEquals(1, list.get(2));
Assert.assertEquals(2, list.get(3));
Assert.assertEquals(33, list.get(4));
Assert.assertEquals(3, list.get(5));
Assert.assertEquals(4, list.get(6));
Assert.assertEquals(800, list.get(8));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.coding1094051862.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();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.coding1094051862.basic;

public class Queue {

public void enQueue(Object o){
}

public Object deQueue(){
return null;
}

public boolean isEmpty(){
return false;
}

public int size(){
return -1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.coding1094051862.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;
}
}

0 comments on commit f75d55d

Please sign in to comment.