Find out the correct position of the ball after shuffling | C ++ implementation of the above approach ; Function to generate the index of the glass containing the ball ; Change the index ; Change the index ; Print the index ; Driver 's Code ; Storing all the shuffle operation
#include <bits/stdc++.h> NEW_LINE using namespace std ; const int M = 3 , N = 2 ; void getIndex ( int n , int shuffle [ ] [ N ] ) { for ( int i = 0 ; i < 3 ; i ++ ) { if ( shuffle [ i ] [ 0 ] == n ) n = shuffle [ i ] [ 1 ] ; else if ( shuffle [ i ] [ 1 ] == n ) n = shuffle [ i ] [ 0 ] ; } cout << n ; } int main ( ) { int n = 3 ; int shuffle [ M ] [ N ] = { { 3 , 1 } , { 2 , 1 } , { 1 , 2 } } ; getIndex ( n , shuffle ) ; }