1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React, { useState, useEffect } from "react";
import { makeStyles } from "@material-ui/styles";
// This function from @material-ui/styles help create css
const userStyle = makeStyles({
container: {
display: "flex",
justifyContent: "center",
alignItems: "flex-end",
height: "100%",
border: "2px solid lightgray"
},
bar: {
margin: "1px"
}
});
// Initializes a random array based on props given (min, max, amt)
const initArray = (min, max, amount) => {
let arr = [];
for (let i = 0; i < amount; i++)
arr.push(Math.floor(Math.random() * max) + min);
return arr;
};
// Main sorting array. Change this for different algorithms.
const BubbleSort = props => {
// Make our styles first with useStyles()
const classes = userStyle();
// useState is used to create "state" variables in function components which have no state.
// It works like this:
// const [var, targetMethod] = useState(arg from targetMethod);
// Object.assign(target, source) (makes an empty array from initArray return val)
const [masterArr] = useState(Object.assign([], initArray(1, 100, 50)));
// "array" var will hold the sorted array
const [array, setArray] = useState([]);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX