Skip to content

Commit 5a97b44

Browse files
authored
Merge pull request #1 from DonaldY/master
merge
2 parents 2d87167 + 64f8cb0 commit 5a97b44

File tree

113 files changed

+7651
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+7651
-0
lines changed

group24/.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
*.class
2+
# Mobile Tools for Java (J2ME)
3+
.mtj.tmp/
4+
5+
# Package Files #
6+
*.jar
7+
*.war
8+
*.ear
9+
10+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
11+
hs_err_pid*
12+
13+
#ide config
14+
.metadata
15+
.recommenders
16+
.idea/
17+
*.iml
18+
rebel.*
19+
.rebel.*
20+
21+
target
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package com.github.chishiwu.coding2017.basic;
2+
3+
import java.util.Arrays;
4+
5+
public class ArrayList implements List {
6+
7+
private int size = 0;
8+
Object[] elementData = new Object[100];
9+
10+
// 动态添加元素
11+
public void add(Object o) {
12+
ensureCapacity(size + 1);
13+
elementData[size] = o;
14+
size++;
15+
16+
}
17+
18+
public void add(int index, Object o) {
19+
Check(index);
20+
ensureCapacity(size + 1);
21+
System.arraycopy(elementData, index, elementData, index + 1, size
22+
- index);
23+
elementData[index] = o;
24+
size++;
25+
}
26+
27+
// 动态扩容
28+
private void ensureCapacity(int minCapacity) {
29+
// TODO Auto-generated method stub
30+
int oldCapacity = elementData.length;
31+
if (minCapacity > oldCapacity) {
32+
int newCapacity = (oldCapacity * 3) / 2 + 1;
33+
if (newCapacity < minCapacity) {
34+
newCapacity = minCapacity;
35+
}
36+
elementData = Arrays.copyOf(elementData, newCapacity);
37+
}
38+
}
39+
40+
public void Check(int index) {
41+
if (index >= size || index < 0) {
42+
throw new IndexOutOfBoundsException("index" + index + "越界");
43+
}
44+
}
45+
46+
public Object get(int index) {
47+
Check(index);
48+
return elementData[index];
49+
}
50+
51+
public Object remove(int index) {
52+
Check(index);
53+
// 备份
54+
Object oldValue = elementData[index];
55+
int num = size - index - 1;
56+
if (num > 0)
57+
System.arraycopy(elementData, index + 1, elementData, index + 1,
58+
num);
59+
elementData[--size] = null;
60+
return oldValue;
61+
62+
}
63+
64+
public int size() {
65+
return size;
66+
}
67+
68+
public Iterator iterator() {
69+
return new ArrayListIterator();
70+
}
71+
72+
private class ArrayListIterator implements Iterator {
73+
74+
private int currentIndex = 0;
75+
76+
public boolean hasNext() {
77+
if (currentIndex >= size)
78+
return false;
79+
else
80+
return true;
81+
}
82+
83+
public Object next() {
84+
Object o = elementData[currentIndex];
85+
currentIndex++;
86+
return o;
87+
}
88+
}
89+
90+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.github.chishiwu.coding2017.basic;
2+
3+
public interface Iterator {
4+
public boolean hasNext();
5+
public Object next();
6+
7+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package com.github.chishiwu.coding2017.basic;
2+
3+
4+
5+
public class LinkedList implements List {
6+
7+
private Node head;
8+
9+
public void add(Object o){
10+
11+
}
12+
public void add(int index , Object o){
13+
14+
}
15+
public Object get(int index){
16+
return null;
17+
}
18+
public Object remove(int index){
19+
return null;
20+
}
21+
22+
public int size(){
23+
return -1;
24+
}
25+
26+
public void addFirst(Object o){
27+
28+
}
29+
public void addLast(Object o){
30+
31+
}
32+
public Object removeFirst(){
33+
return null;
34+
}
35+
public Object removeLast(){
36+
return null;
37+
}
38+
public Iterator iterator(){
39+
return null;
40+
}
41+
42+
43+
private static class Node{
44+
Object data;
45+
Node next;
46+
47+
}
48+
49+
/**
50+
* 鎶婅閾捐〃閫嗙疆
51+
* 渚嬪閾捐〃涓�3->7->10 , 閫嗙疆鍚庡彉涓� 10->7->3
52+
*/
53+
public void reverse(){
54+
55+
}
56+
57+
/**
58+
* 鍒犻櫎涓�釜鍗曢摼琛ㄧ殑鍓嶅崐閮ㄥ垎
59+
* 渚嬪锛歭ist = 2->5->7->8 , 鍒犻櫎浠ュ悗鐨勫�涓�7->8
60+
* 濡傛灉list = 2->5->7->8->10 ,鍒犻櫎浠ュ悗鐨勫�涓�,8,10
61+
62+
*/
63+
public void removeFirstHalf(){
64+
65+
}
66+
67+
/**
68+
* 浠庣i涓厓绱犲紑濮嬶紝 鍒犻櫎length 涓厓绱�锛�娉ㄦ剰i浠�寮�
69+
* @param i
70+
* @param length
71+
*/
72+
public void remove(int i, int length){
73+
74+
}
75+
/**
76+
* 鍋囧畾褰撳墠閾捐〃鍜宭ist鍧囧寘鍚凡鍗囧簭鎺掑垪鐨勬暣鏁�
77+
* 浠庡綋鍓嶉摼琛ㄤ腑鍙栧嚭閭d簺list鎵�寚瀹氱殑鍏冪礌
78+
* 渚嬪褰撳墠閾捐〃 = 11->101->201->301->401->501->601->701
79+
* listB = 1->3->4->6
80+
* 杩斿洖鐨勭粨鏋滃簲璇ユ槸[101,301,401,601]
81+
* @param list
82+
*/
83+
public static int[] getElements(LinkedList list){
84+
return null;
85+
}
86+
87+
/**
88+
* 宸茬煡閾捐〃涓殑鍏冪礌浠ュ�閫掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩�
89+
* 浠庡綋鍓嶉摼琛ㄤ腑涓垹闄ゅ湪list涓嚭鐜扮殑鍏冪礌
90+
91+
* @param list
92+
*/
93+
94+
public void subtract(LinkedList list){
95+
96+
}
97+
98+
/**
99+
* 宸茬煡褰撳墠閾捐〃涓殑鍏冪礌浠ュ�閫掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩�
100+
* 鍒犻櫎琛ㄤ腑鎵�湁鍊肩浉鍚岀殑澶氫綑鍏冪礌锛堜娇寰楁搷浣滃悗鐨勭嚎鎬ц〃涓墍鏈夊厓绱犵殑鍊煎潎涓嶇浉鍚岋級
101+
*/
102+
public void removeDuplicateValues(){
103+
104+
}
105+
106+
/**
107+
* 宸茬煡閾捐〃涓殑鍏冪礌浠ュ�閫掑鏈夊簭鎺掑垪锛屽苟浠ュ崟閾捐〃浣滃瓨鍌ㄧ粨鏋勩�
108+
* 璇曞啓涓�珮鏁堢殑绠楁硶锛屽垹闄よ〃涓墍鏈夊�澶т簬min涓斿皬浜巑ax鐨勫厓绱狅紙鑻ヨ〃涓瓨鍦ㄨ繖鏍风殑鍏冪礌锛�
109+
* @param min
110+
* @param max
111+
*/
112+
public void removeRange(int min, int max){
113+
114+
}
115+
116+
/**
117+
* 鍋囪褰撳墠閾捐〃鍜屽弬鏁發ist鎸囧畾鐨勯摼琛ㄥ潎浠ュ厓绱犱緷鍊奸�澧炴湁搴忔帓鍒楋紙鍚屼竴琛ㄤ腑鐨勫厓绱犲�鍚勪笉鐩稿悓锛�
118+
* 鐜拌姹傜敓鎴愭柊閾捐〃C锛屽叾鍏冪礌涓哄綋鍓嶉摼琛ㄥ拰list涓厓绱犵殑浜ら泦锛屼笖琛–涓殑鍏冪礌鏈変緷鍊奸�澧炴湁搴忔帓鍒�
119+
* @param list
120+
*/
121+
public LinkedList intersection( LinkedList list){
122+
return null;
123+
}
124+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.github.chishiwu.coding2017.basic;
2+
3+
public interface List {
4+
public void add(Object o);
5+
public void add(int index, Object o);
6+
public Object get(int index);
7+
public Object remove(int index);
8+
public int size();
9+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.github.chishiwu.coding2017.basic;
2+
3+
public class Queue {
4+
5+
public void enQueue(Object o){
6+
}
7+
8+
public Object deQueue(){
9+
return null;
10+
}
11+
12+
public boolean isEmpty(){
13+
return false;
14+
}
15+
16+
public int size(){
17+
return -1;
18+
}
19+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.github.chishiwu.coding2017.basic;
2+
3+
public class Stack {
4+
private Node mStackNode;
5+
private int size;
6+
7+
public void push(Object o) {
8+
Node node = new Node();
9+
node.data = o;
10+
if (null == mStackNode) {
11+
mStackNode = node;
12+
} else {
13+
mStackNode.next = node;
14+
mStackNode = node;
15+
}
16+
size++;
17+
}
18+
19+
public Object pop() {
20+
if (size == 0) {
21+
throw new RuntimeException("the stack is empty");
22+
}
23+
Object obj = mStackNode.data;
24+
mStackNode = mStackNode.pre;
25+
size--;
26+
return obj;
27+
}
28+
29+
public Object peek() {
30+
if (size == 0) {
31+
throw new RuntimeException("the stack is empty");
32+
}
33+
return mStackNode.data;
34+
}
35+
36+
public boolean isEmpty() {
37+
return size == 0;
38+
}
39+
40+
public int size() {
41+
return size;
42+
}
43+
44+
private static class Node {
45+
Object data;
46+
Node next;
47+
Node pre;
48+
}
49+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
http://www.cnblogs.com/chishiwu/p/6514526.html

group24/1148285693/.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Mobile Tools for Java (J2ME)
2+
.mtj.tmp/
3+
4+
# Package Files
5+
*.war
6+
*.ear
7+
*.bk
8+
.gradle
9+
target
10+
*.class
11+
*.real
12+
13+
# virtual machine crash logs
14+
# see http://www.java.com/en/download/help/error_hotspot.xml
15+
hs_err_pid*
16+
17+
# Eclipse Files #
18+
.project
19+
.classpath
20+
.settings
21+
22+
# Idea
23+
*.iml
24+
*.ipr
25+
*.iws
26+
.idea
27+
28+
# log
29+
*_IS_UNDEFINED
30+
logs
31+
*.log
32+
33+
# other
34+
*.bak
35+
.directory
36+
.DS_Store
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
8+
<parent>
9+
<artifactId>learning2017</artifactId>
10+
<groupId>me.lzb</groupId>
11+
<version>1.0</version>
12+
</parent>
13+
14+
15+
<artifactId>learning-basic</artifactId>
16+
<name>basic</name>
17+
<version>1.0</version>
18+
19+
20+
<dependencies>
21+
</dependencies>
22+
</project>

0 commit comments

Comments
 (0)