Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. //Bubblesort.java
  2. public class Bubblesort
  3. {
  4.     static void sort(int[] arr)
  5.     {
  6.         int sort=0;
  7.         for(int i=0;i<arr.lenght;i++)
  8.         {
  9.             for(int j=0;j=i-1; j++)
  10.             {
  11.                 if(arr[j]>arr[i])
  12.                 {
  13.                     int temp=arr[j];
  14.                     arr[j]=arr[i];
  15.                     arr[i]=temp;
  16.                     sort++;
  17.                 }
  18.                 else
  19.                 {
  20.                 }
  21.                
  22.                 if(sort!=0)
  23.                 {
  24.                     sort(int[] arr);   
  25.                 }
  26.             }
  27.         }
  28.         for(int i=0;i<arr.length;i++)
  29.         {
  30.             System.out.println(arr[i]);
  31.         }
  32.     }
  33.     public static void main(String[] args)
  34.     {
  35.         System.out.print("Initialisiere Array...\n");
  36.         int [] array{1,4,7,2,3,7,9,40,20};
  37.         sort(array);       
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement