Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class test2{
- //static void insertionSort (int[] a){
- public static void insertionSort (int[] a)
- {
- int i = 0;
- int j = 0;
- int key = 0;
- for (j = 1; j < a.length; j++)
- {
- key = a[j];
- i = j- 1;
- while ((i >= 0) && (a[i] > key))
- {
- a[i+1] = a[i];
- i = i - 1;
- }
- a[i + 1] = key;
- }
- }
- public static void main (String args []){
- int a[]={
- 3,8,9,1,5,7,6
- };
- //int x = a[1];
- insertionSort (a);
- int i=0;
- System.out.print ("Sortiert mit insertion: ");
- for (i=0;i<a.length;i++){
- System.out.print (a[i]);
- }
- System.out.println ();
- }
- }
Add Comment
Please, Sign In to add comment