This commit is contained in:
2026-06-15 09:00:38 +08:00
parent fec66377d5
commit 4640c5e02b
191 changed files with 6046 additions and 0 deletions
+405
View File
@@ -0,0 +1,405 @@
<template>
<div class="chapter-view" v-if="chapter">
<header class="chapter-header">
<div class="chapter-icon">{{ chapter.icon }}</div>
<div>
<h1 class="chapter-title">{{ chapter.title }}</h1>
<p class="chapter-subtitle">{{ chapter.subtitle }}</p>
<p class="chapter-desc">{{ chapter.description }}</p>
</div>
</header>
<section class="topics-section">
<h2 class="section-label">📌 本章知识点</h2>
<div class="topics-list">
<span v-for="topic in chapter.topics" :key="topic" class="topic-pill">
{{ topic }}
</span>
</div>
</section>
<!-- 子文件夹分组显示 -->
<section v-for="folder in chapter.subfolders" :key="folder.name" class="folder-section">
<h2 class="folder-title">📂 {{ folder.label }}</h2>
<p class="folder-hint" v-if="getFolderDescription(folder.name)">{{ getFolderDescription(folder.name) }}</p>
<!-- 动态演示入口 -->
<div v-if="folder.demo" class="demo-entry">
<router-link :to="folder.demo.path" class="demo-link">
<span class="demo-link-icon">{{ folder.demo.label.split(' ')[0] }}</span>
<span class="demo-link-text">{{ folder.demo.label }}</span>
<span class="demo-link-desc">{{ folder.demo.description }}</span>
<span class="demo-link-arrow"></span>
</router-link>
</div>
<div class="file-list">
<div
v-for="file in folder.files"
:key="file.path"
class="file-item"
:class="{ active: currentFile?.path === file.path }"
@click="selectFile(file)"
>
<div class="file-item-header">
<span class="file-item-icon">📄</span>
<span class="file-item-name">{{ file.name }}</span>
<span class="file-item-label">{{ file.label }}</span>
</div>
<p class="file-item-desc">{{ file.description }}</p>
</div>
</div>
</section>
<!-- 根级文件没有子文件夹的文件 -->
<section v-if="chapter.files && chapter.files.length" class="folder-section">
<h2 class="folder-title">📂 其他示例</h2>
<div class="file-list">
<div
v-for="file in chapter.files"
:key="file.path"
class="file-item"
:class="{ active: currentFile?.path === file.path }"
@click="selectFile(file)"
>
<div class="file-item-header">
<span class="file-item-icon">📄</span>
<span class="file-item-name">{{ file.name }}</span>
<span class="file-item-label">{{ file.label }}</span>
</div>
<p class="file-item-desc">{{ file.description }}</p>
</div>
</div>
</section>
<!-- 代码查看区域 -->
<section v-if="currentFile" class="code-section">
<h2 class="section-label code-section-label">💻 代码查看</h2>
<CodeViewer
:filePath="currentFile.path"
:fileName="currentFile.name"
:fileLabel="currentFile.label"
:description="currentFile.description"
/>
</section>
<section v-else class="empty-section">
<div class="empty-state">
<span class="empty-icon">👆</span>
<p>请从上方选择一个代码文件查看其源码</p>
</div>
</section>
</div>
<div v-else class="not-found">
<h2>章节未找到</h2>
<p>请返回首页重新选择</p>
<router-link to="/" class="back-link"> 返回首页</router-link>
</div>
</template>
<script setup>
import { ref, computed, watch } from 'vue'
import { useRoute } from 'vue-router'
import { getChapterById } from '../data/chapters.js'
import CodeViewer from '../components/CodeViewer.vue'
const props = defineProps({
id: String
})
const route = useRoute()
const chapterId = computed(() => props.id || route.params.id)
const currentFile = ref(null)
const chapter = computed(() => getChapterById(chapterId.value))
// Reset current file when switching chapters
watch(chapterId, () => {
currentFile.value = null
})
function selectFile(file) {
currentFile.value = file
}
function getFolderDescription(folderName) {
const descriptions = {
mergesort: '归并排序是分治法的经典应用:将数组一分为二,分别排序后合并。时间复杂度 O(n log n)。',
quicksort: '快速排序通过选择一个基准元素,将数组分为左右两部分,递归排序。平均时间复杂度 O(n log n)。',
halfsearch: '二分查找在有序数组中通过每次将搜索范围缩小一半来查找目标值,时间复杂度 O(log n)。',
bigcheng: '大整数乘法通过分治策略将 n 位数乘法分解为更小规模的计算,降低时间复杂度。',
matrix: '矩阵乘法有多种实现方式:朴素算法 O(n³),Strassen 分治算法可优化至 O(n^2.81)。',
digui: '递归是分治法的基石,通过这些示例理解递归的基本结构与调用栈。',
maopao: '冒泡排序通过相邻元素比较交换将最大元素"冒泡"到末尾,时间复杂度 O(n²)。',
allpai: '全排列生成所有 n! 种排列方式,是回溯思想和分治策略的典型应用。',
richeng: '循环赛日程表使用分治策略为 2^k 个选手安排比赛日程。',
bag01: '0/1背包问题是动态规划的经典问题:给定容量和物品,求最大价值。',
lcs: '最长公共子序列(LCS)问题是比较两个序列相似度的经典DP问题。',
image: '图像压缩问题使用动态规划确定最优的像素段划分,平衡压缩比与存储空间。',
homework: '课后练习中的算法实现示例。',
huodong: '活动选择问题是贪心算法的经典案例:选择最多的不重叠活动。',
huffman: 'Huffman编码是数据压缩经典算法,通过构造最优前缀码实现无损压缩。',
bag: '贪心背包(部分背包)问题允许取物品的一部分,按单位价值贪心选择。',
bestload: '最优装载问题:在载重限制下尽可能多地装载物品。',
money: '找零问题:使用最少硬币凑出指定金额。',
shortest: '最短路径问题:寻找图中两点之间的最短路径。',
hui01bag: '0/1背包的回溯解法:通过深度优先搜索和剪枝寻找最优解。',
loading: '装载问题的回溯解法:搜索最优的装载方案。',
queue: 'N皇后问题的回溯解法:在 N×N 棋盘上放置 N 个皇后使其互不攻击。',
xianbag01: '0/1背包的分支限界解法:使用队列或优先队列进行广度优先搜索。',
tsp: '旅行商问题(TSP):寻找最短的环游所有城市的路径。',
graph: '图的两种基本遍历方式:广度优先(BFS)和深度优先(DFS)。'
}
return descriptions[folderName] || ''
}
</script>
<style scoped>
.chapter-view {
max-width: 1000px;
margin: 0 auto;
padding: 0 24px;
}
.chapter-header {
display: flex;
gap: 16px;
align-items: flex-start;
padding: 32px 0 20px;
border-bottom: 1px solid var(--border-color);
margin-bottom: 24px;
}
.chapter-icon {
font-size: 48px;
flex-shrink: 0;
}
.chapter-title {
font-size: 26px;
font-weight: 800;
color: var(--text-primary);
margin-bottom: 4px;
}
.chapter-subtitle {
font-size: 15px;
color: var(--primary-color);
font-weight: 500;
margin-bottom: 6px;
}
.chapter-desc {
font-size: 14px;
color: var(--text-secondary);
line-height: 1.6;
}
.section-label {
font-size: 18px;
font-weight: 700;
color: var(--text-primary);
margin-bottom: 12px;
}
.topics-section {
margin-bottom: 28px;
}
.topics-list {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.topic-pill {
font-size: 13px;
background: var(--active-bg);
color: var(--primary-color);
padding: 6px 16px;
border-radius: 20px;
font-weight: 500;
border: 1px solid var(--border-color);
}
.folder-section {
margin-bottom: 28px;
}
.folder-title {
font-size: 17px;
font-weight: 700;
color: var(--text-primary);
margin-bottom: 6px;
padding-bottom: 8px;
border-bottom: 2px solid var(--border-color);
}
.folder-hint {
font-size: 13px;
color: var(--text-tertiary);
margin-bottom: 12px;
line-height: 1.5;
}
/* 动态演示入口 */
.demo-entry {
margin-bottom: 12px;
}
.demo-link {
display: flex;
align-items: center;
gap: 10px;
padding: 12px 16px;
background: linear-gradient(135deg, rgba(59, 130, 246, 0.08), rgba(139, 92, 246, 0.08));
border: 1px solid rgba(59, 130, 246, 0.25);
border-radius: 10px;
text-decoration: none;
transition: all 0.2s ease;
}
.demo-link:hover {
background: linear-gradient(135deg, rgba(59, 130, 246, 0.15), rgba(139, 92, 246, 0.15));
border-color: var(--primary-color);
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
text-decoration: none;
}
.demo-link-icon {
font-size: 24px;
flex-shrink: 0;
}
.demo-link-text {
font-size: 15px;
font-weight: 700;
color: var(--primary-color);
white-space: nowrap;
}
.demo-link-desc {
font-size: 13px;
color: var(--text-secondary);
flex: 1;
}
.demo-link-arrow {
font-size: 18px;
color: var(--primary-color);
font-weight: 700;
flex-shrink: 0;
}
.file-list {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: 10px;
}
.file-item {
background: var(--card-bg);
border: 1px solid var(--border-color);
border-radius: 10px;
padding: 14px;
cursor: pointer;
transition: all 0.2s ease;
}
.file-item:hover {
border-color: var(--primary-color);
box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.file-item.active {
border-color: var(--primary-color);
background: var(--active-bg);
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}
.file-item-header {
display: flex;
align-items: center;
gap: 6px;
margin-bottom: 4px;
}
.file-item-icon {
font-size: 14px;
}
.file-item-name {
font-family: 'Fira Code', 'Consolas', monospace;
font-size: 13px;
font-weight: 600;
color: var(--primary-color);
}
.file-item-label {
font-size: 11px;
color: var(--text-tertiary);
background: var(--tag-bg);
padding: 1px 6px;
border-radius: 4px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.file-item-desc {
font-size: 12px;
color: var(--text-tertiary);
line-height: 1.4;
margin-left: 20px;
}
.code-section {
margin: 32px 0;
}
.code-section-label {
margin-bottom: 16px;
}
.empty-section {
padding: 60px 0;
text-align: center;
}
.empty-state {
color: var(--text-tertiary);
}
.empty-icon {
font-size: 40px;
display: block;
margin-bottom: 12px;
}
.empty-state p {
font-size: 15px;
}
.not-found {
text-align: center;
padding: 80px 20px;
}
.not-found h2 {
font-size: 24px;
margin-bottom: 8px;
color: var(--text-primary);
}
.back-link {
display: inline-block;
margin-top: 16px;
color: var(--primary-color);
text-decoration: none;
font-weight: 600;
}
.back-link:hover {
text-decoration: underline;
}
</style>
+278
View File
@@ -0,0 +1,278 @@
<template>
<div class="home">
<header class="hero">
<h1 class="hero-title">📚 算法分析与设计</h1>
<p class="hero-subtitle">教学辅助平台 从基础到进阶的算法学习之旅</p>
<p class="hero-desc">
涵盖六大核心章节复杂度分析分治法动态规划贪心算法回溯法分支限界法
</p>
<div class="hero-actions">
<router-link to="/chapter/ch1" class="btn-primary">开始学习 </router-link>
<a href="#chapters" class="btn-secondary">浏览章节</a>
</div>
</header>
<section id="chapters" class="chapters-grid">
<router-link
v-for="ch in chapters"
:key="ch.id"
:to="`/chapter/${ch.id}`"
class="chapter-card"
>
<div class="card-icon">{{ ch.icon }}</div>
<h3 class="card-title">{{ ch.title.split('—')[0].trim() }}</h3>
<p class="card-subtitle">{{ ch.subtitle }}</p>
<p class="card-desc">{{ ch.description }}</p>
<div class="card-topics">
<span v-for="topic in ch.topics.slice(0, 3)" :key="topic" class="topic-tag">
{{ topic }}
</span>
<span v-if="ch.topics.length > 3" class="topic-tag more">+{{ ch.topics.length - 3 }}</span>
</div>
<div class="card-footer">
<span class="explore-link">查看详情 </span>
</div>
</router-link>
</section>
<section class="features-section">
<h2 class="section-title">平台功能</h2>
<div class="features-grid">
<div class="feature-card">
<div class="feature-icon">📖</div>
<h3>代码阅览</h3>
<p>所有算法代码源文件在线展示支持语法高亮与一键复制</p>
</div>
<div class="feature-card">
<div class="feature-icon">📂</div>
<h3>分类导航</h3>
<p>按章节和子主题分类组织快速定位所需算法示例</p>
</div>
<div class="feature-card">
<div class="feature-icon">🔍</div>
<h3>知识点梳理</h3>
<p>每个章节的关键知识点和算法思想概览</p>
</div>
<div class="feature-card">
<div class="feature-icon">💻</div>
<h3>C语言实现</h3>
<p>全部使用标准C语言实现适合教学演示与实验</p>
</div>
</div>
</section>
<footer class="footer">
<p>算法分析与设计 教学辅助平台</p>
</footer>
</div>
</template>
<script setup>
import { chapters } from '../data/chapters.js'
</script>
<style scoped>
.home {
max-width: 1100px;
margin: 0 auto;
padding: 0 24px;
}
.hero {
text-align: center;
padding: 60px 20px 40px;
}
.hero-title {
font-size: 36px;
font-weight: 800;
background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
margin-bottom: 12px;
}
.hero-subtitle {
font-size: 18px;
color: var(--text-secondary);
margin-bottom: 8px;
}
.hero-desc {
font-size: 14px;
color: var(--text-tertiary);
margin-bottom: 24px;
}
.hero-actions {
display: flex;
gap: 12px;
justify-content: center;
}
.btn-primary, .btn-secondary {
padding: 12px 28px;
border-radius: 8px;
font-size: 15px;
font-weight: 600;
text-decoration: none;
transition: all 0.2s;
}
.btn-primary {
background: var(--primary-color);
color: white;
}
.btn-primary:hover {
opacity: 0.9;
transform: translateY(-1px);
}
.btn-secondary {
background: var(--hover-bg);
color: var(--text-primary);
border: 1px solid var(--border-color);
}
.btn-secondary:hover {
background: var(--active-bg);
}
.chapters-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
gap: 20px;
margin: 40px 0;
}
.chapter-card {
background: var(--card-bg);
border: 1px solid var(--border-color);
border-radius: 16px;
padding: 24px;
text-decoration: none;
color: inherit;
transition: all 0.3s ease;
display: flex;
flex-direction: column;
}
.chapter-card:hover {
transform: translateY(-4px);
box-shadow: 0 8px 30px rgba(0,0,0,0.12);
border-color: var(--primary-color);
}
.card-icon {
font-size: 40px;
margin-bottom: 12px;
}
.card-title {
font-size: 18px;
font-weight: 700;
color: var(--text-primary);
margin-bottom: 4px;
}
.card-subtitle {
font-size: 13px;
color: var(--primary-color);
margin-bottom: 10px;
font-weight: 500;
}
.card-desc {
font-size: 13px;
color: var(--text-secondary);
line-height: 1.5;
margin-bottom: 14px;
flex: 1;
}
.card-topics {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-bottom: 14px;
}
.topic-tag {
font-size: 11px;
background: var(--tag-bg);
color: var(--text-secondary);
padding: 3px 10px;
border-radius: 12px;
}
.topic-tag.more {
background: var(--active-bg);
color: var(--primary-color);
}
.card-footer {
border-top: 1px solid var(--border-color);
padding-top: 12px;
}
.explore-link {
font-size: 13px;
color: var(--primary-color);
font-weight: 600;
}
.section-title {
text-align: center;
font-size: 24px;
font-weight: 700;
margin-bottom: 24px;
color: var(--text-primary);
}
.features-section {
margin: 60px 0;
}
.features-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
gap: 16px;
}
.feature-card {
background: var(--card-bg);
border: 1px solid var(--border-color);
border-radius: 12px;
padding: 24px;
text-align: center;
}
.feature-icon {
font-size: 32px;
margin-bottom: 12px;
}
.feature-card h3 {
font-size: 16px;
font-weight: 600;
margin-bottom: 8px;
color: var(--text-primary);
}
.feature-card p {
font-size: 13px;
color: var(--text-secondary);
line-height: 1.5;
}
.footer {
text-align: center;
padding: 40px 0;
color: var(--text-tertiary);
font-size: 13px;
border-top: 1px solid var(--border-color);
margin-top: 40px;
}
</style>
+258
View File
@@ -0,0 +1,258 @@
<template>
<div class="sort-demo">
<header class="demo-header">
<div class="demo-icon">🎯</div>
<div>
<h1 class="demo-title">排序算法动态演示</h1>
<p class="demo-subtitle">通过动画直观理解分治排序算法的每一步操作</p>
</div>
</header>
<section class="demo-section">
<h2 class="section-title">📖 算法说明</h2>
<div class="algo-info">
<div class="algo-card">
<h3>归并排序 (Merge Sort)</h3>
<div class="complexity">
<span><strong>时间复杂度:</strong> O(n log n)</span>
<span><strong>空间复杂度:</strong> O(n)</span>
<span><strong>稳定性:</strong> 稳定</span>
</div>
<p>归并排序采用<strong>分治策略</strong>将数组不断拆分为两半分别排序后再合并合并时通过比较两个有序子数组的头部元素依次选取较小的放入结果数组</p>
<ul class="algo-steps">
<li><strong>分解</strong>将数组从中间分为左右两个子数组</li>
<li><strong>解决</strong>递归地对左右子数组进行归并排序</li>
<li><strong>合并</strong>将两个有序子数组合并为一个有序数组</li>
</ul>
</div>
<div class="algo-card">
<h3>快速排序 (Quick Sort)</h3>
<div class="complexity">
<span><strong>时间复杂度:</strong> O(n log n) 平均 / O() 最坏</span>
<span><strong>空间复杂度:</strong> O(log n)</span>
<span><strong>稳定性:</strong> 不稳定</span>
</div>
<p>快速排序采用<strong>分治策略</strong>选择一个基准元素将数组分为小于基准和大于基准的两部分然后递归排序核心是 <strong>partition划分</strong> 操作</p>
<ul class="algo-steps">
<li><strong>选择基准</strong>选取数组最后一个元素作为 pivot</li>
<li><strong>划分</strong>将小于 pivot 的元素放到左边大于的放到右边</li>
<li><strong>递归</strong>对左右两个子区间递归进行快速排序</li>
</ul>
</div>
</div>
</section>
<section class="demo-section">
<h2 class="section-title">🎬 归并排序演示</h2>
<SortVisualizer
title="归并排序 (Merge Sort)"
algorithm="merge"
:arraySize="12"
/>
</section>
<section class="demo-section">
<h2 class="section-title">🎬 快速排序演示</h2>
<SortVisualizer
title="快速排序 (Quick Sort)"
algorithm="quick"
:arraySize="12"
/>
</section>
<section class="demo-section">
<h2 class="section-title">💡 对比总结</h2>
<div class="comparison-table-wrapper">
<table class="comparison-table">
<thead>
<tr>
<th>特性</th>
<th>归并排序</th>
<th>快速排序</th>
</tr>
</thead>
<tbody>
<tr>
<td>策略</td>
<td>先递归后合并后序遍历</td>
<td>先划分后递归前序遍历</td>
</tr>
<tr>
<td>额外空间</td>
<td>O(n) 需要辅助数组</td>
<td>O(log n) 递归栈空间</td>
</tr>
<tr>
<td>最坏情况</td>
<td>O(n log n) 始终稳定</td>
<td>O() 已有序数组且选择最值作为 pivot</td>
</tr>
<tr>
<td>稳定性</td>
<td> 稳定</td>
<td> 不稳定</td>
</tr>
<tr>
<td>适用场景</td>
<td>外部排序对稳定性有要求的场景</td>
<td>内部排序对平均性能要求高的场景</td>
</tr>
</tbody>
</table>
</div>
</section>
<div class="nav-back">
<router-link to="/chapter/ch2" class="back-link"> 返回第二章</router-link>
</div>
</div>
</template>
<script setup>
import SortVisualizer from '../components/SortVisualizer.vue'
</script>
<style scoped>
.sort-demo {
max-width: 1000px;
margin: 0 auto;
padding: 0 24px;
}
.demo-header {
display: flex;
gap: 16px;
align-items: flex-start;
padding: 28px 0 20px;
border-bottom: 1px solid var(--border-color);
margin-bottom: 28px;
}
.demo-icon {
font-size: 40px;
flex-shrink: 0;
}
.demo-title {
font-size: 26px;
font-weight: 800;
color: var(--text-primary);
margin-bottom: 4px;
}
.demo-subtitle {
font-size: 14px;
color: var(--text-secondary);
}
.demo-section {
margin-bottom: 32px;
}
.section-title {
font-size: 20px;
font-weight: 700;
color: var(--text-primary);
margin-bottom: 16px;
padding-bottom: 8px;
border-bottom: 2px solid var(--border-color);
}
.algo-info {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16px;
}
.algo-card {
background: var(--card-bg);
border: 1px solid var(--border-color);
border-radius: 12px;
padding: 20px;
}
.algo-card h3 {
font-size: 16px;
font-weight: 700;
color: var(--text-primary);
margin-bottom: 8px;
}
.complexity {
display: flex;
flex-wrap: wrap;
gap: 12px;
font-size: 12px;
color: var(--text-secondary);
margin-bottom: 12px;
padding: 8px 12px;
background: var(--hover-bg);
border-radius: 8px;
}
.algo-card p {
font-size: 13px;
color: var(--text-secondary);
line-height: 1.6;
margin-bottom: 10px;
}
.algo-steps {
font-size: 13px;
color: var(--text-secondary);
padding-left: 20px;
line-height: 1.8;
}
.comparison-table-wrapper {
overflow-x: auto;
}
.comparison-table {
width: 100%;
border-collapse: collapse;
font-size: 14px;
}
.comparison-table th,
.comparison-table td {
padding: 10px 16px;
border: 1px solid var(--border-color);
text-align: left;
}
.comparison-table th {
background: var(--hover-bg);
font-weight: 700;
color: var(--text-primary);
}
.comparison-table td {
color: var(--text-secondary);
}
.comparison-table tr:hover td {
background: var(--hover-bg);
}
.nav-back {
padding: 20px 0 40px;
}
.back-link {
color: var(--primary-color);
font-weight: 600;
text-decoration: none;
font-size: 14px;
}
.back-link:hover {
text-decoration: underline;
}
@media (max-width: 768px) {
.algo-info {
grid-template-columns: 1fr;
}
}
</style>