Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class JoinList {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- SLL<Integer> list1 = new SLL<>();
- SLL<Integer> list2 = new SLL<>();
- int n = Integer.parseInt(in.nextLine());
- String [] pom1 = in.nextLine().split(" ");
- for (int i = 0; i < n; i++) {
- list1.insertLast(Integer.parseInt(pom1[i]));
- }
- int m = Integer.parseInt(in.nextLine());
- String [] pom2 = in.nextLine().split(" ");
- for (int i = 0; i < m; i++) {
- list2.insertLast(Integer.parseInt(pom2[i]));
- }
- SLLNode<Integer> t2 = list2.getFirst();
- while(t2!=null) {
- list1.insertLast(t2.element);
- t2=t2.succ;
- }
- System.out.println(list1);
- SLLNode<Integer> t1 = list1.getFirst();
- while(t1.succ!=null) {
- SLLNode<Integer> t3 = t1.succ;
- while(t3!=null) {
- if(t1.element == t3.element) {
- list1.delete(t3);
- t3=t1.succ;
- }
- else {
- t3=t3.succ;
- }
- }
- t1=t1.succ;
- }
- System.out.println(list1);
- SLLNode<Integer> p1 = list1.getFirst();
- while(p1.succ!=null) {
- SLLNode<Integer> p2 = p1.succ;
- while(p2!=null) {
- if(p1.element > p2.element) {
- int tmp = p1.element;
- p1.element = p2.element;
- p2.element = tmp;
- p2=p2.succ;
- } else p2=p2.succ;
- }
- p1=p1.succ;
- }
- System.out.println(list1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement