forked from aliya-rahmani/Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimSort.java
28 lines (22 loc) · 835 Bytes
/
TimSort.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.Arrays;
import java.util.Random;
public class TimSort {
public static void main(String args[])
{
System.out.println("Sorting of randomly generated numbers using TIM SORT");
Random random = new Random();
int N = 20;
int[] sequence = new int[N];
for (int i = 0; i < N; i++)
sequence[i] = Math.abs(random.nextInt(100));
System.out.println("\nOriginal Sequence: ");
printSequence(sequence);
System.out.println("\nSorted Sequence: ");
Arrays.sort(sequence); // as TimSort is used by Java for sorting arrays since Java 7
printSequence(sequence);
}
private static void printSequence(int[] sortedSequence)
{
for (int aSortedSequence : sortedSequence) System.out.print(aSortedSequence + " ");
}
}