Construct a List using the given Q XOR queries | C # program for the above approach ; Function to return required list after performing all the queries ; Store cumulative Bitwise XOR ; Initialize readonly list to return ; Perform each query ; The initial value of 0 ; Sort the list ; Return readonly list ; Driver Code ; Given Queries ; Function Call
using System ; using System . Collections . Generic ; class GFG { static List < int > ConstructList ( int [ , ] Q ) { int xor = 0 ; List < int > ans = new List < int > ( ) ; for ( int i = Q . GetLength ( 0 ) - 1 ; i >= 0 ; i -- ) { if ( Q [ i , 0 ] == 0 ) ans . Add ( Q [ i , 1 ] ^ xor ) ; else xor ^= Q [ i , 1 ] ; } ans . Add ( xor ) ; ans . Sort ( ) ; return ans ; } public static void Main ( String [ ] args ) { int [ , ] Q = { { 0 , 6 } , { 0 , 3 } , { 0 , 2 } , { 1 , 4 } , { 1 , 5 } } ; foreach ( int i in ConstructList ( Q ) ) Console . Write ( i + " , ▁ " ) ; } }