diff --git a/src/data/chapters.js b/src/data/chapters.js index cb9b914..12b5348 100644 --- a/src/data/chapters.js +++ b/src/data/chapters.js @@ -16,10 +16,22 @@ export const chapters = [ '递归算法复杂度', '实验对比分析方法' ], - files: [ - { path: 'c/ch1/first.c', name: 'first.c', label: '递归打印图案', description: '递归打印矩形/三角形图案,演示递归基本结构', pyPath: 'py/ch1/first.py' }, - { path: 'c/ch1/compare.c', name: 'compare.c', label: '性能对比(累加 vs 高斯公式)', description: '比较循环累加与高斯求和公式的耗时差异,直观感受算法效率', pyPath: 'py/ch1/compare.py' }, - { path: 'c/ch1/compareall.c', name: 'compareall.c', label: '多项性能对比', description: '更多累加与高斯公式的计时对比实验' } + subfolders: [ + { + name: 'complexity-demo', + label: '🧪 时间复杂度实验', + demo: { path: '/complexity-demo', label: '📊 动态演示', description: '通过动画直观理解 O(1)、O(log n)、O(n)、O(n log n)、O(n²)、O(2ⁿ) 的增长差异' }, + files: [] + }, + { + name: 'code-examples', + label: '代码示例', + files: [ + { path: 'c/ch1/first.c', name: 'first.c', label: '递归打印图案', description: '递归打印矩形/三角形图案,演示递归基本结构', pyPath: 'py/ch1/first.py' }, + { path: 'c/ch1/compare.c', name: 'compare.c', label: '性能对比(累加 vs 高斯公式)', description: '比较循环累加与高斯求和公式的耗时差异,直观感受算法效率', pyPath: 'py/ch1/compare.py' }, + { path: 'c/ch1/compareall.c', name: 'compareall.c', label: '多项性能对比', description: '更多累加与高斯公式的计时对比实验' } + ] + } ] }, { diff --git a/src/router/index.js b/src/router/index.js index d8934c1..46bc35f 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -2,6 +2,7 @@ import { createRouter, createWebHistory } from 'vue-router' import Home from '../views/Home.vue' import ChapterView from '../views/ChapterView.vue' import SortDemo from '../views/SortDemo.vue' +import ComplexityDemo from '../views/ComplexityDemo.vue' const routes = [ { @@ -19,6 +20,11 @@ const routes = [ path: '/sort-demo', name: 'SortDemo', component: SortDemo + }, + { + path: '/complexity-demo', + name: 'ComplexityDemo', + component: ComplexityDemo } ] diff --git a/src/views/ChapterView.vue b/src/views/ChapterView.vue index 320a1a0..861e92a 100644 --- a/src/views/ChapterView.vue +++ b/src/views/ChapterView.vue @@ -170,6 +170,8 @@ function closeDrawer() { function getFolderDescription(folderName) { const descriptions = { + 'complexity-demo': '通过交互式动画,直观体验不同时间复杂度算法的执行过程与操作次数差异。', + 'code-examples': '本章相关的 C 语言和 Python 代码示例。', mergesort: '归并排序是分治法的经典应用:将数组一分为二,分别排序后合并。时间复杂度 O(n log n)。', quicksort: '快速排序通过选择一个基准元素,将数组分为左右两部分,递归排序。平均时间复杂度 O(n log n)。', halfsearch: '二分查找在有序数组中通过每次将搜索范围缩小一半来查找目标值,时间复杂度 O(log n)。', diff --git a/src/views/ComplexityDemo.vue b/src/views/ComplexityDemo.vue new file mode 100644 index 0000000..39889c9 --- /dev/null +++ b/src/views/ComplexityDemo.vue @@ -0,0 +1,853 @@ + + + + + diff --git a/vite.config.js b/vite.config.js index 2b01f81..d0be6ca 100644 --- a/vite.config.js +++ b/vite.config.js @@ -8,7 +8,7 @@ export default defineConfig({ port: 1025, proxy: { '/api': { - target: 'http://localhost:3001', + target: 'http://localhost:3002', changeOrigin: true, }, },