Advertisement
jackyhuichunkit

InsertionSort

Mar 25th, 2020
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Random;
  3. class InsertionSort {
  4.  
  5.     private static int MAX = 10;
  6.     private static int[] data = new int[MAX];
  7.  
  8.     public static void init() {
  9.         Random rand = new Random();
  10.         for (int i=0; i < MAX; i++) {
  11.             data[i] = rand.nextInt(50);
  12.         }
  13.     }
  14.  
  15.     public static void printData() {
  16.         for (int i=0; i < MAX; i++) {
  17.             System.out.printf("%6d", i);
  18.         }
  19.         System.out.println();
  20.         for (int i=0; i < MAX; i++) {
  21.             System.out.printf("%6d", data[i]);
  22.         }
  23.         System.out.println();
  24.  
  25.     }
  26.  
  27.     public static void main(String[] args) {
  28.  
  29.         init();
  30.         System.out.println("Before:");
  31.         printData();
  32.  
  33.         // Do sorting here on the global variable data[]
  34.  
  35.         System.out.println("After:");
  36.         printData();
  37.  
  38.     }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement