Skip to content

Commit babb79a

Browse files
committed
feat: 全排列算法可视化演示工具
- 回溯树动态可视化 - 算法状态实时追踪 - 动画播放控制 - Java 调试器风格代码面板 - 教程模式 - GitHub Pages 部署配置
0 parents  commit babb79a

Some content is hidden

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

72 files changed

+15306
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Deploy to GitHub Pages
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
13+
concurrency:
14+
group: pages
15+
cancel-in-progress: false
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: '20'
28+
cache: 'npm'
29+
30+
- name: Install dependencies
31+
run: npm ci
32+
33+
- name: Build
34+
run: npm run build
35+
env:
36+
BASE_URL: /leetcode-46-permutations/
37+
38+
- name: Setup Pages
39+
uses: actions/configure-pages@v4
40+
41+
- name: Upload artifact
42+
uses: actions/upload-pages-artifact@v3
43+
with:
44+
path: ./dist
45+
46+
deploy:
47+
environment:
48+
name: github-pages
49+
url: ${{ steps.deployment.outputs.page_url }}
50+
runs-on: ubuntu-latest
51+
needs: build
52+
steps:
53+
- name: Deploy to GitHub Pages
54+
id: deployment
55+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Build output
5+
dist/
6+
7+
# IDE
8+
.idea/
9+
*.swp
10+
*.swo
11+
.vscode/*
12+
!.vscode/extensions.json
13+
14+
# OS
15+
.DS_Store
16+
Thumbs.db
17+
18+
# Logs
19+
*.log
20+
npm-debug.log*
21+
yarn-debug.log*
22+
yarn-error.log*
23+
24+
# Environment
25+
.env
26+
.env.local
27+
.env.*.local
28+
29+
# TypeScript
30+
*.tsbuildinfo
31+
32+
# Test coverage
33+
coverage/
34+
35+
# Temporary files
36+
*.tmp
37+
*.temp
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Requirements Document
2+
3+
## Introduction
4+
5+
本项目旨在增强全排列算法可视化演示工具,参考 LeetCode 题解(liweiwei1419)的讲解方式,添加更深入的算法概念解释功能。核心目标是帮助用户理解回溯算法的"选择-探索-撤销"模式、used 数组的作用、以及递归调用栈的变化过程。
6+
7+
## Glossary
8+
9+
- **Algorithm_Explainer**: 算法解释增强系统
10+
- **Used_Array**: 标记数组,记录每个数字是否已被选择到当前路径中
11+
- **Recursion_Stack**: 递归调用栈,展示当前递归深度和每层的状态
12+
- **Choice_Pattern**: "选择-探索-撤销"模式,回溯算法的核心操作流程
13+
- **Pruning_Indicator**: 剪枝指示器,展示哪些分支被跳过及原因
14+
- **Algorithm_Pseudocode**: 算法伪代码,与当前执行步骤同步高亮
15+
16+
## Requirements
17+
18+
### Requirement 1
19+
20+
**User Story:** As a user, I want to see the used array visualization, so that I can understand how the algorithm tracks which numbers have been selected.
21+
22+
#### Acceptance Criteria
23+
24+
1. WHILE the animation is running THEN the Algorithm_Explainer SHALL display a Used_Array showing true/false status for each input number
25+
2. WHEN a number is selected into the current path THEN the Algorithm_Explainer SHALL animate the corresponding Used_Array element changing from false to true
26+
3. WHEN the algorithm backtracks THEN the Algorithm_Explainer SHALL animate the corresponding Used_Array element changing from true to false
27+
4. THE Algorithm_Explainer SHALL display the Used_Array with visual distinction between used (true) and unused (false) states
28+
29+
### Requirement 2
30+
31+
**User Story:** As a user, I want to see the recursion call stack, so that I can understand the depth and state of recursive calls.
32+
33+
#### Acceptance Criteria
34+
35+
1. WHILE the animation is running THEN the Algorithm_Explainer SHALL display a Recursion_Stack showing all active recursive call frames
36+
2. WHEN a new recursive call is made (select step) THEN the Algorithm_Explainer SHALL push a new frame onto the Recursion_Stack display
37+
3. WHEN the algorithm backtracks THEN the Algorithm_Explainer SHALL pop the top frame from the Recursion_Stack display
38+
4. WHEN displaying each stack frame THEN the Algorithm_Explainer SHALL show the current depth level and the path state at that level
39+
40+
### Requirement 3
41+
42+
**User Story:** As a user, I want to see the "choose-explore-unchoose" pattern highlighted, so that I can understand the core backtracking operation.
43+
44+
#### Acceptance Criteria
45+
46+
1. WHEN a select step occurs THEN the Algorithm_Explainer SHALL display "选择" (Choose) phase indicator with the selected number
47+
2. WHEN exploring child branches THEN the Algorithm_Explainer SHALL display "探索" (Explore) phase indicator
48+
3. WHEN a backtrack step occurs THEN the Algorithm_Explainer SHALL display "撤销" (Unchoose) phase indicator with the removed number
49+
4. THE Algorithm_Explainer SHALL use distinct colors for each phase of the Choice_Pattern
50+
51+
### Requirement 4
52+
53+
**User Story:** As a user, I want to see synchronized pseudocode highlighting, so that I can connect the visualization to the actual algorithm code.
54+
55+
#### Acceptance Criteria
56+
57+
1. THE Algorithm_Explainer SHALL display Algorithm_Pseudocode for the backtracking algorithm in a code panel
58+
2. WHEN a select step occurs THEN the Algorithm_Explainer SHALL highlight the "选择" code line in the pseudocode
59+
3. WHEN a recursive call is made THEN the Algorithm_Explainer SHALL highlight the "递归" code line in the pseudocode
60+
4. WHEN a backtrack step occurs THEN the Algorithm_Explainer SHALL highlight the "撤销" code line in the pseudocode
61+
5. WHEN a complete permutation is found THEN the Algorithm_Explainer SHALL highlight the "添加结果" code line in the pseudocode
62+
63+
### Requirement 5
64+
65+
**User Story:** As a user, I want to see why certain branches are not explored, so that I can understand the pruning logic.
66+
67+
#### Acceptance Criteria
68+
69+
1. WHEN the algorithm skips a number because it is already used THEN the Algorithm_Explainer SHALL display a Pruning_Indicator explaining the skip reason
70+
2. WHEN hovering over an unexplored branch in the tree THEN the Algorithm_Explainer SHALL show a tooltip explaining why that branch was pruned
71+
3. THE Algorithm_Explainer SHALL visually distinguish pruned branches from unexplored branches in the tree visualization
72+
73+
</content>
74+
</invoke>

0 commit comments

Comments
 (0)