-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedListCombine.java
More file actions
45 lines (43 loc) · 1.47 KB
/
LinkedListCombine.java
File metadata and controls
45 lines (43 loc) · 1.47 KB
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
package Codes;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
public class LinkedListCombine {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
List[] array=new List[n];
try {
for (int i = 0; i < n; i++) {
LinkedList<Integer> list = new LinkedList<>();
while (true) {
String input = sc.nextLine();
String[] s = input.split(" ");
if (input.endsWith("")) {
if (!input.equals("")) {
for (int j = 0; j < s.length; j++) {
list.add(Integer.parseInt(s[i]));
}
array[i] = list;
break;
}
}
}
}
LinkedList<Integer> output = new LinkedList<>();
for (int i = 0; i < n; i++) {
output.addAll(array[i]);
}
Collections.sort(output);
for (int i = 0; i < output.size(); i++) {
if (i == output.size() - 1) {
System.out.print(output.get(i));
} else System.out.print(output.get(i) + "->");
}
}
catch (Exception e){
System.out.println("Invalid Input");
}
}
}