Skip to content

Commit 51135d6

Browse files
nibnaitnibnait
authored andcommitted
重新整理目录结构
0 parents  commit 51135d6

347 files changed

Lines changed: 28483 additions & 0 deletions

File tree

Some content is hidden

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

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Example user template template
3+
### Example user template
4+
5+
# IntelliJ project files
6+
.idea
7+
*.iml
8+
/target

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# 算法
2+
[算法篇](src/main/java/algorithm_practice/README.md)
3+
[数据结构](src/main/java/data_struct/README.md)
4+
5+
# 操作系统
6+
[jvm](src/main/java/os/jvm)
7+
8+
# 网络编程
9+
[netty](src/main/java/netty/README.md)

pom.xml

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" 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+
<groupId>org.tianbin</groupId>
8+
<artifactId>algorithm</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
<packaging>war</packaging>
11+
12+
<name>algorithm_practice Maven Webapp</name>
13+
<!-- FIXME change it to the project's website -->
14+
<url>http://www.example.com</url>
15+
16+
<properties>
17+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18+
<maven.compiler.source>1.8</maven.compiler.source>
19+
<maven.compiler.target>1.8</maven.compiler.target>
20+
</properties>
21+
22+
<dependencies>
23+
<!-- https://mvnrepository.com/artifact/cglib/cglib -->
24+
<dependency>
25+
<groupId>cglib</groupId>
26+
<artifactId>cglib</artifactId>
27+
<version>3.2.12</version>
28+
</dependency>
29+
<!-- https://mvnrepository.com/artifact/com.lmax/disruptor -->
30+
<dependency>
31+
<groupId>com.lmax</groupId>
32+
<artifactId>disruptor</artifactId>
33+
<version>3.2.0</version>
34+
</dependency>
35+
<!-- https://mvnrepository.com/artifact/io.netty/netty-all -->
36+
<dependency>
37+
<groupId>io.netty</groupId>
38+
<artifactId>netty-all</artifactId>
39+
<version>4.1.44.Final</version>
40+
</dependency>
41+
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
42+
<dependency>
43+
<groupId>org.apache.commons</groupId>
44+
<artifactId>commons-lang3</artifactId>
45+
<version>3.8.1</version>
46+
</dependency>
47+
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
48+
<dependency>
49+
<groupId>com.alibaba</groupId>
50+
<artifactId>fastjson</artifactId>
51+
<version>1.2.47</version>
52+
</dependency>
53+
<!-- https://mvnrepository.com/artifact/com.google.collections/google-collections -->
54+
<dependency>
55+
<groupId>com.google.collections</groupId>
56+
<artifactId>google-collections</artifactId>
57+
<version>1.0</version>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.projectlombok</groupId>
61+
<artifactId>lombok</artifactId>
62+
<version>1.18.4</version>
63+
</dependency>
64+
<dependency>
65+
<groupId>net.sourceforge.jexcelapi</groupId>
66+
<artifactId>jxl</artifactId>
67+
<version>2.6.12</version>
68+
</dependency>
69+
<dependency>
70+
<groupId>junit</groupId>
71+
<artifactId>junit</artifactId>
72+
<version>4.12</version>
73+
<scope>test</scope>
74+
</dependency>
75+
<dependency>
76+
<groupId>junit</groupId>
77+
<artifactId>junit</artifactId>
78+
<version>4.12</version>
79+
<scope>compile</scope>
80+
</dependency>
81+
</dependencies>
82+
83+
<build>
84+
<finalName>algorithm_practice</finalName>
85+
<pluginManagement><!-- concurrent down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
86+
<plugins>
87+
<plugin>
88+
<artifactId>maven-clean-plugin</artifactId>
89+
<version>3.1.0</version>
90+
</plugin>
91+
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
92+
<plugin>
93+
<artifactId>maven-resources-plugin</artifactId>
94+
<version>3.0.2</version>
95+
</plugin>
96+
<plugin>
97+
<artifactId>maven-compiler-plugin</artifactId>
98+
<version>3.8.0</version>
99+
</plugin>
100+
<plugin>
101+
<artifactId>maven-surefire-plugin</artifactId>
102+
<version>2.22.1</version>
103+
</plugin>
104+
<plugin>
105+
<artifactId>maven-war-plugin</artifactId>
106+
<version>3.2.2</version>
107+
</plugin>
108+
<plugin>
109+
<artifactId>maven-install-plugin</artifactId>
110+
<version>2.5.2</version>
111+
</plugin>
112+
<plugin>
113+
<artifactId>maven-deploy-plugin</artifactId>
114+
<version>2.8.2</version>
115+
</plugin>
116+
</plugins>
117+
</pluginManagement>
118+
</build>
119+
</project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列;
2+
3+
import junit.framework.TestCase;
4+
import org.junit.Test;
5+
6+
import java.util.Stack;
7+
8+
/*
9+
设计一个有getMin 功能的栈
10+
11+
【题目】
12+
实现一个特殊的栈,在实现栈的基本功能的基础上,再实现返回栈中最小元素的操作。
13+
14+
【要求】
15+
1.pop、push、getMin 操作的时间复杂度都是O(1)。
16+
17+
2.设计的栈类型可以使用现成的栈结构。
18+
19+
【难度】
20+
士 ★☆☆☆
21+
*/
22+
public class P01_GetMinStack extends TestCase {
23+
24+
@Test
25+
public void testCase() {
26+
27+
}
28+
29+
class MyStack {
30+
private Stack<Integer> stackData;
31+
private Stack<Integer> stackMin; //加一个最小值栈。getMin直接 stackMin.peek()
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列;
2+
3+
import junit.framework.TestCase;
4+
import org.junit.Test;
5+
6+
import java.util.Stack;
7+
8+
/*
9+
由两个栈组成的队列
10+
11+
【题目】
12+
编写一个类,用两个栈实现队列,支持队列的基本操作(add、poll、peek)。
13+
14+
【难度】
15+
尉 ★★☆☆
16+
*/
17+
public class P02_由两个栈组成的队列 extends TestCase {
18+
19+
@Test
20+
public void testCase() {
21+
22+
}
23+
24+
25+
class TwoStackQueue {
26+
private Stack<Integer> stackPush;
27+
private Stack<Integer> stackPop;
28+
29+
public TwoStackQueue() {
30+
this.stackPush = new Stack<>();
31+
this.stackPop = new Stack<>();
32+
}
33+
34+
//stackPop不为空,stackPush绝对不能像stackPop压入数据
35+
private void pushToPop() {
36+
if (stackPop.isEmpty()) {
37+
while (!stackPop.isEmpty()) {
38+
stackPop.push(stackPush.pop());
39+
}
40+
}
41+
}
42+
43+
public void add(Integer pushInt) {
44+
stackPush.push(pushInt);
45+
pushToPop();
46+
}
47+
48+
public Integer poll() {
49+
if (stackPush.isEmpty() && stackPop.isEmpty()) {
50+
throw new RuntimeException("Queue is empty");
51+
}
52+
pushToPop();
53+
return stackPop.pop();
54+
}
55+
56+
public Integer peek() {
57+
if (stackPush.isEmpty() && stackPop.isEmpty()) {
58+
throw new RuntimeException("Queue is empty");
59+
}
60+
pushToPop();
61+
return stackPop.peek();
62+
}
63+
}
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列;
2+
3+
import common.util.StandardInit;
4+
import common.util.SysOut;
5+
import junit.framework.TestCase;
6+
import org.junit.Test;
7+
8+
import java.util.Stack;
9+
10+
/*
11+
【题目】
12+
一个栈依次压入1、2、3、4、5,那么从栈顶到栈底分别为5、4、3、2、1。将这个栈转置后,从栈顶到栈底为1、2、3、4、5,也就是实现栈中元素的逆序,但是只能用递归函数来实现,不能用其他数据结构。
13+
14+
【难度】
15+
尉 ★★☆☆
16+
*/
17+
public class P03_使用递归逆序一个栈 extends TestCase {
18+
19+
@Test
20+
public void testCase() {
21+
Stack<Integer> stack = StandardInit.initStack();
22+
reverseStackUsingRecursive(stack);
23+
24+
SysOut.printStack(stack);
25+
}
26+
27+
/**
28+
* 设计递归
29+
* @param stack
30+
*/
31+
private void reverseStackUsingRecursive(Stack<Integer> stack) {
32+
if (stack.isEmpty()) {
33+
return ;
34+
}
35+
Integer lastElement = getStackLastElement(stack);
36+
reverseStackUsingRecursive(stack);
37+
stack.push(lastElement);
38+
}
39+
40+
private Integer getStackLastElement(Stack<Integer> stack) {
41+
Integer result = stack.pop();
42+
if (stack.isEmpty()) {
43+
return result;
44+
} else {
45+
Integer stackLastElement = getStackLastElement(stack);
46+
stack.push(result);
47+
return stackLastElement;
48+
}
49+
}
50+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列;
2+
3+
import junit.framework.TestCase;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Getter;
6+
import org.junit.Test;
7+
8+
import java.util.LinkedList;
9+
import java.util.Queue;
10+
11+
/*
12+
【题目】
13+
实现一种狗猫队列的结构,要求如下:
14+
用户可以调用add 方法将cat 类或dog 类的实例放入队列中;
15+
用户可以调用pollAll 方法,将队列中所有的实例按照进队列的先后顺序依次弹出;
16+
用户可以调用pollDog 方法,将队列中dog 类的实例按照进队列的先后顺序依次弹出;
17+
用户可以调用pollCat 方法,将队列中cat 类的实例按照进队列的先后顺序依次弹出;
18+
用户可以调用isEmpty 方法,检查队列中是否还有dog 或cat 的实例;
19+
用户可以调用isDogEmpty 方法,检查队列中是否有dog 类的实例;
20+
用户可以调用isCatEmpty 方法,检查队列中是否有cat 类的实例。
21+
22+
【难度】
23+
士 ★☆☆☆
24+
*/
25+
public class P04_猫狗队列 extends TestCase {
26+
27+
@Getter
28+
@AllArgsConstructor
29+
public class Pet {
30+
private String type;
31+
}
32+
33+
public class Dog extends Pet {
34+
public Dog() {
35+
super("dog");
36+
}
37+
}
38+
public class Cat extends Pet {
39+
public Cat() {
40+
super("cat");
41+
}
42+
}
43+
44+
45+
@Test
46+
public void testCase() {
47+
48+
}
49+
50+
@Getter
51+
@AllArgsConstructor
52+
class PetEnterQueue {
53+
private Pet pet;
54+
private long count; //此Pet进入队列的时间戳
55+
56+
public String getEnterPetType() {
57+
return pet.getType();
58+
}
59+
}
60+
61+
class CatDowQueue {
62+
private Queue<PetEnterQueue> dogQ;
63+
private Queue<PetEnterQueue> catQ;
64+
private long count; //进入大队列的时间戳
65+
66+
public CatDowQueue() {
67+
dogQ = new LinkedList<PetEnterQueue>();
68+
catQ = new LinkedList<PetEnterQueue>();
69+
count = 0;
70+
}
71+
72+
public void add(Pet pet) {
73+
if ("dog".equals(pet.getType())) {
74+
this.dogQ.add(new PetEnterQueue(pet, count++));
75+
} else if ("cat".equals(pet.getType())) {
76+
this.catQ.add(new PetEnterQueue(pet, count++));
77+
} else {
78+
throw new RuntimeException("err, not dog, not cat");
79+
}
80+
}
81+
82+
83+
}
84+
}

0 commit comments

Comments
 (0)