From 932c83c0079a0631bd0a8a40d7a03f965aa02d32 Mon Sep 17 00:00:00 2001 From: Quinta <0pietroquintavalle0@gmail.com> Date: Sat, 29 Jun 2024 13:43:07 +0200 Subject: [PATCH] not too bad --- app/page.tsx | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/app/page.tsx b/app/page.tsx index 9fe6ce4..b9752eb 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -3,21 +3,28 @@ import { useState, useEffect } from "react" import { Button } from "@/components/ui/button" import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuRadioGroup, DropdownMenuRadioItem } from "@/components/ui/dropdown-menu" +import { Slider } from "@/components/ui/slider" export default function Component() { const [array, setArray] = useState([]) const [isRunning, setIsRunning] = useState(false) const [currentAlgorithm, setCurrentAlgorithm] = useState("bubble") + const [arraySize, setArraySize] = useState(20) useEffect(() => { - generateRandomArray() - }, []) + generateRandomArray(arraySize) + }, [arraySize]) - const generateRandomArray = () => { - const newArray = Array.from({ length: 50 }, () => Math.floor(Math.random() * 100)) + const generateRandomArray = (size: number) => { + const newArray = Array.from({ length: size }, () => Math.floor(Math.random() * 100)) setArray(newArray) } + const shuffleArray = () => { + const shuffledArray = [...array].sort(() => Math.random() - 0.5) + setArray(shuffledArray) + } + const startAnimation = () => { setIsRunning(true) switch (currentAlgorithm) { @@ -41,7 +48,7 @@ export default function Component() { const resetAnimation = () => { setIsRunning(false) - generateRandomArray() + generateRandomArray(arraySize) } const bubbleSort = async () => { @@ -127,22 +134,28 @@ export default function Component() { } return ( -
-
+
+
+

Algorithm Visualizer

+
+
{array.map((value, index) => (
))}
- + + - Algorithms + + {currentAlgorithm.charAt(0).toUpperCase() + currentAlgorithm.slice(1)} Sort +
+
+ + setArraySize(value[0])} + min={5} + max={100} + /> +
) }