Advertisement
ineedmorespacelx

Ordenar Matrices (Números ascendentes)

Nov 23rd, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package itfkdup;
  7.  
  8. /**
  9.  *
  10.  * @author Usuariomaq23
  11.  */
  12. public class Itfkdup {
  13.  
  14.     /**
  15.      * @param args the command line arguments
  16.      */
  17.     public static void main(String[] args) {
  18.         int M[][] = {{7,6,15,4,3,2,1},{6,7,5,4,3,20,1},{1,6,7,40,3,2,1},{4,6,5,7,3,2,1},{1,6,5,4,3,2,7}};
  19.         int x, y;
  20.         int MU2[];
  21.        
  22.         for(x=0; x<M.length; x++)
  23.         {
  24.             MU2 = ordenar(x,M);
  25.            
  26.             for(y=0; y<MU2.length; y++)
  27.             {
  28.                 System.out.print(MU2[y] + " ");
  29.             }
  30.             System.out.println();
  31.         }
  32.     }
  33.     public static int[] ordenar(int x, int M[][])
  34.     {
  35.         int MU[];
  36.         int y;
  37.         for(y=0; y<M[x].length; y++)
  38.         {
  39.         }
  40.        
  41.         MU = new int[y];
  42.        
  43.         for(y=0; y<M[x].length; y++)
  44.         {
  45.             MU[y] = M[x][y];
  46.         }
  47.        
  48.         int c, i=1, pos, t;
  49.         c=MU.length;
  50.         while(i>0)
  51.         {
  52.             i=0;
  53.             c=c-1;
  54.             pos=0;
  55.            
  56.             while(pos<c)
  57.             {
  58.                 if(MU[pos]>MU[pos+1])
  59.                 {
  60.                     t=MU[pos];
  61.                     MU[pos] = MU[pos+1];
  62.                     MU[pos+1] = t;
  63.                     i++;
  64.                 }
  65.                 pos++;
  66.             }
  67.         }
  68.         /*for(x=0; x<MU.length; x++)
  69.         {
  70.             System.out.println(MU[x]);
  71.         }*/
  72.         return MU;
  73.     }
  74.    
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement