|
3 | 3 | <h1>Linked List</h1>
|
4 | 4 | <div ref="circleContainer"></div>
|
5 | 5 | <div v-if="showSuccessResult" class="success-message">
|
6 |
| - Search result found at: "{{ result }}" |
| 6 | + Searched item {{ targetValue }} found at: "{{ result }}" |
7 | 7 | </div>
|
8 | 8 |
|
9 | 9 | <div v-if="showFailureResult" class="fail-message">
|
|
28 | 28 | constructor(data) {
|
29 | 29 | this.data = data;
|
30 | 30 | this.next = null;
|
31 |
| - this.element = null; |
| 31 | + this.element = {}; |
32 | 32 | }
|
33 | 33 | }
|
34 | 34 |
|
|
39 | 39 |
|
40 | 40 | append(data, element) {
|
41 | 41 | const newNode = new Node(data);
|
42 |
| - newNode.element = element; |
| 42 | + newNode.element.circle = element.circle; |
43 | 43 | if (!this.head) {
|
| 44 | + newNode.element.lines = element.lines; |
44 | 45 | this.head = newNode;
|
45 | 46 | return;
|
46 | 47 | }
|
|
49 | 50 | while (current.next) {
|
50 | 51 | current = current.next;
|
51 | 52 | }
|
| 53 | + current.element.lines = element.lines; |
52 | 54 | current.next = newNode;
|
53 | 55 | }
|
54 | 56 |
|
|
215 | 217 | appendIntoLinkedList(num, pos) {
|
216 | 218 | if (!pos) {
|
217 | 219 | const circle = this.createCircle(num);
|
218 |
| - const line = this.createArrow((this.xAxis - this.circleRadius * 20) + 70); |
| 220 | + let line; |
| 221 | + if(this.linkedList.head){ |
| 222 | + line = this.createArrow((this.xAxis - this.circleRadius * 40) + 70); |
| 223 | + } |
| 224 | +
|
219 | 225 | this.linkedList.append(num, {circle: circle, lines: line});
|
220 | 226 | }
|
221 | 227 | },
|
|
231 | 237 | while (current) {
|
232 | 238 | found = current.data == this.targetValue;
|
233 | 239 | current.element.circle.transition()
|
234 |
| - .duration(1000).attr('fill', "pink"); |
235 |
| - await new Promise(resolve => setTimeout(resolve, 1200)); |
236 |
| - for(const line of current.element.lines){ |
237 |
| - line.transition().duration(300).attr('stroke', "pink"); |
238 |
| - } |
239 |
| - await new Promise(resolve => setTimeout(resolve, 1000)); |
| 240 | + .duration(500).attr('fill', "pink"); |
| 241 | + await new Promise(resolve => setTimeout(resolve, 600)); |
240 | 242 | if (found) {
|
241 | 243 | current.element.circle.transition()
|
242 | 244 | .duration(1000).attr('fill', "green");
|
243 | 245 | break;
|
244 | 246 | }
|
| 247 | + await new Promise(resolve => setTimeout(resolve, 600)); |
| 248 | + if(current.next){ |
| 249 | + for (const line of current.element.lines) { |
| 250 | + line.transition().duration(300).attr('stroke', "pink"); |
| 251 | + } |
| 252 | + await new Promise(resolve => setTimeout(resolve, 300)); |
| 253 | + } |
245 | 254 | current = current.next;
|
246 | 255 | pos++;
|
247 | 256 | }
|
|
0 commit comments