Skip to content

Commit df4cbdb

Browse files
author
FuJianXin
committed
去除 并发模块代码
1 parent 564662d commit df4cbdb

14 files changed

Lines changed: 277 additions & 473 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package jianzhioffer;
2+
3+
import java.util.Stack;
4+
5+
/**
6+
*〈一句话功能简述〉<br>
7+
*〈栈的压入、弹出序列〉
8+
*
9+
* @author 一个鲁肃
10+
* @create 2018/8/14
11+
* @since 1.0.0
12+
*/
13+
public class IsPopOrder {
14+
15+
16+
public boolean isPopOrder(int [] pushA,int [] popA) {
17+
if (pushA.length == 0 || popA.length == 0){
18+
return false;
19+
}
20+
Stack<Integer> stack = new Stack<>();
21+
//记录弹出序列的未知
22+
int index = 0;
23+
for (int aPushA : pushA) {
24+
stack.push(aPushA);
25+
while (!stack.isEmpty() && stack.peek() == popA[index]) {
26+
//入栈序列与出栈序列比较的过程
27+
stack.pop();
28+
index++;
29+
}
30+
}
31+
return stack.empty() ? true : false;
32+
}
33+
34+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package jianzhioffer;
2+
3+
import java.util.Stack;
4+
5+
/**
6+
*〈一句话功能简述〉<br>
7+
*〈实现一个包含getMin函数的栈空间〉
8+
*
9+
* @author 一个鲁肃
10+
* @create 2018/8/14
11+
* @since 1.0.0
12+
*/
13+
public class MinStack {
14+
15+
/**
16+
* 使用一个额外的栈,用来存储最小值
17+
*/
18+
private Stack<Integer> minStack;
19+
20+
/**
21+
* 用于用于存储压栈的数字
22+
*/
23+
private Stack<Integer> dataStack;
24+
25+
26+
public void push(Integer num){
27+
dataStack.push(num);
28+
if (minStack.isEmpty()){
29+
minStack.push(num);
30+
}else if (minStack.peek() > dataStack.peek()){
31+
minStack.push(num);
32+
}else {
33+
minStack.push(minStack.peek());
34+
}
35+
}
36+
37+
38+
public Integer pop() throws Exception {
39+
if (dataStack.empty()){
40+
throw new RuntimeException("dataStack is empty");
41+
}
42+
minStack.pop();
43+
return dataStack.pop();
44+
}
45+
46+
47+
public Integer peek() throws Exception {
48+
if (dataStack.empty()){
49+
throw new RuntimeException("dataStack is empty");
50+
}
51+
return dataStack.peek();
52+
}
53+
54+
55+
public Integer getMin(){
56+
if (minStack.empty()){
57+
throw new RuntimeException("minStack is empty");
58+
}
59+
return minStack.peek();
60+
}
61+
62+
63+
}

AlgorithmTest/AlgorithmTest/src/jianzhioffer/Mirror.java

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package jianzhioffer;
22

3+
import java.util.Stack;
4+
35
/**
46
*〈一句话功能简述〉<br>
57
*〈二叉树的镜像〉
@@ -10,10 +12,66 @@
1012
*/
1113
public class Mirror {
1214

15+
/**
16+
* 功能描述: <br>
17+
*〈将给定的二叉树转换成它的镜像树〉
18+
*
19+
* @param:root 根节点
20+
* @since: 1.0.0
21+
* @Author: 一个鲁肃
22+
* @Date: 2018/8/13 18:37
23+
*/
24+
public void mirror(TreeNode root) {
25+
//代码的鲁棒性
26+
if (root == null){
27+
return;
28+
}
29+
//case
30+
if (root.left == null && root.right == null){
31+
return;
32+
}
33+
//swap
34+
TreeNode temp = root.left;
35+
root.left = root.right;
36+
root.right = temp;
1337

14-
public void Mirror(TreeNode root) {
38+
//子节点继续进行判断
39+
if (root.left != null){
40+
mirror(root.left);
41+
}
42+
if (root.right != null){
43+
mirror(root.right);
44+
}
45+
}
1546

47+
/**
48+
* 额外空间栈
49+
* @param root 根节点
50+
*/
51+
public void mirror1(TreeNode root){
52+
//代码的鲁棒性
53+
if (root == null){
54+
return;
55+
}
56+
//额外空间栈
57+
Stack<TreeNode> stack = new Stack<>();
58+
stack.push(root);
59+
while (!stack.isEmpty()){
60+
TreeNode node = stack.pop();
61+
if (node.left != null || node.right != null){
62+
TreeNode temp = node.left;
63+
node.left = node.right;
64+
node.right = temp;
65+
}
66+
if (root.left != null){
67+
stack.push(root.left);
68+
}
69+
if (root.left != null){
70+
stack.push(root.left);
71+
}
72+
}
1673
}
1774

1875

76+
1977
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package jianzhioffer;
2+
3+
import java.util.ArrayList;
4+
5+
/**
6+
*〈一句话功能简述〉<br>
7+
*〈从上往下打印二叉树〉
8+
*
9+
* @author 一个鲁肃
10+
* @create 2018/8/14
11+
* @since 1.0.0
12+
*/
13+
public class PrintFromTopToBottom {
14+
15+
public ArrayList<Integer> printFromTopToBottom(TreeNode root) {
16+
//TODO
17+
return null;
18+
}
19+
20+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package jianzhioffer;
2+
3+
import java.util.ArrayList;
4+
5+
/**
6+
*〈一句话功能简述〉<br>
7+
*〈顺时针打印矩阵〉
8+
*
9+
* @author 一个鲁肃
10+
* @create 2018/8/14
11+
* @since 1.0.0
12+
*/
13+
public class PrintMatrix {
14+
15+
public ArrayList<Integer> printMatrix(int [][] matrix) {
16+
//存储结果集
17+
ArrayList<Integer> list = new ArrayList<>();
18+
19+
20+
return null;
21+
}
22+
23+
24+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package jianzhioffer;
2+
3+
/**
4+
*〈一句话功能简述〉<br>
5+
*〈二叉搜索树的后序遍历〉
6+
*〈输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。
7+
* 如果是则输出Yes,否则输出No。假设输入的数组的任意两个数字都互不相同。〉
8+
*
9+
* @author 一个鲁肃
10+
* @create 2018/8/14
11+
* @since 1.0.0
12+
*/
13+
public class VerifySquenceOfBST {
14+
15+
/**
16+
* 功能描述: <br>
17+
*〈非递归版本〉
18+
*
19+
* @param:sequence
20+
* @return: boolean
21+
*/
22+
public boolean verifySquenceOfBST1(int [] sequence) {
23+
//TODO
24+
int size = sequence.length;
25+
if (size == 0){
26+
return false;
27+
}
28+
//定义指针变量
29+
int i = 0;
30+
while (--size > 0){
31+
while (sequence[i] < sequence[size]){
32+
i++;
33+
}
34+
while (sequence[i] > sequence[size]){
35+
i++;
36+
}
37+
if (i < size) {
38+
return false;
39+
}
40+
i = 0;
41+
}
42+
return true;
43+
}
44+
45+
/**
46+
* 功能描述: <br>
47+
*〈递归版本〉
48+
*
49+
* @param:sequence
50+
* @return: boolean
51+
*/
52+
public boolean verifySquenceOfBST2(int [] sequence) {
53+
//TODO
54+
if (sequence == null || sequence.length == 0){
55+
return false;
56+
}
57+
return judge(sequence,0,sequence.length-1);
58+
}
59+
60+
public boolean judge(int[] arr,int start,int end){
61+
if (start >= end){
62+
return true;
63+
}
64+
int index = start;
65+
while (arr[index] < arr[end]){
66+
index++;
67+
}
68+
for (int i = index;i < end;i++){
69+
if (arr[i] < arr[end]){
70+
return false;
71+
}
72+
}
73+
74+
return judge(arr,start,index-1) && judge(arr,index,end-1);
75+
}
76+
77+
}

ThreadCoding/.idea/encodings.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

ThreadCoding/.idea/inspectionProfiles/Project_Default.xml

Lines changed: 0 additions & 36 deletions
This file was deleted.

ThreadCoding/.idea/misc.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

ThreadCoding/.idea/modules.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)