https://github.com/sleepingraven/algorithmnote
Practical utilities in algorithm learning / OJ accepting.
https://github.com/sleepingraven/algorithmnote
algorithm data-structure demo leetcode
Last synced: 3 months ago
JSON representation
Practical utilities in algorithm learning / OJ accepting.
- Host: GitHub
- URL: https://github.com/sleepingraven/algorithmnote
- Owner: sleepingraven
- License: apache-2.0
- Created: 2021-03-13T08:51:07.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-26T15:12:56.000Z (over 3 years ago)
- Last Synced: 2025-02-24T07:19:16.129Z (8 months ago)
- Topics: algorithm, data-structure, demo, leetcode
- Language: Java
- Homepage:
- Size: 216 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Note Structure
-
draft
OJ 代码编辑区域
-note
笔记/练习
-demo
,helloworld
一些题目和基本数据结构的练习
-huffman
用 Huffman 编码实现文件压缩
-practice
常见/常用算法实现
-util
工具/模板
-ac
,advanced
常用数据结构/工具类
-common
,function
,primitive
基础工具类
-datastructure
二叉树、链表的生成和格式化工具
## 1.
note
###
huffman
压缩/解压文件的程序实现
demo:
```java
String srcPath = "D:/new Text Document.pdf";
StoreWay storeWay = new CodeCustom();
CodingMethod codingMethod = new DefaultCodingMethod();Compressor compressor = new Compressor(1);
String destPath = compressor.compress(srcPath, storeWay, codingMethod);
Decompressor decompressor = new Decompressor();
String decompressPath = decompressor.decompress(destPath, codingMethod);System.out.println(destPath);
System.out.println(decompressPath);
```output:
```
……
用时: 834msD:\new Text Document.h_tar
D:\new Text Document(1).pdf
```###
practice
####
CircularVector
用来在矩阵中以螺旋的顺序生成一组下标
demo:
```java
final int n = 4;
int[][] matrix = new int[n][n];
CircularVector cv = new CircularVector(0, n - 1, 0, n - 1);
for (int i = 1; i <= n * n; i++) {
matrix[cv.x()][cv.y()] = i;
cv.next();
}String str = Arrays.stream(matrix).map(Arrays::toString).collect(Collectors.joining("\n"));
System.out.println(str);
```output:
```
[1, 2, 3, 4]
[12, 13, 14, 5]
[11, 16, 15, 6]
[10, 9, 8, 7]
```## 2.
util
###
ac
####
DataGenerator
用来
- 根据数组创建二叉树、链表
- 将字符串解析成数组demo:
```java
int[][] matrix = DataGenerator.parseIntArray("[[1,2,3],[4,5,6],[7,8,9]]", int[][].class);String str = Arrays.stream(matrix).map(Arrays::toString).collect(Collectors.joining("\n"));
System.out.println(str);
```output:
```
[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
```###
datastructure
用来
- 生成二叉树、链表
- 格式化二叉树、链表demo:
```java
final int n = 31;
Integer[] a = IntStream.range(1, n + 1).boxed().toArray(i -> new Integer[n]);
TreeNode treeNode = DataGenerator.buildTree(a);String str = treeNode.toString();
System.out.println(str);
```output:
```
1
/ \
2 3
/ \ / \
4 5 6 7
/ \ / \ / \ / \
8 9 10 11 12 13 14 15
/ \ / \ / \ / \ / \ / \ / \ / \
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
```