Skip to content

Commit

Permalink
第一周大作业
Browse files Browse the repository at this point in the history
  • Loading branch information
tengjunjie1118 committed Feb 26, 2017
1 parent f5018be commit 4ac3afd
Show file tree
Hide file tree
Showing 22 changed files with 873 additions and 0 deletions.
12 changes: 12 additions & 0 deletions group01/1328404806/RemoteSystemsTempFiles/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RemoteSystemsTempFiles</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
<nature>org.eclipse.rse.ui.remoteSystemsTempNature</nature>
</natures>
</projectDescription>
27 changes: 27 additions & 0 deletions group01/1328404806/dataStructure/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
1 change: 1 addition & 0 deletions group01/1328404806/dataStructure/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
23 changes: 23 additions & 0 deletions group01/1328404806/dataStructure/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>dataStructure</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
25 changes: 25 additions & 0 deletions group01/1328404806/dataStructure/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>increaseLearning</groupId>
<artifactId>dataStructure</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>dataStructure</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ListService;

//集合接口
public interface KILinkedList<T> {

public void add(T t, int pos);

public T remove(int pos);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ListService;

//集合接口
public interface KIList<T> {

public void add(T item);

public void add(int index, T item);

public void set(int index, T item);

public void remove(int index);

public void remove(T item);

public void clear();

public boolean contains(T item);

public boolean isEmpty();

public T get(int index);

public int indexOf(T item);

public int size();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ListService;

//集合接口
public interface KIQueueList<T> {
public T add(T ele);

public T remove();

public Object[] getData();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ListService;

//集合接口
public interface KIStackList<T> {
public void push(T ele);

public void pop();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
package ListServiceImpl;

import ListService.KIList;

public class KArrayList<T> implements KIList<T> {

/** 初始化的容量的大小 */
private final static int INIT_CAPACITY = 12;
private Object[] mList = null;

/** 当前的容量 */
private int mCurrentCapacity = 0;
/** 容器中元素的个数 */
private int mSize = 0;

public KArrayList() {
mList = new Object[INIT_CAPACITY];
mCurrentCapacity = INIT_CAPACITY;
}

/**
* 插入一个元素到链表尾部
*
* @param item
*/
public void add(T item) {
if (mSize == mCurrentCapacity) {
expansion();
}
mList[mSize] = item;
mSize++;

}

/**
* 插入一个元素到指定位置,从插入位置及其后面的元素往后移动一个位置
*
* @param index
* 要插入的位置
* @param item
*/
public void add(int index, T item) {
if (index < 0 || index >= mSize) { // 不允许index小于0,或者index >= 数组当前大小
throw new IndexOutOfBoundsException();
}
if (mSize == mCurrentCapacity) {
expansion();
}
Object[] newList = new Object[mCurrentCapacity];
System.arraycopy(mList, 0, newList, 0, index);
System.arraycopy(mList, index, newList, index + 1, mSize - index);
newList[index] = item;
mList = newList;
mSize++;

}

/**
* 更新指定位置的元素
*
* @param index
* @param item
*/
public void set(int index, T item) {
if (index < 0 || index >= mSize) {
throw new IndexOutOfBoundsException();
}
mList[index] = item;

}

/**
* 移除指定位置的元素,后面的元素向前移动一位
*
* @param index
*/
public void remove(int index) {
if (index < 0 || index >= mSize) {
throw new IndexOutOfBoundsException();
}
Object[] newList = new Object[mCurrentCapacity];
System.arraycopy(mList, 0, newList, 0, index);
System.arraycopy(mList, index + 1, newList, index, mSize - index);
mList = newList;
mSize--;

}

/**
* 移除链表中特定的元素。(如果item在链表中有多个,只移除第一个)
*
* @param item
*/
public void remove(T item) {
for (int i = 0; i < mSize; i++) {
if (mList[i].equals(item)) {
remove(i);
break;
}
}

}

/**
* 将链表清空,capacity不变
*/
public void clear() {
mList = new Object[mCurrentCapacity];
mSize = 0;

}

/**
* 判断是否包含某个元素
*
* @param item
* @return true表示有这个元素,false表示没有这个元素
*/
public boolean contains(T item) {
for (int i = 0; i < mSize; i++) {
if (mList[i].equals(item)) {
return true;
}
}
return false;
}

/**
* 判断链表是否为空
*
* @return boolean
*/
public boolean isEmpty() {
return (mSize == 0) ? true : false;
}

/**
* 获取指定位置的元素
*
* @param index
* @return
*/
@SuppressWarnings("unchecked")
public T get(int index) {
if (index < 0 || index >= mSize) {
throw new IndexOutOfBoundsException();
}
return (T) mList[index];
}

/**
* 获取特定元素所在的位置。 如果该链表中存在多个相同的元素,只返回第一个的位置,如果找不到,则返回-1。
*
* @param item
* @return int 如果没找到,返回-1
*/
public int indexOf(T item) {
for (int i = 0; i < mSize; i++) {
if (mList[i].equals(item)) {
return i;
}
}
return -1;
}

/**
* 获取当前链表的长度
*
* @return int
*/
public int size() {
return mSize;
}

/**
* 扩容,当 mSize == mCurrentCapacity 时调用
*/
private void expansion() {
Object[] oldList = mList;
Object[] newList = new Object[getNewCapacity()];
System.arraycopy(oldList, 0, newList, 0, oldList.length);
mList = newList;
}

/**
* 获取新的容量大小 当满的时候每次增加当前容量的50%
*/
private int getNewCapacity() {
return mCurrentCapacity = mCurrentCapacity + (mCurrentCapacity >> 1);
}

}
Loading

0 comments on commit 4ac3afd

Please sign in to comment.