@@ -4,6 +4,7 @@ import { MergeSort } from '../Strategy/Algorithms/MergeSort';
44import { RadixSortLSD } from '../Strategy/Algorithms/RadixSortLSD' ;
55import { QuickSort } from '../Strategy/Algorithms/QuickSort.js'
66import SelectionSort from '../Strategy/Algorithms/SelectionSort' ;
7+ import { HeapSort } from '../Strategy/Algorithms/Heapsort' ;
78function AlgorithmSelection ( { strategy, options} ) {
89
910 const [ currentAlgo , setCurrentAlgo ] = useState ( options . state . algorithm ) ;
@@ -12,6 +13,7 @@ function AlgorithmSelection({strategy, options}) {
1213 const Merge = new MergeSort ( ) ;
1314 const Selection = new SelectionSort ( ) ;
1415 const Quick = new QuickSort ( ) ;
16+ const Heap = new HeapSort ( ) ;
1517
1618
1719 useEffect ( ( ) => {
@@ -29,6 +31,7 @@ function AlgorithmSelection({strategy, options}) {
2931 else if ( currentAlgo === "Merge" ) strategy . setStrategy = Merge ;
3032 else if ( currentAlgo === "Selection" ) strategy . setStrategy = Selection ;
3133 else if ( currentAlgo === "Quick" ) strategy . setStrategy = Quick ;
34+ else if ( currentAlgo === "Heap" ) strategy . setStrategy = Heap ;
3235 } , [ ] )
3336
3437
@@ -55,6 +58,18 @@ function AlgorithmSelection({strategy, options}) {
5558 >
5659 < p className = { `${ currentAlgo === 'Radix' && 'text-black group-hover:text-white' } ` } > Radix Sort</ p >
5760 </ div >
61+
62+ < div className = { `${ currentAlgo === 'Heap' && 'bg-gray-200' } group cursor-pointer w-full hover:bg-gray-700 font-semibold text-white h-[2.8em] flex items-center justify-start pl-4` }
63+ onClick = { ( ) => {
64+ setCurrentAlgo ( 'Heap' ) ;
65+ options . setState ( { algorithm : "Heap" } ) ;
66+ strategy . setStrategy = Heap ;
67+ localStorage . setItem ( "algorithm" , "Heap" ) ;
68+ setShowDropdown ( ! showDropdown )
69+ } }
70+ >
71+ < p className = { `${ currentAlgo === 'Heap' && 'text-black group-hover:text-white' } ` } > Heap Sort</ p >
72+ </ div >
5873
5974 < div className = { `${ currentAlgo === 'Merge' && 'bg-gray-200' } group cursor-pointer w-full hover:bg-gray-700 font-semibold text-white h-[2.8em] flex items-center justify-start pl-4` }
6075 onClick = { ( ) => {
@@ -66,9 +81,22 @@ function AlgorithmSelection({strategy, options}) {
6681 } }
6782 >
6883 < p className = { `${ currentAlgo === 'Merge' && 'text-black group-hover:text-white' } ` } > Merge Sort</ p >
69-
7084 </ div >
71- < div className = { `${ currentAlgo === 'Selection' && 'bg-gray-200' } group cursor-pointer w-full hover:bg-gray-700 font-semibold text-white h-[2.8em] flex items-center justify-start pl-4` }
85+
86+ < div className = { `${ currentAlgo === 'Quick' && 'bg-gray-200' } group cursor-pointer w-full hover:bg-gray-700 font-semibold text-white h-[2.8em] flex items-center justify-start pl-4` }
87+ onClick = { ( ) => {
88+ setCurrentAlgo ( 'Quick' ) ;
89+ options . setState ( { algorithm : "Quick" } ) ;
90+ strategy . setStrategy = Quick ;
91+ localStorage . setItem ( "algorithm" , "Quick" ) ;
92+ setShowDropdown ( ! showDropdown )
93+ } }
94+ >
95+ < p className = { `${ currentAlgo === 'Quick' && 'text-black group-hover:text-white' } ` } > Quick Sort</ p >
96+ </ div >
97+
98+
99+ < div className = { `${ currentAlgo === 'Selection' && 'bg-gray-200' } group cursor-pointer w-full rounded-b-md hover:bg-gray-700 font-semibold text-white h-[2.8em] flex items-center justify-start pl-4` }
72100 onClick = { ( ) => {
73101 setCurrentAlgo ( 'Selection' ) ;
74102 options . setState ( { algorithm : "Selection" } ) ;
@@ -80,17 +108,6 @@ function AlgorithmSelection({strategy, options}) {
80108 < p className = { `${ currentAlgo === 'Selection' && 'text-black group-hover:text-white' } ` } > Selection Sort</ p >
81109
82110 </ div >
83- < div className = { `${ currentAlgo === 'Quick' && 'bg-gray-200' } group cursor-pointer w-full hover:bg-gray-700 rounded-b-md font-semibold text-white h-[2.8em] flex items-center justify-start pl-4` }
84- onClick = { ( ) => {
85- setCurrentAlgo ( 'Quick' ) ;
86- options . setState ( { algorithm : "Quick" } ) ;
87- strategy . setStrategy = Quick ;
88- localStorage . setItem ( "algorithm" , "Quick" ) ;
89- setShowDropdown ( ! showDropdown )
90- } }
91- >
92- < p className = { `${ currentAlgo === 'Quick' && 'text-black group-hover:text-white' } ` } > Quick Sort</ p >
93- </ div >
94111 </ div >
95112 </ div >
96113 )
0 commit comments