@tomaszjarosz/react-visualizers 0.2.10 → 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +53 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +53 -1
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
package/dist/index.cjs
CHANGED
|
@@ -1210,6 +1210,46 @@ const ALGORITHM_COMPLEXITIES$1 = {
|
|
|
1210
1210
|
quick: { time: "O(n log n)", space: "O(log n)" },
|
|
1211
1211
|
merge: { time: "O(n log n)", space: "O(n)" }
|
|
1212
1212
|
};
|
|
1213
|
+
const ALGORITHM_CODE$1 = {
|
|
1214
|
+
bubble: [
|
|
1215
|
+
"for (i = 0; i < n-1; i++)",
|
|
1216
|
+
" for (j = 0; j < n-i-1; j++)",
|
|
1217
|
+
" if (arr[j] > arr[j+1])",
|
|
1218
|
+
" swap(arr[j], arr[j+1])"
|
|
1219
|
+
],
|
|
1220
|
+
selection: [
|
|
1221
|
+
"for (i = 0; i < n-1; i++)",
|
|
1222
|
+
" minIdx = i",
|
|
1223
|
+
" for (j = i+1; j < n; j++)",
|
|
1224
|
+
" if (arr[j] < arr[minIdx])",
|
|
1225
|
+
" minIdx = j",
|
|
1226
|
+
" swap(arr[i], arr[minIdx])"
|
|
1227
|
+
],
|
|
1228
|
+
insertion: [
|
|
1229
|
+
"for (i = 1; i < n; i++)",
|
|
1230
|
+
" key = arr[i]",
|
|
1231
|
+
" j = i - 1",
|
|
1232
|
+
" while (j >= 0 && arr[j] > key)",
|
|
1233
|
+
" arr[j+1] = arr[j]",
|
|
1234
|
+
" j--",
|
|
1235
|
+
" arr[j+1] = key"
|
|
1236
|
+
],
|
|
1237
|
+
quick: [
|
|
1238
|
+
"quickSort(arr, low, high)",
|
|
1239
|
+
" if (low < high)",
|
|
1240
|
+
" pi = partition(arr, low, high)",
|
|
1241
|
+
" quickSort(arr, low, pi-1)",
|
|
1242
|
+
" quickSort(arr, pi+1, high)"
|
|
1243
|
+
],
|
|
1244
|
+
merge: [
|
|
1245
|
+
"mergeSort(arr, l, r)",
|
|
1246
|
+
" if (l < r)",
|
|
1247
|
+
" m = (l + r) / 2",
|
|
1248
|
+
" mergeSort(arr, l, m)",
|
|
1249
|
+
" mergeSort(arr, m+1, r)",
|
|
1250
|
+
" merge(arr, l, m, r)"
|
|
1251
|
+
]
|
|
1252
|
+
};
|
|
1213
1253
|
const BINARY_SEARCH_CODE = [
|
|
1214
1254
|
"binarySearch(arr, target):",
|
|
1215
1255
|
" left = 0, right = n - 1",
|
|
@@ -2774,6 +2814,8 @@ function generateRandomArray(size) {
|
|
|
2774
2814
|
return Array.from({ length: size }, () => Math.floor(Math.random() * 100) + 5);
|
|
2775
2815
|
}
|
|
2776
2816
|
const SortingComparisonVisualizerComponent = ({
|
|
2817
|
+
showControls = true,
|
|
2818
|
+
showCode = true,
|
|
2777
2819
|
className = ""
|
|
2778
2820
|
}) => {
|
|
2779
2821
|
const [algorithm1, setAlgorithm1] = React.useState("bubble");
|
|
@@ -2942,7 +2984,17 @@ const SortingComparisonVisualizerComponent = ({
|
|
|
2942
2984
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center text-2xl font-bold text-gray-300", children: "VS" }),
|
|
2943
2985
|
renderAlgorithmPanel(algorithm2, state2, setAlgorithm2, algorithm1, "border-purple-200")
|
|
2944
2986
|
] }) }) }),
|
|
2945
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-4 py-3
|
|
2987
|
+
showCode && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-4 py-3 border-t border-gray-200", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
2988
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
2989
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs font-medium text-indigo-600 mb-2", children: ALGORITHM_NAMES$1[algorithm1] }),
|
|
2990
|
+
/* @__PURE__ */ jsxRuntime.jsx(CodePanel, { code: ALGORITHM_CODE$1[algorithm1], activeLine: -1 })
|
|
2991
|
+
] }),
|
|
2992
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
2993
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs font-medium text-purple-600 mb-2", children: ALGORITHM_NAMES$1[algorithm2] }),
|
|
2994
|
+
/* @__PURE__ */ jsxRuntime.jsx(CodePanel, { code: ALGORITHM_CODE$1[algorithm2], activeLine: -1 })
|
|
2995
|
+
] })
|
|
2996
|
+
] }) }),
|
|
2997
|
+
showControls && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-4 py-3 bg-gray-50 border-t border-gray-200", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between flex-wrap gap-3", children: [
|
|
2946
2998
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
2947
2999
|
isPlaying && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex items-center gap-1 text-xs text-indigo-600 font-medium", children: [
|
|
2948
3000
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "w-2 h-2 bg-indigo-500 rounded-full animate-pulse" }),
|