Insert order

Insert Sort

package tp.zgz.chapter04;

public class InsertSort {
public static void main(String[] args) {
int[] arr = new int[10];
for (int i = 0; i arr[i] = (int) (100 + Math.random() * (100 + 1));
}
System.out.printf("Array before sorting:");
for (int i = 0; i <10; i++) {
System.out.printf(arr[i] + "");
}
System.out.println();
System.out.printf("sorted array:" );
SelectedSort.Sort(arr);
}

static void Sort(int arr[]) {
//Traverse the data
for ( int i = 1; i
int temp = arr[i];
int j = i-1; //j is the position to be inserted< br /> while (j >= 0 && temp arr[j + 1] = arr[j];
j--;
}
arr[j + 1] = temp;
}
print(arr);
}

static void print(int arr[]) {
for (int i = 0; i System.out.printf(" %d ", arr[i]);
}
}
}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5283 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.