Skip to content

Commit c53d6c9

Browse files
author
Bappy
committed
AV-07: linked-list search refined
1 parent 148eaf1 commit c53d6c9

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
const arrowLength = 20;
184184
const arrowY = 100;
185185
// Line 1: Horizontal line
186-
this.circleContainer.append('line')
186+
const line1 = this.circleContainer.append('line')
187187
.attr('x1', arrowX - arrowLength - 20)
188188
.attr('y1', arrowY)
189189
.attr('x2', arrowX)
@@ -192,7 +192,7 @@
192192
.attr('stroke-width', 2);
193193
194194
// Line 2: Diagonal line (left)
195-
this.circleContainer.append('line')
195+
const line2 = this.circleContainer.append('line')
196196
.attr('x1', arrowX - 10)
197197
.attr('y1', arrowY - 5)
198198
.attr('x2', arrowX - arrowLength + 20)
@@ -201,20 +201,22 @@
201201
.attr('stroke-width', 2);
202202
203203
// Line 3: Diagonal line (right)
204-
this.circleContainer.append('line')
204+
const line3 = this.circleContainer.append('line')
205205
.attr('x1', arrowX - 10)
206206
.attr('y1', arrowY + 5)
207207
.attr('x2', arrowX - arrowLength + 20)
208208
.attr('y2', arrowY)
209209
.attr('stroke', 'black')
210210
.attr('stroke-width', 2);
211+
212+
return [line1, line2, line3];
211213
},
212214
213215
appendIntoLinkedList(num, pos) {
214216
if (!pos) {
215-
const ele = this.createCircle(num);
216-
this.createArrow((this.xAxis - this.circleRadius * 20) + 70);
217-
this.linkedList.append(num, ele);
217+
const circle = this.createCircle(num);
218+
const line = this.createArrow((this.xAxis - this.circleRadius * 20) + 70);
219+
this.linkedList.append(num, {circle: circle, lines: line});
218220
}
219221
},
220222
@@ -228,11 +230,15 @@
228230
let pos = 1;
229231
while (current) {
230232
found = current.data == this.targetValue;
231-
current.element.transition()
233+
current.element.circle.transition()
232234
.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+
}
233239
await new Promise(resolve => setTimeout(resolve, 1000));
234240
if (found) {
235-
current.element.transition()
241+
current.element.circle.transition()
236242
.duration(1000).attr('fill', "green");
237243
break;
238244
}

0 commit comments

Comments
 (0)