Skip to content

Commit

Permalink
Merge pull request #12 from yys213114/master
Browse files Browse the repository at this point in the history
提交作业
  • Loading branch information
honokaBiu authored Feb 26, 2017
2 parents a85c46f + 8bbd619 commit b70ddf8
Show file tree
Hide file tree
Showing 14 changed files with 302 additions and 119 deletions.
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>coding2017</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
2 changes: 2 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
1 change: 1 addition & 0 deletions group20/423184723/Test/博客地址
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http://www.cnblogs.com/yyssyh213/p/6442285.html
78 changes: 78 additions & 0 deletions group20/423184723/src/basic/ArrayList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.coding.basic;

import com.sun.media.sound.EmergencySoundbank;

public class ArrayList implements List {
/**
* 列表中元素的个数
*/
private int size = 0;

/**
* 初始化数组大小
*/
private int arraySize = 100;
/**
* 初始化数组
*/
private Object[] elementData = new Object[arraySize];

/**
* 添加方法
*/
public void add(Object o){
if(size>=(arraySize*0.75)){
Object [] target = new Object[(int) (arraySize*1.5)];
System.arraycopy(elementData,0,target,0,arraySize);
target[size-1] = o;
size++;
}else if(size<(arraySize*0.75)){
elementData[size-1]=o;
size++;
}
}
/**
* 根据索引添加方法
*/
public void add(int index, Object o){
if(size >= arraySize*0.75){
Object [] target = new Object[(int) (arraySize*1.5)];
System.arraycopy(elementData,0,target,0,arraySize);
for (int j = target.length;j>=index;j--){
target[j-1] = target[j-2];
}
target[index] = o;
size++;
}else if(size < arraySize*0.75){
for (int j = elementData.length;j>=index;j--){
elementData[j-1] = elementData[j-2];
}
elementData[index] = o;
size++;
}
}
/**
* 根据索引获取对象
*/
public Object get(int index){
return elementData[index];
}
/**
* 根据索引移除对象
*/
public Object remove(int index){
for (int i = index; i < elementData.length; i++) {
elementData[i]=elementData[i+1];
size++;
}
return elementData[index];
}
/**
* 获取数组大小
*/
public int size(){
return this.size;
}


}
File renamed without changes.
146 changes: 146 additions & 0 deletions group20/423184723/src/basic/LinkedList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package com.coding.basic;

import com.coding.basic.LinkedList.Node;

public class LinkedList implements List {

private Node head;
private int size;

public void add(Object o){
if (head.data == null) {
head.data = o;
head.next = null;
size++;
return;
}
Node node = new Node(o);
Node curr = head;
while (curr.next != null) {
curr = curr.next;
}
curr.next = node;
size++;
}
public void add(int index , Object o){
if (index < 0 || index > size) {
System.out.println(index + "无效指数");
return;
}
if (head.data == null) {
if (index == 0) {
head.data = o;
head.next = null;
size++;
return;
} else {
System.out.println("无效指数");
return;
}
}
Node node = new Node(o);
Node curr = head;
for (int i = 0; i < index - 1; i++) {
curr = curr.next;
}
Node temp = curr.next;
curr.next = node;
node.next = temp;
size++;
}
public Object get(int index){
if (index < 0 || index > size) {
System.out.println(index + " is invalid index!");
return null;
}
Node result = head;
for (int i = 0; i < index; i++) {
result = result.next;
}
return result;
}
public Object remove(int index){
if (index < 0 || index > size) {
System.out.println(index + " is invalid index!");
return null;
}
Node curr = head;
for (int i = 0; i < index - 1; i++) {
curr = curr.next;
}
Node result = curr.next;
curr.next = curr.next.next;
size--;
return result;
}

public int size(){
return this.size;
}

public void addFirst(Object o){
if (head.data == null) {
head.data = o;
head.next = null;
size++;
return;
}
Node temp = head;
head = new Node(o);
head.next = temp;
size++;
}
public void addLast(Object o){
if (head.data == null) {
head.data = o;
head.next = null;
size++;
return;
}
Node node = new Node(o);
Node curr = head;
while (curr.next != null) {
curr = curr.next;
}
curr.next = node;
size++;
}
public Object removeFirst(){
if (head.data == null) {
return null;
}
Node result = head;
head = head.next;
size--;
return result;
}
public Object removeLast(){
if (head.data == null) {
return null;
}
Node curr = head;
for (int i = 0; i < size - 1; i++) {
curr = curr.next;
}
Node result = curr.next;
curr.next = null;
size--;
return result;
}
public Iterator iterator(){
return null;
}


private static class Node{
Object data;
Node next;
public Node(Object o) {
data = o;
next = null;
}



}
}
File renamed without changes.
29 changes: 29 additions & 0 deletions group20/423184723/src/basic/Queue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.coding.basic;

public class Queue {

private LinkedList list = new LinkedList();
public void enQueue(Object o){
list.add(o);
}

public Object deQueue(){
int length = list.size();
if (length == 0) {
return null;
}
return list.removeFirst();
}

public boolean isEmpty(){
if (list.size() == 0) {
return true;
} else {
return false;
}
}

public int size(){
return list.size;
}
}
35 changes: 35 additions & 0 deletions group20/423184723/src/basic/Stack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.coding.basic;

public class Stack {
private ArrayList elementData = new ArrayList();

public void push(Object o){
elementData.add(o);
}

public Object pop(){
int length = elementData.size();
if (length == 0) {
return null;
}
return elementData.remove(length - 1);
}

public Object peek(){
int length = elementData.size();
if (length == 0) {
return null;
}
return elementData.get(length - 1);
}
public boolean isEmpty(){
if (elementData.size() != 0) {
return false;
} else {
return true;
}
}
public int size(){
return elementData.size();
}
}
32 changes: 0 additions & 32 deletions group20/423184723/src/com/coding/basic/ArrayList.java

This file was deleted.

46 changes: 0 additions & 46 deletions group20/423184723/src/com/coding/basic/LinkedList.java

This file was deleted.

Loading

0 comments on commit b70ddf8

Please sign in to comment.