Skip to content

Commit 2cc2577

Browse files
committed
Final Version
1 parent 0e77e6b commit 2cc2577

5 files changed

Lines changed: 58 additions & 7 deletions

File tree

src/Components/Algorithms/AlgoAnimations/AlgoAnimations.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ export function getBucketSortAnimations(array) {
246246
let i = 0;
247247
array.forEach(element => {
248248
Buckets[Math.floor((element - minVal) / bucketSize)].push(element);
249-
animations.push([i,Math.floor((element - minVal) / bucketSize),bucketCount]);animations.push([i,Math.floor((element - minVal) / bucketSize),bucketCount]);
249+
animations.push([i, Math.floor((element - minVal) / bucketSize), bucketCount]);
250+
animations.push([i, Math.floor((element - minVal) / bucketSize), bucketCount]);
250251
i++;
251252
});
252253
i = 0;

src/Components/Algorithms/AlgoProcedure/HeapSortProc.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
const HeapSortProc = (props) => {
22
return (
33
<div>
4-
<div>Too complex to show</div>
4+
<div>
5+
<p>void heapSort(int arr[], int N)</p>
6+
<p>for (int i = N / 2 - 1; i{">"}= 0; i--) heapify(arr, N, i);</p>
7+
<p>for (int i = N - 1; i{">"} 0; i--)</p>
8+
<p>swap(arr[0], arr[i]);</p>
9+
<p>heapify(arr, i, 0);</p>
10+
</div>
511
</div>
612
);
713
};

src/Components/Algorithms/AlgoProcedure/MergeSortProc.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
const MergeSortProc = (props) => {
22
return (
33
<div>
4-
<div>Too complex to show</div>
4+
<div>
5+
<p>mergeSort(int array[], int const begin, int const end)</p>
6+
<p>if (begin {">"}= end) return;</p>
7+
<p>mid = begin + (end - begin) / 2; mergeSort(array, begin, mid);</p>
8+
<p>mergeSort(array, mid + 1, end); merge(array, begin, mid, end); </p>
9+
</div>
510
</div>
611
);
712
};

src/Components/Algorithms/AlgoProcedure/QuickSortProc.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ const QuickSortProc = (props) => {
1515
<p>for i = beg to end-1</p>
1616
<p>arr[i] less than pivot</p>
1717
<p>swap arr[i] and arr[pIndex];pIndex++</p>
18-
<p>swap pivot and arr[pIndex+1]</p>
19-
<p>return pIndex + 1</p>
18+
<p>swap pivot and arr[pIndex+1];return pIndex + 1</p>
2019
</div>
2120
<div>
2221
{props.stepData == "" && <div>click play button to start</div>}

src/Components/Layout/VisualizerContainer.jsx

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default class VisualizerContainer extends React.Component {
5555
if (this.props.arr !== prevProps.arr) {
5656
this.setState({ array: this.props.arr });
5757
this.setState({ type: this.props.type });
58-
this.resetArray();
58+
//this.resetArray();
5959
this.clearTimeouts();
6060
this.setState((state, props) => ({ lastPos: -1 }));
6161
}
@@ -83,6 +83,10 @@ export default class VisualizerContainer extends React.Component {
8383
this.setState({ play: this.state.play });
8484
console.log("executed animations ");
8585
}
86+
if (this.state.execTime != prevState.execTime) {
87+
this.setState({ execTime: this.state.execTime });
88+
console.log("executed execTime ");
89+
}
8690
}
8791

8892
resetArray() {
@@ -112,6 +116,7 @@ export default class VisualizerContainer extends React.Component {
112116
this.setState({ play: !this.state.play });
113117
this.state.timeoutIds.forEach((timeoutId) => clearTimeout(timeoutId));
114118
this.setState({ timeoutIds: [] });
119+
// this.setState({ lastPos: -1 });
115120
};
116121
pause = (opt) => {
117122
this.setState({ play: !this.state.play });
@@ -165,8 +170,12 @@ export default class VisualizerContainer extends React.Component {
165170

166171
mergeSort(a) {
167172
let animations = [];
173+
//const start = performance.now();
168174
if (this.state.animations.length == 0) {
175+
const start = performance.now();
169176
animations = getMergeSortAnimations(this.state.array);
177+
const end = performance.now();
178+
this.setState({ execTime: (end - start).toFixed(4) });
170179
}
171180
if (animations.length != 0) this.setState({ animations });
172181
const timeoutIds = [];
@@ -220,6 +229,7 @@ export default class VisualizerContainer extends React.Component {
220229
timeDelay * ANIMATION_SPEED_MS
221230
);
222231
timeoutIds.push(timeoutId);
232+
223233
//this.updateArray();
224234
this.setState({ timeoutIds });
225235
this.updateArray();
@@ -228,7 +238,10 @@ export default class VisualizerContainer extends React.Component {
228238
quickSort(a) {
229239
let animations = [];
230240
if (this.state.animations.length == 0) {
241+
const start = performance.now();
231242
animations = getQuickSortAnimations(this.state.array);
243+
const end = performance.now();
244+
this.setState({ execTime: (end - start).toFixed(4) });
232245
}
233246
if (animations.length != 0) this.setState({ animations });
234247
const timeoutIds = [];
@@ -307,7 +320,10 @@ export default class VisualizerContainer extends React.Component {
307320
ModifiedquickSort(a) {
308321
let animations = [];
309322
if (this.state.animations.length == 0) {
323+
const start = performance.now();
310324
animations = getOptimizedQuickSortAnimations(this.state.array);
325+
const end = performance.now();
326+
this.setState({ execTime: (end - start).toFixed(4) });
311327
}
312328
if (animations.length != 0) this.setState({ animations });
313329
const timeoutIds = [];
@@ -439,7 +455,10 @@ export default class VisualizerContainer extends React.Component {
439455
insertionSort(a) {
440456
let animations = [];
441457
if (this.state.animations.length == 0) {
458+
const start = performance.now();
442459
animations = getInsertionSortAnimations(this.state.array);
460+
const end = performance.now();
461+
this.setState({ execTime: (end - start).toFixed(4) });
443462
}
444463
const arrlength = this.state.array.length;
445464
if (animations.length != 0) this.setState({ animations });
@@ -508,7 +527,10 @@ export default class VisualizerContainer extends React.Component {
508527
countSort(a) {
509528
let animations = [];
510529
if (this.state.animations.length == 0) {
530+
const start = performance.now();
511531
animations = getCountingSortAnimations(this.state.array);
532+
const end = performance.now();
533+
this.setState({ execTime: (end - start).toFixed(4) });
512534
}
513535
const arrlength = this.state.array.length;
514536
if (animations.length != 0) this.setState({ animations });
@@ -577,11 +599,15 @@ export default class VisualizerContainer extends React.Component {
577599
let firstNum = 40;
578600
let secondNum = 100;
579601
if (this.state.animations.length == 0) {
602+
const start = performance.now();
603+
580604
animations = getCountElementsAnimations(
581605
this.state.array,
582606
firstNum,
583607
secondNum
584608
);
609+
const end = performance.now();
610+
this.setState({ execTime: (end - start).toFixed(4) });
585611
}
586612
const arrlength = this.state.array.length;
587613
if (animations.length != 0) this.setState({ animations });
@@ -662,7 +688,10 @@ export default class VisualizerContainer extends React.Component {
662688
radixSort(a) {
663689
let animations = [];
664690
if (this.state.animations.length == 0) {
691+
const start = performance.now();
665692
animations = getRadixSortAnimations(this.state.array);
693+
const end = performance.now();
694+
this.setState({ execTime: (end - start).toFixed(4) });
666695
}
667696
const arrlength = this.state.array.length;
668697
console.log("I am good");
@@ -748,7 +777,11 @@ export default class VisualizerContainer extends React.Component {
748777
heapSort(a) {
749778
let animations = [];
750779
if (this.state.animations.length == 0) {
780+
const start = performance.now();
781+
751782
animations = getHeapSortAnimations(this.state.array);
783+
const end = performance.now();
784+
this.setState({ execTime: (end - start).toFixed(4) });
752785
}
753786
if (animations.length != 0) this.setState({ animations });
754787
const timeoutIds = [];
@@ -811,7 +844,11 @@ export default class VisualizerContainer extends React.Component {
811844
bubbleSort(a) {
812845
let animations = [];
813846
if (this.state.animations.length == 0) {
847+
const start = performance.now();
848+
814849
animations = getBubbleSortAnimations(this.state.array);
850+
const end = performance.now();
851+
this.setState({ execTime: (end - start).toFixed(4) });
815852
}
816853
if (animations.length != 0) this.setState({ animations });
817854
const timeoutIds = [];
@@ -892,7 +929,10 @@ export default class VisualizerContainer extends React.Component {
892929
bucketSort(a) {
893930
let animations = [];
894931
if (this.state.animations.length == 0) {
932+
const start = performance.now();
895933
animations = getBucketSortAnimations(this.state.array);
934+
const end = performance.now();
935+
this.setState({ execTime: (end - start).toFixed(4) });
896936
}
897937
const arrlength = this.state.array.length;
898938
if (animations.length != 0) this.setState({ animations });
@@ -1024,7 +1064,7 @@ export default class VisualizerContainer extends React.Component {
10241064
onInput={onInputhandler}
10251065
></input>
10261066
<span style={{ fontWeight: 700 }}>
1027-
Execution time: {this.state.execTime}{" "}
1067+
Execution time: {this.state.execTime} ms
10281068
</span>
10291069
</div>
10301070
</div>

0 commit comments

Comments
 (0)