Skip to content

Commit 4e1e57e

Browse files
kraklokam-zhan-yue
authored andcommitted
refactor: add MSD Radix Sort parameters and URL support
1 parent 5534a01 commit 4e1e57e

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* eslint-disable no-prototype-builtins */
2+
/* eslint-disable jsx-a11y/label-has-associated-control */
3+
import React, { useState, useContext, useEffect } from 'react';
4+
import { URLContext } from '../../context/urlState';
5+
import { genRandNumList } from './helpers/ParamHelper';
6+
import ListParam from './helpers/ListParam';
7+
import PropTypes from 'prop-types';
8+
import { withAlgorithmParams } from './helpers/urlHelpers';
9+
import '../../styles/Param.scss';
10+
11+
const DEFAULT_NODES = genRandNumList(10, 1, 100);
12+
const DEFAULT_MODE = 'sort';
13+
const MSD_RADIX_SORT = 'MSD Radix Sort';
14+
const MSDRS_SORT_EXAMPLE = 'Please follow the example provided: 0,1,2,3,4';
15+
16+
function MSDRadixSortParam({ mode, list }) {
17+
const [message, setMessage] = useState(null);
18+
const [localNodes, setLocalNodes] = useState(list || DEFAULT_NODES);
19+
const { setNodes } = useContext(URLContext);
20+
21+
useEffect(() => {
22+
setNodes(localNodes);
23+
}, [localNodes]);
24+
25+
return (
26+
<>
27+
<div className="form">
28+
<ListParam
29+
name="radixSortMSD"
30+
buttonName="Sort"
31+
mode={mode || DEFAULT_MODE}
32+
formClassName="formLeft"
33+
DEFAULT_VAL={localNodes}
34+
SET_VAL={setLocalNodes}
35+
ALGORITHM_NAME={MSD_RADIX_SORT}
36+
EXAMPLE={MSDRS_SORT_EXAMPLE}
37+
setMessage={setMessage}
38+
/>
39+
</div>
40+
41+
{/* render success/error message */}
42+
{message}
43+
</>
44+
);
45+
}
46+
47+
MSDRadixSortParam.propTypes = {
48+
alg: PropTypes.string.isRequired,
49+
mode: PropTypes.string.isRequired,
50+
list: PropTypes.string.isRequired,
51+
}
52+
53+
export default withAlgorithmParams(MSDRadixSortParam);

src/algorithms/parameters/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export { default as HSParam } from './HSParam';
33
export { default as BSTParam } from './BSTParam';
44
export { default as QSParam } from './QSParam';
55
export { default as msort_arr_td } from './msort_arr_td';
6+
export { default as MSDRadixSortParam } from './MSDRadixSortParam';
67
export { default as msort_lista_td } from './msort_lista_td';
78
export { default as Prims_oldParam } from './PRIM_oldParam';
89
export { default as PrimsParam } from './PRIMParam';

0 commit comments

Comments
 (0)