Skip to content

Commit c6ede9a

Browse files
committed
update codes
1 parent 6b81cf6 commit c6ede9a

Some content is hidden

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

42 files changed

+1266
-354
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
- 《Algorithms on Strings,Trees and Sequences》
8484
- 《Advanced Data Structures》 - 各种诡异高级的数据结构和算法 如元胞自动机、斐波纳契堆、线段树 600 块
8585
- 参考链接和学习网站
86+
- https://github.com/TheAlgorithms/Java
8687
- https://github.com/nonstriater/Learn-Algorithms
8788
- https://github.com/trekhleb/javascript-algorithms
8889
- https://github.com/kdn251/interviews/blob/master/README-zh-cn.md#%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84
@@ -99,7 +100,7 @@
99100
- <http://sjjg.js.zwu.edu.cn/SFXX/sf1/sfys.html>
100101
- <http://www.cs.usfca.edu/\~galles/visualization/Algorithms.html>
101102
- 编程网站
102-
- [leetcode](http://leetcode.com/)
103+
- [leetcode](http://leetcode-cn.com/)
103104
- [openjudge](http://openjudge.cn/)
104105
- 其它
105106
- [高级数据结构和算法](https://www.coursera.org/learn/gaoji-shuju-jiegou/) 北大教授张铭老师在 coursera 上的课程。完成这门课之时,你将掌握多维数组、广义表、Trie 树、AVL 树、伸展树等高级数据结构,并结合内排序、外排序、检索、索引有关的算法,高效地解决现实生活中一些比较复杂的应用问题。当然 coursera 上也还有很多其它算法方面的视频课程。

assets/list.eddx

31.8 KB
Binary file not shown.

codes/algorithm/pom.xml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66

7-
<groupId>io.github.dunwu</groupId>
7+
<parent>
8+
<groupId>io.github.dunwu</groupId>
9+
<artifactId>algorithm-tutorial</artifactId>
10+
<version>1.0.0</version>
11+
<relativePath>../../</relativePath>
12+
</parent>
13+
814
<artifactId>algorithm</artifactId>
9-
<version>1.0.1</version>
1015
<packaging>jar</packaging>
1116
<name>algorithm</name>
1217
<description>数据示例源码</description>
@@ -17,18 +22,4 @@
1722
<maven.compiler.source>${java.version}</maven.compiler.source>
1823
<maven.compiler.target>${java.version}</maven.compiler.target>
1924
</properties>
20-
21-
<dependencies>
22-
<dependency>
23-
<groupId>ch.qos.logback</groupId>
24-
<artifactId>logback-classic</artifactId>
25-
<version>1.1.3</version>
26-
</dependency>
27-
<dependency>
28-
<groupId>junit</groupId>
29-
<artifactId>junit</artifactId>
30-
<version>4.12</version>
31-
<scope>test</scope>
32-
</dependency>
33-
</dependencies>
3425
</project>

codes/algorithm/src/test/java/io/github/dunwu/algorithm/array/ThreeSumTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.github.dunwu.algorithm.array;
22

3-
import org.junit.Assert;
4-
import org.junit.Test;
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
55

66
import java.util.Arrays;
77
import java.util.List;
@@ -15,8 +15,8 @@ public class ThreeSumTest {
1515
@Test
1616
public void threeSumTest() {
1717
List<List<Integer>> list = ThreeSum.threeSum(new int[] { -1, 0, 1, 2, -1, -4 });
18-
Assert.assertEquals(Arrays.asList(-1, 0, 1), list.get(1));
19-
Assert.assertEquals(Arrays.asList(-1, -1, 2), list.get(0));
18+
Assertions.assertEquals(Arrays.asList(-1, 0, 1), list.get(1));
19+
Assertions.assertEquals(Arrays.asList(-1, -1, 2), list.get(0));
2020
}
2121

2222
}

codes/algorithm/src/test/java/io/github/dunwu/algorithm/search/SearchStrategyTest.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import io.github.dunwu.algorithm.search.strategy.BinarySearch;
44
import io.github.dunwu.algorithm.search.strategy.OrderSearch;
55
import io.github.dunwu.algorithm.util.ArrayUtil;
6-
import org.junit.*;
7-
import org.junit.runners.MethodSorters;
6+
import org.junit.jupiter.api.Assertions;
7+
import org.junit.jupiter.api.BeforeAll;
8+
import org.junit.jupiter.api.BeforeEach;
9+
import org.junit.jupiter.api.Test;
810

911
import java.util.Random;
1012

@@ -15,7 +17,6 @@
1517
*
1618
* @author Zhang Peng
1719
*/
18-
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
1920
public class SearchStrategyTest {
2021

2122
/**
@@ -42,7 +43,7 @@ public class SearchStrategyTest {
4243
/**
4344
* 生成随机数组样本,并调用 JDK api 生成期望的有序数组
4445
*/
45-
@BeforeClass
46+
@BeforeAll
4647
public static void beforeClass() {
4748
Random random = new Random();
4849

@@ -62,7 +63,7 @@ public static void beforeClass() {
6263
/**
6364
* 每次执行 @Test 前都使用生成的随机样本初始化实际用于排序的数组
6465
*/
65-
@Before
66+
@BeforeEach
6667
public void before() {
6768
}
6869

@@ -77,13 +78,13 @@ public void testOrderSearch() {
7778
*/
7879
private void executeSearch(SearchStrategy strategy) {
7980
int target01 = strategy.find(origin01, origin01[expected01]);
80-
Assert.assertEquals(expected01, target01);
81+
Assertions.assertEquals(expected01, target01);
8182

8283
int target02 = strategy.find(origin02, origin02[expected02]);
83-
Assert.assertEquals(expected02, target02);
84+
Assertions.assertEquals(expected02, target02);
8485

8586
int target03 = strategy.find(origin03, origin03[expected03]);
86-
Assert.assertEquals(expected03, target03);
87+
Assertions.assertEquals(expected03, target03);
8788
}
8889

8990
@Test

codes/algorithm/src/test/java/io/github/dunwu/algorithm/sort/SortStrategyTest.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import io.github.dunwu.algorithm.sort.strategy.*;
44
import io.github.dunwu.algorithm.util.ArrayUtil;
5-
import org.junit.*;
6-
import org.junit.runners.MethodSorters;
5+
import org.junit.jupiter.api.Assertions;
6+
import org.junit.jupiter.api.BeforeAll;
7+
import org.junit.jupiter.api.BeforeEach;
8+
import org.junit.jupiter.api.Test;
79

810
import java.util.Arrays;
911

@@ -14,7 +16,6 @@
1416
*
1517
* @author Zhang Peng
1618
*/
17-
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
1819
public class SortStrategyTest {
1920

2021
/**
@@ -47,7 +48,7 @@ public class SortStrategyTest {
4748
/**
4849
* 生成随机数组样本,并调用 JDK api 生成期望的有序数组
4950
*/
50-
@BeforeClass
51+
@BeforeAll
5152
public static void beforeClass() {
5253
// 在 [0, 100] 间生成长度为 10 的存在重复的随机数组
5354
origin01 = ArrayUtil.randomRepeatIntegerArray(0, 10, 9);
@@ -68,7 +69,7 @@ public static void beforeClass() {
6869
/**
6970
* 每次执行 @Test 前都使用生成的随机样本初始化实际用于排序的数组
7071
*/
71-
@Before
72+
@BeforeEach
7273
public void before() {
7374
target01 = Arrays.copyOf(origin01, origin01.length);
7475
target02 = Arrays.copyOf(origin02, origin02.length);
@@ -86,11 +87,11 @@ public void testBubbleSort() {
8687
*/
8788
private void executeSort(SortStrategy strategy) {
8889
strategy.sort(target01);
89-
Assert.assertArrayEquals(expected01, target01);
90+
Assertions.assertArrayEquals(expected01, target01);
9091
strategy.sort(target02);
91-
Assert.assertArrayEquals(expected02, target02);
92+
Assertions.assertArrayEquals(expected02, target02);
9293
strategy.sort(target03);
93-
Assert.assertArrayEquals(expected03, target03);
94+
Assertions.assertArrayEquals(expected03, target03);
9495
}
9596

9697
@Test
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.github.dunwu.algorithm.string;
22

3-
import org.junit.Assert;
4-
import org.junit.Test;
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
55

66
/**
77
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
@@ -12,85 +12,85 @@ public class StringAlgorithmTest {
1212
@Test
1313
public void lengthOfLongestSubstring() {
1414
int len = StringAlgorithm.lengthOfLongestSubstring("abcabcbb");
15-
Assert.assertEquals(3, len);
15+
Assertions.assertEquals(3, len);
1616

1717
len = StringAlgorithm.lengthOfLongestSubstring("bbbbb");
18-
Assert.assertEquals(1, len);
18+
Assertions.assertEquals(1, len);
1919

2020
len = StringAlgorithm.lengthOfLongestSubstring("pwwkew");
21-
Assert.assertEquals(3, len);
21+
Assertions.assertEquals(3, len);
2222
}
2323

2424
@Test
2525
public void longestCommonPrefix() {
2626
String str = StringAlgorithm.longestCommonPrefix(new String[] { "flower", "flow", "flight" });
27-
Assert.assertEquals("fl", str);
27+
Assertions.assertEquals("fl", str);
2828

2929
str = StringAlgorithm.longestCommonPrefix(new String[] { "dog", "racecar", "car" });
30-
Assert.assertEquals("", str);
30+
Assertions.assertEquals("", str);
3131
}
3232

3333
@Test
3434
public void checkInclusion() {
3535
boolean result = StringAlgorithm.checkInclusion("ab", "eidbaooo");
36-
Assert.assertEquals(true, result);
36+
Assertions.assertEquals(true, result);
3737

3838
result = StringAlgorithm.checkInclusion("ab", "eidboaoo");
39-
Assert.assertEquals(false, result);
39+
Assertions.assertEquals(false, result);
4040
}
4141

4242
@Test
4343
public void multiply() {
4444
String result = StringAlgorithm.multiply("2", "3");
45-
Assert.assertEquals("6", result);
45+
Assertions.assertEquals("6", result);
4646

4747
result = StringAlgorithm.multiply("333", "2");
48-
Assert.assertEquals("666", result);
48+
Assertions.assertEquals("666", result);
4949

5050
result = StringAlgorithm.multiply("123", "456");
51-
Assert.assertEquals("56088", result);
51+
Assertions.assertEquals("56088", result);
5252

5353
result = StringAlgorithm.multiply("123456789", "987654321");
54-
Assert.assertEquals("121932631112635269", result);
54+
Assertions.assertEquals("121932631112635269", result);
5555

5656
result = StringAlgorithm.multiply("498828660196", "840477629533");
57-
Assert.assertEquals("419254329864656431168468", result);
57+
Assertions.assertEquals("419254329864656431168468", result);
5858
}
5959

6060
@Test
6161
public void add() {
6262
String result = StringAlgorithm.add("100000000000000000000", "8888");
63-
Assert.assertEquals("100000000000000008888", result);
63+
Assertions.assertEquals("100000000000000008888", result);
6464

6565
result = StringAlgorithm.add("1368", "9120");
66-
Assert.assertEquals("10488", result);
66+
Assertions.assertEquals("10488", result);
6767
}
6868

6969
@Test
7070
public void reverseWords() {
7171
String result = StringAlgorithm.reverseWords("the sky is blue");
72-
Assert.assertEquals("blue is sky the", result);
72+
Assertions.assertEquals("blue is sky the", result);
7373

7474
result = StringAlgorithm.reverseWords(" hello world! ");
75-
Assert.assertEquals("world! hello", result);
75+
Assertions.assertEquals("world! hello", result);
7676

7777
result = StringAlgorithm.reverseWords("a good example");
78-
Assert.assertEquals("example good a", result);
78+
Assertions.assertEquals("example good a", result);
7979
}
8080

8181
@Test
8282
public void simplifyPath() {
8383
String result = StringAlgorithm.simplifyPath("/home/");
84-
Assert.assertEquals("/home", result);
84+
Assertions.assertEquals("/home", result);
8585

8686
result = StringAlgorithm.simplifyPath("/../");
87-
Assert.assertEquals("/", result);
87+
Assertions.assertEquals("/", result);
8888

8989
result = StringAlgorithm.simplifyPath("/home//foo/");
90-
Assert.assertEquals("/home/foo", result);
90+
Assertions.assertEquals("/home/foo", result);
9191

9292
result = StringAlgorithm.simplifyPath("/a/./b/../../c/");
93-
Assert.assertEquals("/c", result);
93+
Assertions.assertEquals("/c", result);
9494
}
9595

9696
}

codes/data-structure/pom.xml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66

7-
<groupId>io.github.dunwu</groupId>
7+
<parent>
8+
<groupId>io.github.dunwu</groupId>
9+
<artifactId>algorithm-tutorial</artifactId>
10+
<version>1.0.0</version>
11+
<relativePath>../../</relativePath>
12+
</parent>
13+
814
<artifactId>data-structure</artifactId>
9-
<version>1.0.1</version>
1015
<packaging>jar</packaging>
1116
<name>data-structure</name>
1217
<description>数据结构示例源码</description>
@@ -17,18 +22,4 @@
1722
<maven.compiler.source>${java.version}</maven.compiler.source>
1823
<maven.compiler.target>${java.version}</maven.compiler.target>
1924
</properties>
20-
21-
<dependencies>
22-
<dependency>
23-
<groupId>ch.qos.logback</groupId>
24-
<artifactId>logback-classic</artifactId>
25-
<version>1.1.3</version>
26-
</dependency>
27-
<dependency>
28-
<groupId>junit</groupId>
29-
<artifactId>junit</artifactId>
30-
<version>4.12</version>
31-
<scope>test</scope>
32-
</dependency>
33-
</dependencies>
3425
</project>

0 commit comments

Comments
 (0)