11import React , { Component } from 'react' ;
22import './bubbleAnimations.css' ;
33import BubbleSortAlgo from '../algorithms/bubbleSort' ;
4+ import SelectionSortAlgo from '../algorithms/selectionSort'
45
56class BubbleSort extends Component
67{
@@ -10,9 +11,13 @@ class BubbleSort extends Component
1011 componentDidMount ( ) {
1112 this . generateRandom ( ) ;
1213 }
13- sortArray = ( ) => {
14+ bubbleSort = ( ) => {
1415 var animationsArray = BubbleSortAlgo ( this . state . array ) ;
15- console . log ( "hi" ) ;
16+ this . startAnimations ( animationsArray ) ;
17+ }
18+
19+ selectionSort = ( ) => {
20+ var animationsArray = SelectionSortAlgo ( this . state . array ) ;
1621 this . startAnimations ( animationsArray ) ;
1722 }
1823 startAnimations ( animationsArray )
@@ -23,7 +28,7 @@ class BubbleSort extends Component
2328 var swap = comparision [ 2 ] ;
2429 // console.log(firstElem,secondElem)
2530 setTimeout ( ( ) => {
26- console . log ( firstElem , secondElem )
31+ // console.log(firstElem,secondElem)
2732 this . changeColourCompare ( firstElem , secondElem ) ;
2833 } , ( i + 0.25 ) * 50 )
2934 setTimeout ( ( ) => { this . changeBackColour ( firstElem , secondElem ) ; } , ( i + 0.5 ) * 50 )
@@ -70,7 +75,8 @@ class BubbleSort extends Component
7075 return (
7176 < >
7277 < button className = "newArray" onClick = { this . generateRandom } > New Array</ button >
73- < button className = "sortArray" onClick = { this . sortArray } > Sort Array</ button >
78+ < button className = "bubbleSort" onClick = { this . bubbleSort } > Bubble Sort</ button >
79+ < button className = "selectionSort" onClick = { this . selectionSort } > Selection Sort</ button >
7480 < div className = 'bars' >
7581 { array . map ( ( value , i ) => {
7682 return (
0 commit comments