Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import java.util.Random;
  2. class bubble3
  3. {
  4.  
  5. static int [] randFill(int n)
  6. {
  7. Random r = new Random();
  8. int [] z = new int [n];
  9. for (int i=0;i<n;i++) z[i]=r.nextInt(n);
  10.  
  11. return z;
  12. }
  13.  
  14. static void Bubblesort(int [] a)
  15. {
  16. int N=a.length;
  17. for (int i=N-1;i>0;i--)
  18. for (int j=0;j<i;j++)
  19. if (a[j] > a[j+1])
  20. {
  21. int temp = a[j+1];
  22. a[j+1]=a[j];
  23. a[j]=temp;
  24. }
  25.  
  26. }
  27.  
  28. public static void main (String [] args)
  29. {
  30. for (int i=0;i<5000;i++)
  31. {
  32. int b[]=randFill(i);
  33. long x=System.nanoTime();
  34. Bubblesort(b);
  35. System.out.println(i+" "+(System.nanoTime()-x));
  36. }
  37. }
  38. }
  39.  
  40. Do the same for mergsort
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement