Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package APS_TEST;
- import APS_TEST.SLL.SLL;
- import APS_TEST.SLL.SLLNode;
- import java.util.Scanner;
- public class SpecialSLLJoin
- {
- public static void main(String[] args)
- {
- SLL<Integer> list_1 = new SLL<>();
- SLL<Integer> list_2 = new SLL<>();
- SLL<Integer> list_3 = new SLL<>();
- Scanner scanner = new Scanner(System.in);
- int list_1_len;
- int list_2_len;
- // List_1 input read
- list_1_len = scanner.nextInt();
- for (int i = 0; i < list_1_len; ++i)
- list_1.insertLast(scanner.nextInt());
- // List_2 input read
- list_2_len = scanner.nextInt();
- for (int i = 0; i< list_2_len; ++i)
- list_2.insertLast(scanner.nextInt());
- SLLNode<Integer> temp1 = list_1.getFirst();
- SLLNode<Integer> temp2 = list_2.getFirst();
- // probi celo vreme dve po dve da zimas
- // prekini so cikluso ako nemozas dve po dve da zimas
- while (temp1 != null && temp2 != null)
- {
- if (temp1.getSucc() != null)
- {
- list_3.insertLast(temp1.getElement());
- list_3.insertLast(temp1.getSucc().getElement());
- temp1 = temp1.getSucc().getSucc();
- }
- else
- break;
- if (temp2.getSucc() != null)
- {
- list_3.insertLast(temp2.getElement());
- list_3.insertLast(temp2.getSucc().getElement());
- temp2 = temp2.getSucc().getSucc();
- }
- else
- break;
- }
- int x = 0;
- // elementite so ostanale od lista 1 dodadi gi na lista 3
- while (temp1 != null)
- {
- list_3.insertLast(temp1.getElement());
- temp1 = temp1.getSucc();
- }
- // elementite so ostanale od lista 2 dodadi gi na lista 3
- while (temp2 != null)
- {
- list_3.insertLast(temp2.getElement());
- temp2 = temp2.getSucc();
- }
- // print result
- System.out.println(list_3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement