morry2341

InsertionSort Vorlesung 19.04

Apr 19th, 2023 (edited)
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. public static void insertionSort(int[] f){
  2. for(int i = 1; i < f.length; ++i){ //direkt incrementieren, deswegen ++i nicht i++
  3. int tmp = int[i];
  4. int j = i;
  5.  
  6. while(j> 0 && f[j-1] > tmp){
  7. f[j] = f[j-1];
  8. --j; //gleich dekrementieren deswegen --j nicht j--
  9. }
  10.  
  11. f[j] = tmp;
  12. }
  13. }
  14.  
  15. //mithilfe lässt man anzeigen die (un)sortierte Algorithmus Arrays.toString(values)
Advertisement
Add Comment
Please, Sign In to add comment