Guest User

Untitled

a guest
Jul 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. public class Sortierer4{
  2.  
  3. //static void insertionSort (int[] a){
  4. public static void insertionSort (int[] a)
  5. {
  6. int i = 0;
  7. int j = 0;
  8. int key = 0;
  9. for (j = 2; j < a.length; j++)
  10. {
  11. key = a[j];
  12. i = j- 1;
  13.  
  14. while ((i > 0) && (a[i] > key))
  15. {
  16. a[i+1] = a[i];
  17. i = i - 1;
  18. }
  19. a[i + 1] = key;
  20. }
  21. }
  22. static void bubbleSort (int[] a)
  23. {
  24. boolean vertauscht = true;
  25. int h = 0;
  26. int n= a.length-1;
  27.  
  28. while (vertauscht & n>=1)
  29. {
  30. vertauscht = false;
  31. for (int i=0; i<n; i++)
  32. {
  33. if (a[i] > a[i+1])
  34. {
  35. h = a[i];
  36. a[i] = a[i+1];
  37. a[i+1] = h;
  38. vertauscht = true;
  39. }
  40. }
  41. n = n-1;
  42. }
  43.  
  44. }
  45. }
Add Comment
Please, Sign In to add comment