From 0255ceba02bba3cb7f7b47652df743fa2d3d8722 Mon Sep 17 00:00:00 2001 From: changjunqiang <344656718@qq.com> Date: Tue, 16 Jun 2026 10:23:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E6=97=B6=E9=97=B4=E5=A4=8D=E6=9D=82?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/data/chapters.js | 20 +- src/router/index.js | 6 + src/views/ChapterView.vue | 2 + src/views/ComplexityDemo.vue | 853 +++++++++++++++++++++++++++++++++++ vite.config.js | 2 +- 5 files changed, 878 insertions(+), 5 deletions(-) create mode 100644 src/views/ComplexityDemo.vue 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 @@ + + + + 📊 + + 时间复杂度动态演示 + 通过动画和计数直观理解不同算法的时间复杂度 + + + + + + + 输入规模 n: + + {{ n }} + + + 选择算法: + + + {{ a.label }} — {{ a.complexity }} + + + + + ▶ 运行演示 + 下一步 + ⟳ 重置 + + + + + + + {{ currentAlgo.label }} + + 时间复杂度:{{ currentAlgo.complexity }} + 空间复杂度:{{ currentAlgo.space }} + + {{ currentAlgo.description }} + + 操作次数:{{ opCount }} + ≈ {{ currentAlgo.formula.replace('n', n) }} + + + + + + + + + + 数据状态: + + + + {{ val }} + + + + + + + + 📝 执行步骤 + + + {{ idx + 1 }} + {{ step }} + + + + + + + 📈 复杂度增长对比 + + + {{ item.label }} + + + {{ item.count }} + + + + + + + + + + ← 返回第一章 + + + + + + + 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, }, },
通过动画和计数直观理解不同算法的时间复杂度
{{ currentAlgo.description }}