forked from diliuzuzhanghao/coding2017
-
Notifications
You must be signed in to change notification settings - Fork 0
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 diliuzuzhanghao#7 from DonaldY/master
合并组长的代码
- Loading branch information
Showing
171 changed files
with
7,041 additions
and
2,171 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
79 changes: 39 additions & 40 deletions
79
group24/1148285693/.gitignore → group24/1148285693/learning2017/.gitignore
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 |
---|---|---|
@@ -1,40 +1,39 @@ | ||
# 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 | ||
|
||
|
||
Test.java | ||
example | ||
# 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 | ||
|
||
|
||
Test.java |
54 changes: 54 additions & 0 deletions
54
group24/1148285693/learning2017/learning-basic/src/main/java/me/lzb/basic/FileList.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,54 @@ | ||
package me.lzb.basic; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* 给定一个目录,递归的列出下面所有的子目录和文件 | ||
* | ||
* @author LZB | ||
*/ | ||
public class FileList { | ||
|
||
public void list(File f) { | ||
System.out.println(f.getPath()); | ||
|
||
list(f, 0); | ||
} | ||
|
||
|
||
private void list(File file, int level) { | ||
if (file.isDirectory()) { | ||
print(file, level); | ||
} | ||
level++; | ||
File[] files = file.listFiles(); | ||
for (int i = 0; i < files.length; i++) { | ||
if (files[i].isDirectory()) { | ||
list(files[i], level); | ||
} else { | ||
print(files[i], level); | ||
} | ||
} | ||
} | ||
|
||
private void print(File f, int level) { | ||
System.out.println(getFileFormat(level) + f.getName()); | ||
|
||
} | ||
|
||
|
||
private String getFileFormat(int level) { | ||
StringBuffer sb = new StringBuffer(); | ||
if (level > 1) { | ||
sb.append("|"); | ||
} | ||
|
||
for (int i = 0; i < level - 1; i++) { | ||
sb.append(" "); | ||
} | ||
if (level > 0) { | ||
sb.append("|--"); | ||
} | ||
return sb.toString(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...src/main/java/me/lzb/basic/ArrayList.java → ...ain/java/me/lzb/basic/list/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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package me.lzb.basic; | ||
package me.lzb.basic.list; | ||
|
||
/** | ||
* 简易ArrayList | ||
|
2 changes: 1 addition & 1 deletion
2
...src/main/java/me/lzb/basic/ArrayUtil.java → ...ain/java/me/lzb/basic/list/ArrayUtil.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package me.lzb.basic; | ||
package me.lzb.basic.list; | ||
|
||
public class ArrayUtil { | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
.../src/main/java/me/lzb/basic/Iterator.java → ...main/java/me/lzb/basic/list/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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package me.lzb.basic; | ||
package me.lzb.basic.list; | ||
|
||
/** | ||
* Created by LZB on 2017/3/11. | ||
|
2 changes: 1 addition & 1 deletion
2
...rc/main/java/me/lzb/basic/LinkedList.java → ...in/java/me/lzb/basic/list/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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package me.lzb.basic; | ||
package me.lzb.basic.list; | ||
|
||
|
||
/** | ||
|
2 changes: 1 addition & 1 deletion
2
...asic/src/main/java/me/lzb/basic/List.java → ...src/main/java/me/lzb/basic/list/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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package me.lzb.basic; | ||
package me.lzb.basic.list; | ||
|
||
/** | ||
* list接口 | ||
|
2 changes: 1 addition & 1 deletion
2
group24/1148285693/learning2017/learning-basic/src/main/java/me/lzb/basic/queue/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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package me.lzb.basic.queue; | ||
|
||
import me.lzb.basic.LinkedList; | ||
import me.lzb.basic.list.LinkedList; | ||
|
||
/** | ||
* 先进先出 | ||
|
60 changes: 60 additions & 0 deletions
60
...148285693/learning2017/learning-basic/src/main/java/me/lzb/basic/stack/QuickMinStack.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,60 @@ | ||
package me.lzb.basic.stack; | ||
|
||
import java.util.Stack; | ||
|
||
/** | ||
* 设计一个栈,支持栈的push和pop操作,以及第三种操作findMin, 它返回改数据结构中的最小元素 | ||
* finMin操作最坏的情形下时间复杂度应该是O(1) , 简单来讲,操作一次就可以得到最小值 | ||
*/ | ||
public class QuickMinStack { | ||
private int mini; | ||
private java.util.Stack<Integer> stack = new Stack(); | ||
|
||
|
||
public void push(int data) { | ||
if (stack.size() <= 0) { | ||
mini = data; | ||
} else if (mini > data) { | ||
mini = data; | ||
} | ||
stack.push(data); | ||
} | ||
|
||
public int pop() { | ||
if (stack.isEmpty()) { | ||
throw new RuntimeException("stack is empty"); | ||
} | ||
|
||
|
||
int a = stack.pop(); | ||
if (a <= mini) { | ||
newMin(); | ||
} | ||
|
||
return a; | ||
} | ||
|
||
public int findMin() { | ||
if (stack.isEmpty()) { | ||
throw new RuntimeException("stack is empty"); | ||
} | ||
return mini; | ||
} | ||
|
||
|
||
private void newMin() { | ||
if (stack.isEmpty()) { | ||
return; | ||
} | ||
|
||
int a = stack.peek(); | ||
for (int i : stack) { | ||
if (i < a) { | ||
a = i; | ||
} | ||
} | ||
|
||
this.mini = a; | ||
} | ||
|
||
} |
4 changes: 3 additions & 1 deletion
4
...sic/src/main/java/me/lzb/basic/Stack.java → ...c/main/java/me/lzb/basic/stack/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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
package me.lzb.basic; | ||
package me.lzb.basic.stack; | ||
|
||
import me.lzb.basic.list.ArrayList; | ||
|
||
/** | ||
* 先进后出 | ||
|
2 changes: 1 addition & 1 deletion
2
...src/main/java/me/lzb/basic/StackUtil.java → ...in/java/me/lzb/basic/stack/StackUtil.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package me.lzb.basic; | ||
package me.lzb.basic.stack; | ||
|
||
import java.util.Stack; | ||
|
||
|
98 changes: 98 additions & 0 deletions
98
...5693/learning2017/learning-basic/src/main/java/me/lzb/basic/stack/StackWithTwoQueues.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,98 @@ | ||
package me.lzb.basic.stack; | ||
|
||
|
||
import java.util.LinkedList; | ||
|
||
public class StackWithTwoQueues { | ||
|
||
private java.util.Queue<Integer> queue1; | ||
private java.util.Queue<Integer> queue2; | ||
private boolean isOne; | ||
|
||
|
||
public StackWithTwoQueues() { | ||
queue1 = new LinkedList(); | ||
queue2 = new LinkedList(); | ||
isOne = true; | ||
} | ||
|
||
|
||
public boolean isEmpty() { | ||
return queue1.isEmpty() && queue2.isEmpty(); | ||
} | ||
|
||
|
||
public int size() { | ||
return queue1.isEmpty() ? queue2.size() : queue1.size(); | ||
} | ||
|
||
|
||
public void push(int data) { | ||
|
||
if (isOne) { | ||
queue1.add(data); | ||
} else { | ||
queue2.add(data); | ||
} | ||
} | ||
|
||
public int pop() { | ||
if (isEmpty()) { | ||
throw new RuntimeException(" Stack is empty now"); | ||
} | ||
|
||
int r; | ||
if (isOne) { | ||
|
||
while (queue1.size() > 1) { | ||
queue2.add(queue1.poll()); | ||
} | ||
r = queue1.poll(); | ||
isOne = false; | ||
} else { | ||
|
||
while (queue2.size() > 1) { | ||
queue1.add(queue2.poll()); | ||
} | ||
r = queue2.poll(); | ||
isOne = true; | ||
} | ||
|
||
return r; | ||
} | ||
|
||
|
||
@Override | ||
public String toString() { | ||
if (isEmpty()) { | ||
return "[]"; | ||
} | ||
StringBuffer sb = new StringBuffer(); | ||
sb.append("["); | ||
|
||
|
||
int a = 1; | ||
if (isOne) { | ||
for (int i : queue1) { | ||
sb.append(i); | ||
if (a < queue1.size()) { | ||
sb.append(","); | ||
} | ||
a++; | ||
} | ||
|
||
|
||
} else { | ||
for (int i : queue2) { | ||
sb.append(i); | ||
if (a < queue2.size()) { | ||
sb.append(","); | ||
} | ||
a++; | ||
} | ||
} | ||
|
||
sb.append("]"); | ||
return sb.toString(); | ||
} | ||
} |
Oops, something went wrong.