Find the arrangement of queue at given time | Java program to find the arrangement of queue at time = t ; prints the arrangement at time = t ; Checking the entire queue for every moment from time = 1 to time = t . ; If current index contains ' B ' and next index contains ' G ' then swap . ; Driver function
import java . io . * ; class Geek { static void solve ( int n , int t , char s [ ] ) { for ( int i = 0 ; i < t ; i ++ ) for ( int j = 0 ; j < n - 1 ; j ++ ) if ( s [ j ] == ' B ' && s [ j + 1 ] == ' G ' ) { char temp = s [ j ] ; s [ j ] = s [ j + 1 ] ; s [ j + 1 ] = temp ; j ++ ; } System . out . print ( s ) ; } public static void main ( String args [ ] ) { int n = 6 , t = 2 ; String s = " BBGBBG " ; char str [ ] = s . toCharArray ( ) ; solve ( n , t , str ) ; } }