@@ -656,18 +656,28 @@ IEnumerator buildMaxHeap(int[] arr, int n) {
656656 }
657657
658658 IEnumerator RadixSort ( int [ ] Array ) {
659+ List < GameObject > pillars = new List < GameObject > ( ) ;
660+ foreach ( Transform tran in GameObject . Find ( "Bar" ) . transform ) {
661+ pillars . Add ( tran . gameObject ) ;
662+ }
663+
659664 int n = Array . Length ;
660665 int max = Array [ 0 ] ;
661666
662667 //find largest element in the Array
663668 for ( int i = 1 ; i < n ; i ++ ) {
664- if ( max < Array [ i ] )
669+ if ( max < Array [ i ] ) {
665670 max = Array [ i ] ;
671+ }
666672 }
667673
668674 //Counting sort is performed based on place.
669675 //like ones place, tens place and so on.
670676 for ( int place = 1 ; max / place > 0 ; place *= 10 ) {
677+ if ( place >= 0 && place < Array . Length ) {
678+ pillars [ place ] . GetComponent < Pillar > ( ) . Color = nextColor ;
679+ }
680+
671681 yield return new WaitForSeconds ( time ) ;
672682 yield return StartCoroutine ( CountingSort ( Array , place ) ) ;
673683 }
@@ -680,6 +690,11 @@ IEnumerator RadixSort(int[] Array) {
680690 }
681691
682692 IEnumerator CountingSort ( int [ ] Array , int place ) {
693+ List < GameObject > pillars = new List < GameObject > ( ) ;
694+ foreach ( Transform tran in GameObject . Find ( "Bar" ) . transform ) {
695+ pillars . Add ( tran . gameObject ) ;
696+ }
697+
683698 int n = Array . Length ;
684699 int [ ] output = new int [ n ] ;
685700
@@ -688,9 +703,14 @@ IEnumerator CountingSort(int[] Array, int place) {
688703 //count number of occurrences in freq array
689704 for ( int i = 0 ; i < n ; i ++ ) {
690705 yield return new WaitForSeconds ( time ) ;
706+ pillars [ i ] . GetComponent < Pillar > ( ) . Color = tempColor ;
691707 freq [ ( Array [ i ] / place ) % 10 ] ++ ;
692708 }
693709
710+ for ( int i = 0 ; i < Array . Length ; i ++ ) {
711+ pillars [ i ] . GetComponent < Pillar > ( ) . Color = whiteColor ;
712+ }
713+
694714 //Change count[i] so that count[i] now contains actual
695715 //position of this digit in output[]
696716 for ( int i = 1 ; i < 10 ; i ++ ) {
@@ -703,13 +723,19 @@ IEnumerator CountingSort(int[] Array, int place) {
703723 yield return new WaitForSeconds ( time ) ;
704724 output [ freq [ ( Array [ i ] / place ) % 10 ] - 1 ] = Array [ i ] ;
705725 freq [ ( Array [ i ] / place ) % 10 ] -- ;
726+ pillars [ i ] . GetComponent < Pillar > ( ) . Color = tempColor ;
727+ }
728+
729+ for ( int i = 0 ; i < Array . Length ; i ++ ) {
730+ pillars [ i ] . GetComponent < Pillar > ( ) . Color = whiteColor ;
706731 }
707732
708733 //Copy the output array to the input Array, Now the Array will
709734 //contain sorted array based on digit at specified place
710735 for ( int i = 0 ; i < n ; i ++ ) {
711736 yield return new WaitForSeconds ( time ) ;
712737 Array [ i ] = output [ i ] ;
738+ pillars [ i ] . GetComponent < Pillar > ( ) . Color = tempColor ;
713739 }
714740 }
715741}
0 commit comments