-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBigIntegerSorting.java
66 lines (58 loc) · 1.53 KB
/
BigIntegerSorting.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class bigsorting {
public static void main(String[] args) {
int i;
Scanner in = new Scanner(System.in);
System.out.println("Enter the numbers that u want to take for sorting");
int n = in.nextInt();
String[] unsorted = new String[n];
System.out.println("enter the numbers ");
for(int unsorted_i=0; unsorted_i < n; unsorted_i++){
unsorted[unsorted_i] = in.next();
}
// your code goes here
BigInteger arr[]=new BigInteger[n];
for(i=0;i<n;i++)
{
long l= Long.parseLong(unsorted[i]);
BigInteger temp= BigInteger.valueOf(l);
arr[i]=temp;
}
for(i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
int res=arr[i].compareTo(arr[j]);
if(res==1)
{
BigInteger temp1 = arr[i];
arr[i]=arr[j];
arr[j]=temp1;
}
}
}
System.out.println("sorted sequence of bigintegers is :");
for(i=0;i<n;i++)
{
System.out.println(arr[i]);
}
}
}
/*output
run:
Enter the numbers that u want to take for sorting
3
enter the numbers
4567888
65435678
5678909876
sorted sequence of bigintegers is :
4567888
65435678
5678909876
BUILD SUCCESSFUL (total time: 10 seconds)
*/