forked from onlyliuxin/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 11
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 #1 from DonaldY/master
merge
- Loading branch information
Showing
113 changed files
with
7,651 additions
and
0 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,21 @@ | ||
*.class | ||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.ear | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
|
||
#ide config | ||
.metadata | ||
.recommenders | ||
.idea/ | ||
*.iml | ||
rebel.* | ||
.rebel.* | ||
|
||
target |
90 changes: 90 additions & 0 deletions
90
...p24/1107225491/1107225491Learning/src/com/github/chishiwu/coding2017/basic/ArrayList.java
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,90 @@ | ||
package com.github.chishiwu.coding2017.basic; | ||
|
||
import java.util.Arrays; | ||
|
||
public class ArrayList implements List { | ||
|
||
private int size = 0; | ||
Object[] elementData = new Object[100]; | ||
|
||
// 动态添加元素 | ||
public void add(Object o) { | ||
ensureCapacity(size + 1); | ||
elementData[size] = o; | ||
size++; | ||
|
||
} | ||
|
||
public void add(int index, Object o) { | ||
Check(index); | ||
ensureCapacity(size + 1); | ||
System.arraycopy(elementData, index, elementData, index + 1, size | ||
- index); | ||
elementData[index] = o; | ||
size++; | ||
} | ||
|
||
// 动态扩容 | ||
private void ensureCapacity(int minCapacity) { | ||
// TODO Auto-generated method stub | ||
int oldCapacity = elementData.length; | ||
if (minCapacity > oldCapacity) { | ||
int newCapacity = (oldCapacity * 3) / 2 + 1; | ||
if (newCapacity < minCapacity) { | ||
newCapacity = minCapacity; | ||
} | ||
elementData = Arrays.copyOf(elementData, newCapacity); | ||
} | ||
} | ||
|
||
public void Check(int index) { | ||
if (index >= size || index < 0) { | ||
throw new IndexOutOfBoundsException("index" + index + "越界"); | ||
} | ||
} | ||
|
||
public Object get(int index) { | ||
Check(index); | ||
return elementData[index]; | ||
} | ||
|
||
public Object remove(int index) { | ||
Check(index); | ||
// 备份 | ||
Object oldValue = elementData[index]; | ||
int num = size - index - 1; | ||
if (num > 0) | ||
System.arraycopy(elementData, index + 1, elementData, index + 1, | ||
num); | ||
elementData[--size] = null; | ||
return oldValue; | ||
|
||
} | ||
|
||
public int size() { | ||
return size; | ||
} | ||
|
||
public Iterator iterator() { | ||
return new ArrayListIterator(); | ||
} | ||
|
||
private class ArrayListIterator implements Iterator { | ||
|
||
private int currentIndex = 0; | ||
|
||
public boolean hasNext() { | ||
if (currentIndex >= size) | ||
return false; | ||
else | ||
return true; | ||
} | ||
|
||
public Object next() { | ||
Object o = elementData[currentIndex]; | ||
currentIndex++; | ||
return o; | ||
} | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
group24/1107225491/1107225491Learning/src/com/github/chishiwu/coding2017/basic/Iterator.java
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,7 @@ | ||
package com.github.chishiwu.coding2017.basic; | ||
|
||
public interface Iterator { | ||
public boolean hasNext(); | ||
public Object next(); | ||
|
||
} |
124 changes: 124 additions & 0 deletions
124
...24/1107225491/1107225491Learning/src/com/github/chishiwu/coding2017/basic/LinkedList.java
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,124 @@ | ||
package com.github.chishiwu.coding2017.basic; | ||
|
||
|
||
|
||
public class LinkedList implements List { | ||
|
||
private Node head; | ||
|
||
public void add(Object o){ | ||
|
||
} | ||
public void add(int index , Object o){ | ||
|
||
} | ||
public Object get(int index){ | ||
return null; | ||
} | ||
public Object remove(int index){ | ||
return null; | ||
} | ||
|
||
public int size(){ | ||
return -1; | ||
} | ||
|
||
public void addFirst(Object o){ | ||
|
||
} | ||
public void addLast(Object o){ | ||
|
||
} | ||
public Object removeFirst(){ | ||
return null; | ||
} | ||
public Object removeLast(){ | ||
return null; | ||
} | ||
public Iterator iterator(){ | ||
return null; | ||
} | ||
|
||
|
||
private static class Node{ | ||
Object data; | ||
Node next; | ||
|
||
} | ||
|
||
/** | ||
* 鎶婅閾捐〃閫嗙疆 | ||
* 渚嬪閾捐〃涓�3->7->10 , 閫嗙疆鍚庡彉涓� 10->7->3 | ||
*/ | ||
public void reverse(){ | ||
|
||
} | ||
|
||
/** | ||
* 鍒犻櫎涓�釜鍗曢摼琛ㄧ殑鍓嶅崐閮ㄥ垎 | ||
* 渚嬪锛歭ist = 2->5->7->8 , 鍒犻櫎浠ュ悗鐨勫�涓�7->8 | ||
* 濡傛灉list = 2->5->7->8->10 ,鍒犻櫎浠ュ悗鐨勫�涓�,8,10 | ||
*/ | ||
public void removeFirstHalf(){ | ||
|
||
} | ||
|
||
/** | ||
* 浠庣i涓厓绱犲紑濮嬶紝 鍒犻櫎length 涓厓绱�锛�娉ㄦ剰i浠�寮� | ||
* @param i | ||
* @param length | ||
*/ | ||
public void remove(int i, int length){ | ||
|
||
} | ||
/** | ||
* 鍋囧畾褰撳墠閾捐〃鍜宭ist鍧囧寘鍚凡鍗囧簭鎺掑垪鐨勬暣鏁� | ||
* 浠庡綋鍓嶉摼琛ㄤ腑鍙栧嚭閭d簺list鎵�寚瀹氱殑鍏冪礌 | ||
* 渚嬪褰撳墠閾捐〃 = 11->101->201->301->401->501->601->701 | ||
* listB = 1->3->4->6 | ||
* 杩斿洖鐨勭粨鏋滃簲璇ユ槸[101,301,401,601] | ||
* @param list | ||
*/ | ||
public static int[] getElements(LinkedList list){ | ||
return null; | ||
} | ||
|
||
/** | ||
* 宸茬煡閾捐〃涓殑鍏冪礌浠ュ�閫掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩� | ||
* 浠庡綋鍓嶉摼琛ㄤ腑涓垹闄ゅ湪list涓嚭鐜扮殑鍏冪礌 | ||
* @param list | ||
*/ | ||
|
||
public void subtract(LinkedList list){ | ||
|
||
} | ||
|
||
/** | ||
* 宸茬煡褰撳墠閾捐〃涓殑鍏冪礌浠ュ�閫掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩� | ||
* 鍒犻櫎琛ㄤ腑鎵�湁鍊肩浉鍚岀殑澶氫綑鍏冪礌锛堜娇寰楁搷浣滃悗鐨勭嚎鎬ц〃涓墍鏈夊厓绱犵殑鍊煎潎涓嶇浉鍚岋級 | ||
*/ | ||
public void removeDuplicateValues(){ | ||
|
||
} | ||
|
||
/** | ||
* 宸茬煡閾捐〃涓殑鍏冪礌浠ュ�閫掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩� | ||
* 璇曞啓涓�珮鏁堢殑绠楁硶锛屽垹闄よ〃涓墍鏈夊�澶т簬min涓斿皬浜巑ax鐨勫厓绱狅紙鑻ヨ〃涓瓨鍦ㄨ繖鏍风殑鍏冪礌锛� | ||
* @param min | ||
* @param max | ||
*/ | ||
public void removeRange(int min, int max){ | ||
|
||
} | ||
|
||
/** | ||
* 鍋囪褰撳墠閾捐〃鍜屽弬鏁發ist鎸囧畾鐨勯摼琛ㄥ潎浠ュ厓绱犱緷鍊奸�澧炴湁搴忔帓鍒楋紙鍚屼竴琛ㄤ腑鐨勫厓绱犲�鍚勪笉鐩稿悓锛� | ||
* 鐜拌姹傜敓鎴愭柊閾捐〃C锛屽叾鍏冪礌涓哄綋鍓嶉摼琛ㄥ拰list涓厓绱犵殑浜ら泦锛屼笖琛–涓殑鍏冪礌鏈変緷鍊奸�澧炴湁搴忔帓鍒� | ||
* @param list | ||
*/ | ||
public LinkedList intersection( LinkedList list){ | ||
return null; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
group24/1107225491/1107225491Learning/src/com/github/chishiwu/coding2017/basic/List.java
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,9 @@ | ||
package com.github.chishiwu.coding2017.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(); | ||
} |
19 changes: 19 additions & 0 deletions
19
group24/1107225491/1107225491Learning/src/com/github/chishiwu/coding2017/basic/Queue.java
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,19 @@ | ||
package com.github.chishiwu.coding2017.basic; | ||
|
||
public class Queue { | ||
|
||
public void enQueue(Object o){ | ||
} | ||
|
||
public Object deQueue(){ | ||
return null; | ||
} | ||
|
||
public boolean isEmpty(){ | ||
return false; | ||
} | ||
|
||
public int size(){ | ||
return -1; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
group24/1107225491/1107225491Learning/src/com/github/chishiwu/coding2017/basic/Stack.java
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,49 @@ | ||
package com.github.chishiwu.coding2017.basic; | ||
|
||
public class Stack { | ||
private Node mStackNode; | ||
private int size; | ||
|
||
public void push(Object o) { | ||
Node node = new Node(); | ||
node.data = o; | ||
if (null == mStackNode) { | ||
mStackNode = node; | ||
} else { | ||
mStackNode.next = node; | ||
mStackNode = node; | ||
} | ||
size++; | ||
} | ||
|
||
public Object pop() { | ||
if (size == 0) { | ||
throw new RuntimeException("the stack is empty"); | ||
} | ||
Object obj = mStackNode.data; | ||
mStackNode = mStackNode.pre; | ||
size--; | ||
return obj; | ||
} | ||
|
||
public Object peek() { | ||
if (size == 0) { | ||
throw new RuntimeException("the stack is empty"); | ||
} | ||
return mStackNode.data; | ||
} | ||
|
||
public boolean isEmpty() { | ||
return size == 0; | ||
} | ||
|
||
public int size() { | ||
return size; | ||
} | ||
|
||
private static class Node { | ||
Object data; | ||
Node next; | ||
Node pre; | ||
} | ||
} |
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/chishiwu/p/6514526.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,36 @@ | ||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files | ||
*.war | ||
*.ear | ||
*.bk | ||
.gradle | ||
target | ||
*.class | ||
*.real | ||
|
||
# virtual machine crash logs | ||
# see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
|
||
# Eclipse Files # | ||
.project | ||
.classpath | ||
.settings | ||
|
||
# Idea | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea | ||
|
||
# log | ||
*_IS_UNDEFINED | ||
logs | ||
*.log | ||
|
||
# other | ||
*.bak | ||
.directory | ||
.DS_Store |
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,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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> | ||
|
||
|
||
<parent> | ||
<artifactId>learning2017</artifactId> | ||
<groupId>me.lzb</groupId> | ||
<version>1.0</version> | ||
</parent> | ||
|
||
|
||
<artifactId>learning-basic</artifactId> | ||
<name>basic</name> | ||
<version>1.0</version> | ||
|
||
|
||
<dependencies> | ||
</dependencies> | ||
</project> |
Oops, something went wrong.