Advertisement
LightProgrammer000

Ordenamento Bubble Sort [Array]

Jan 26th, 2019
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2.  
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4.  
  5.     <head>
  6.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7.         <title> Testando JavaScript </title>
  8.  
  9.         <style> </style>
  10.  
  11.         <script type="text/javascript">
  12.  
  13.             // Variável
  14.             var Valores = [ 10, 98, 56, 159, 84,
  15.                             72, 31, 39, 221, 42,
  16.                             11, 34, 21, 435, 60,
  17.                             54, 93, 32, 654, 92 ];
  18.  
  19.             // Método: Bubble Sort
  20.             for (i = 0; i < Valores.length; i++)
  21.             {
  22.                 for (j = 0; j < i; j++)
  23.                 {
  24.                     if ( Valores[j] > Valores[i] )
  25.                     {
  26.                         aux = Valores[i];
  27.                         Valores[i] = Valores[j];
  28.                         Valores[j] = aux;
  29.                     }
  30.                 }
  31.             }
  32.  
  33.             // Saída de dados
  34.             for (i = 0; i < Valores.length; i++)
  35.             {
  36.                 document.write(Valores[i] + "<br>");           
  37.             }
  38.  
  39.         </script>
  40.     </head>
  41.  
  42. <body>
  43.  
  44. </body>
  45.  
  46. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement