forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from yys213114/master
提交作业
- Loading branch information
Showing
14 changed files
with
302 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
eclipse.preferences.version=1 | ||
encoding/<project>=UTF-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
http://www.cnblogs.com/yyssyh213/p/6442285.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.