transpose 2D Array List using swap or suggest me a way to swap without using additional Array list

Viewed 23

please find the below code for 2D array list swap, have used swap only for normal array list, please let me know how to do it using 2D array list

   int n=A.size();
   int m=A.get(0).size();
   for(int i=0;i<n;i++)
    { 
      for(int j=0;j<m;j++)
        {  
         //i have tried to swap using collections.swap            
          Collections.swap(A,A.get(i).get(j),A.get(j).get(i));
        }
   }
0 Answers
Related