Skip to content

Commit dd7791a

Browse files
committed
Merge sort bug fixed
1 parent 757b57a commit dd7791a

4 files changed

Lines changed: 17 additions & 10 deletions

File tree

‎src/components/Animation/Animation.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {Document} from 'postcss';
55
class Animation {
66

77
constructor() {
8-
Animation.threads = [];
8+
Animation.timeouts = [];
99
// SG 07/09/2022 15:11 Singleton pattern
1010
if (Animation._instance) {
1111
return Animation._instance;
@@ -51,12 +51,19 @@ class Animation {
5151
static async getAnimation(delay) {
5252
if (!Animation.stop) {
5353
await new Promise((resolve) =>
54-
Animation.threads.push(setTimeout(() => {
54+
Animation.timeouts.push(setTimeout(() => {
5555
resolve();
5656
}, delay)));
5757
}
58+
59+
}
60+
61+
static getTimeouts() {
62+
return Animation.timeouts;
5863
}
5964

65+
66+
6067
static async makeBeep(vol, freq, duration){
6168

6269
}

‎src/components/Canvas/Description/SortingCanvasDescription.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ function SortingCanvasDescription() {
1616
<div className="self-center font-sans max-w-[90vw] text-gray-700 dark:text-white mt-10 md:mt-0 md:pt-0 pb-[5em]">
1717
<p className="text-[1.5em] md:text-[2.8em] font-bold mb-5">Welcome to Sorting Visualizer</p>
1818
<div>
19-
<p className="font-medium text-[1.1em] text-gray-700 dark:text-textGray">Let's start by entering a number. It will generate an array with <BoldParagraph text="random numbers"/> based on the input.</p>
20-
<p className="font-medium text-[1.1em] text-gray-700 dark:text-textGray">Next, select an <BoldParagraph text="algorithm"/> and press the <BoldParagraph text="play"/> button.</p>
19+
<span className="font-medium text-[1.1em] text-gray-700 dark:text-textGray">Let's start by entering a number. It will generate an array with <BoldParagraph text="random numbers"/> based on the input.</span><br/>
20+
<span className="font-medium text-[1.1em] text-gray-700 dark:text-textGray">Next, select an <BoldParagraph text="algorithm"/> and press the <BoldParagraph text="play"/> button.</span>
2121
</div>
2222

2323
<div className="mt-4">
24-
<p className="font-medium text-[1.1em] text-gray-700 dark:text-textGray">The maximum input is currently limited to <BoldParagraph text={InputHandler.getAllowedMaxInputSize()}/>. To play with a larger number, increase the window size and refresh the page.</p>
24+
<span className="font-medium text-[1.1em] text-gray-700 dark:text-textGray">The maximum input is currently limited to <BoldParagraph text={InputHandler.getAllowedMaxInputSize()}/>. To play with a larger number, increase the window size and refresh the page.</span>
2525
</div>
2626

2727
<div className="mt-[4em]">

‎src/components/Canvas/InputField.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ReactComponent as Play } from '../../img/play.svg'
66
import { ReactComponent as Replay } from '../../img/replay.svg'
77
import AlgorithmSelection from './AlgorithmSelection.js';
88
import ShowValue from './ShowValue.js';
9+
import { Animation } from '../Animation/Animation.js';
910

1011

1112
class InputField extends Component {
@@ -16,7 +17,7 @@ class InputField extends Component {
1617
this.name = props.name;
1718
this.Strategy = new Strategy();
1819
this.state = {
19-
algorithm: localStorage.getItem("algorithm") || 'Radix'
20+
algorithm: localStorage.getItem("algorithm") || 'Radix',
2021
}
2122
}
2223

@@ -60,7 +61,7 @@ class InputField extends Component {
6061
}} className=" p-[.7em] text-[.92em] ml-3 rounded-md text-white font-semibold hover:scale-[1.02] hover:bg-lightGreen transition duration-200 ease-in-out dark:bg-lightBlue2 bg-lightGreen dark:text-white hover:shadow-custom-md-blue dark:hover:shadow-custom-md-lightBlue">Generate Array</button>
6162
</div>
6263
</div>
63-
64+
6465

6566
<div className="flex gap-5 md:gap-10 flex-wrap justify-center items-center">
6667

@@ -79,6 +80,7 @@ class InputField extends Component {
7980
} className={`relative w-[3.2em] h-[2.6em] p-3 group rounded-lg flex ${this.state.algorithm && inputArrayLength ? "dark:bg-lightBlue2 bg-lightGreen cursor-pointer hover:shadow-custom-md-blue dark:hover:shadow-custom-md-lightBlue transition-all duration-200 ease-in-out" : "bg-gray-600 cursor-not-allowed"}`}>
8081
<Play className={`absolute left-[50%] top-[50%] -translate-x-[50%] -translate-y-[50%] scale-[1.1] mr-auto ml-auto transition-all duration-200 ease-in-out ${this.state.algorithm && "group-hover:scale-[1.2]"}`}/>
8182
</div>
83+
8284

8385
<div className="self-center group">
8486
<div onClick={() => { //TODO need to make sure to kill setTimeout

‎src/components/Strategy/Algorithms/QuickSort.js‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ class QuickSort {
104104

105105
async perform(options, array) {
106106
this.options = options;
107-
const DELAY = options.delay;
108-
const SKIP = options.skipJ;
109-
console.log(this.quickSort(array, 0, array.length-1));
107+
this.quickSort(array, 0, array.length-1);
110108
}
111109
}
112110

0 commit comments

Comments
 (0)