Skip to content

Commit fba09a2

Browse files
committed
AV-07: updated linked list arrow design and animation
1 parent 15c0bac commit fba09a2

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/algorithms/linked-list/Linked-List.vue

+19-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<h1>Linked List</h1>
44
<div ref="circleContainer"></div>
55
<div v-if="showSuccessResult" class="success-message">
6-
Search result found at: "{{ result }}"
6+
Searched item {{ targetValue }} found at: "{{ result }}"
77
</div>
88

99
<div v-if="showFailureResult" class="fail-message">
@@ -28,7 +28,7 @@
2828
constructor(data) {
2929
this.data = data;
3030
this.next = null;
31-
this.element = null;
31+
this.element = {};
3232
}
3333
}
3434
@@ -39,8 +39,9 @@
3939
4040
append(data, element) {
4141
const newNode = new Node(data);
42-
newNode.element = element;
42+
newNode.element.circle = element.circle;
4343
if (!this.head) {
44+
newNode.element.lines = element.lines;
4445
this.head = newNode;
4546
return;
4647
}
@@ -49,6 +50,7 @@
4950
while (current.next) {
5051
current = current.next;
5152
}
53+
current.element.lines = element.lines;
5254
current.next = newNode;
5355
}
5456
@@ -215,7 +217,11 @@
215217
appendIntoLinkedList(num, pos) {
216218
if (!pos) {
217219
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+
219225
this.linkedList.append(num, {circle: circle, lines: line});
220226
}
221227
},
@@ -231,17 +237,20 @@
231237
while (current) {
232238
found = current.data == this.targetValue;
233239
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));
240242
if (found) {
241243
current.element.circle.transition()
242244
.duration(1000).attr('fill', "green");
243245
break;
244246
}
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+
}
245254
current = current.next;
246255
pos++;
247256
}

0 commit comments

Comments
 (0)