-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
242 lines (233 loc) · 7.86 KB
/
index.html
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>算法</title>
<!-- 引入样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<style>
#app {
min-width: 1200px;
}
.ta-c {
text-align: center;
}
[v-cloak] {
display: none;
}
.el-col-11 {
background-color: rgba(0, 0, 0, 0.8);
color: white;
padding: 0 20px;
border-radius: 5px;
}
</style>
</head>
<body>
<div id="app">
<el-collapse v-model="activeName" accordion v-cloak>
<el-collapse-item title="排序算法" name="1">
<template slot="title">
<h3>排序算法</h3>
</template>
<el-row :gutter="10">
<el-col :span="20" :offset="2">
<el-tabs type="border-card">
<el-tab-pane label="冒泡排序">
<el-row>
<el-col :span="5">
{{ sortGroup.bubbleData }}
</el-col>
<el-col :span="11">
<pre>
<code class="language-plaintext">
for (let i = 0; i < arr.length - 1; i++) {
for (let j = i + 1; j < arr.length - 1; j++) {
if (arr[i] > arr[j]) {
[arr[i], arr[j]] = [arr[j], arr[i]]
}
}
}
</code>
</pre>
</el-col>
<el-col :span="3" class="ta-c">
<el-button size="small" type="primary" @click="bubbleSort(sortGroup.bubbleData)">排序
</el-button>
</el-col>
<el-col :span="5">
{{ sortGroup.bubbleDataNew }}
</el-col>
</el-row>
</el-tab-pane>
<el-tab-pane label="快速排序">
<el-row>
<el-col :span="5">
{{ sortGroup.bubbleData }}
</el-col>
<el-col :span="11">
<pre>
<code class="language-plaintext">
const loopFn = (arr) => {
if (arr.length <= 1) return arr
const centerIndex = Math.floor(arr.length / 2)
const centerValue = arr.splice(centerIndex, 1)[0]
const [left, right] = [[], []]
arr.map((e, i) => {
if (e < centerValue) {
left.push(e)
} else {
right.push(e)
}
})
return loopFn(left).concat([centerValue], loopFn(right))
}
</code>
</pre>
</el-col>
<el-col :span="3" class="ta-c">
<el-button size="small" type="primary" @click="quickSort(sortGroup.quickData)">排序
</el-button>
</el-col>
<el-col :span="5">
{{ sortGroup.quickDataNew }}
</el-col>
</el-row>
</el-tab-pane>
<el-tab-pane label="插入排序">
<el-row>
<el-col :span="5">
{{ sortGroup.insertData }}
</el-col>
<el-col :span="11">
<pre>
<code class="language-plaintext">
const sortArr = [_arr[0]]
const getIndex = (arr, e) => {
if (e < arr[0]) return 0
if (e >= arr[arr.length - 1]) return arr.length
let i = 0
for (; i < arr.length; i++) {
if (e >= arr[i] && e <= arr[i + 1]) {
break
}
}
return i + 1
}
for (let i = 1; i < _arr.length; i++) {
const searchIndex = getIndex(sortArr, _arr[i])
sortArr.splice(searchIndex, 0, _arr[i])
}
this.sortGroup.insertDataNew = sortArr
</code>
</pre>
</el-col>
<el-col :span="3" class="ta-c">
<el-button size="small" type="primary" @click="insertSort(sortGroup.insertData)">排序
</el-button>
</el-col>
<el-col :span="5">
{{ sortGroup.insertDataNew }}
</el-col>
</el-row>
</el-tab-pane>
</el-tabs>
</el-col>
</el-row>
</el-collapse-item>
<el-collapse-item title="反馈 Feedback" name="2">
<div>控制反馈:通过界面样式和交互动效让用户可以清晰的感知自己的操作;</div>
<div>页面反馈:操作后,通过页面元素的变化清晰地展现当前状态。</div>
</el-collapse-item>
<el-collapse-item title="效率 Efficiency" name="3">
<div>简化流程:设计简洁直观的操作流程;</div>
<div>清晰明确:语言表达清晰且表意明确,让用户快速理解进而作出决策;</div>
<div>帮助用户识别:界面简单直白,让用户快速识别而非回忆,减少用户记忆负担。</div>
</el-collapse-item>
<el-collapse-item title="可控 Controllability" name="4">
<div>用户决策:根据场景可给予用户操作建议或安全提示,但不能代替用户进行决策;</div>
<div>结果可控:用户可以自由的进行操作,包括撤销、回退和终止当前操作等。</div>
</el-collapse-item>
</el-collapse>
</div>
<!-- import Vue before Element -->
<script src="https://unpkg.com/vue@2.6.0/dist/vue.js"></script>
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/styles/default.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/highlight.min.js"></script>
<script>
new Vue({
el: '#app',
data: function () {
return {
visible: false,
activeName: '1',
sortGroup: {
bubbleData: [6, 1, 4, 5, 8, 2, 7, 3, 9],
bubbleDataNew: [],
quickData: [6, 1, 4, 5, 8, 2, 7, 3, 9],
quickDataNew: [],
insertData: [6, 1, 4, 5, 8, 2, 7, 3, 9],
insertDataNew: [],
}
}
},
mounted () {
},
methods: {
bubbleSort (_arr) {
const arr = JSON.parse(JSON.stringify(_arr))
for (let i = 0; i < arr.length - 1; i++) {
for (let j = i + 1; j < arr.length - 1; j++) {
if (arr[i] > arr[j]) {
[arr[i], arr[j]] = [arr[j], arr[i]]
}
}
}
this.sortGroup.bubbleDataNew = arr
},
quickSort (_arr) {
const arr = JSON.parse(JSON.stringify(_arr))
const loopFn = (arr) => {
if (arr.length <= 1) return arr
const centerIndex = Math.floor(arr.length / 2)
const centerValue = arr.splice(centerIndex, 1)[0]
const [left, right] = [[], []]
arr.map((e, i) => {
if (e < centerValue) {
left.push(e)
} else {
right.push(e)
}
})
return loopFn(left).concat([centerValue], loopFn(right))
}
this.sortGroup.quickDataNew = loopFn(arr)
},
insertSort (_arr) {
const sortArr = [_arr[0]]
const getIndex = (arr, e) => {
if (e < arr[0]) return 0
if (e >= arr[arr.length - 1]) return arr.length
let i = 0
for (; i < arr.length; i++) {
if (e >= arr[i] && e <= arr[i + 1]) {
break
}
}
return i + 1
}
for (let i = 1; i < _arr.length; i++) {
const searchIndex = getIndex(sortArr, _arr[i])
sortArr.splice(searchIndex, 0, _arr[i])
}
this.sortGroup.insertDataNew = sortArr
}
}
})
</script>
</body>
</html>