Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 0 0
  1. package APS_TEST;
  2.  
  3. import APS_TEST.SLL.SLL;
  4. import APS_TEST.SLL.SLLNode;
  5.  
  6. import java.util.Scanner;
  7.  
  8. public class SpecialSLLJoin
  9. {
  10.     public static void main(String[] args)
  11.     {
  12.         SLL<Integer>    list_1          =   new SLL<>();
  13.         SLL<Integer>    list_2          =   new SLL<>();
  14.         SLL<Integer>    list_3          = new SLL<>();
  15.         Scanner             scanner         =   new Scanner(System.in);
  16.         int                     list_1_len;
  17.         int                     list_2_len;
  18.  
  19.  
  20.         // List_1 input read
  21.         list_1_len = scanner.nextInt();
  22.         for (int i = 0; i < list_1_len; ++i)
  23.             list_1.insertLast(scanner.nextInt());
  24.  
  25.         // List_2 input read
  26.         list_2_len = scanner.nextInt();
  27.         for (int i = 0; i< list_2_len; ++i)
  28.             list_2.insertLast(scanner.nextInt());
  29.  
  30.  
  31.         SLLNode<Integer> temp1 = list_1.getFirst();
  32.         SLLNode<Integer> temp2 = list_2.getFirst();
  33.  
  34.  
  35.         // probi celo vreme dve po dve da zimas
  36.         // prekini so cikluso ako nemozas dve po dve da zimas
  37.         while (temp1 != null && temp2 != null)
  38.         {
  39.             if (temp1.getSucc() != null)
  40.             {
  41.                 list_3.insertLast(temp1.getElement());
  42.                 list_3.insertLast(temp1.getSucc().getElement());
  43.  
  44.                 temp1 = temp1.getSucc().getSucc();
  45.             }
  46.             else
  47.                 break;
  48.  
  49.             if (temp2.getSucc() != null)
  50.             {
  51.                 list_3.insertLast(temp2.getElement());
  52.                 list_3.insertLast(temp2.getSucc().getElement());
  53.  
  54.                 temp2 = temp2.getSucc().getSucc();
  55.             }
  56.             else
  57.                 break;
  58.         }
  59.  
  60.         int x = 0;
  61.  
  62.  
  63.         // elementite so ostanale od lista 1 dodadi gi na lista 3
  64.         while (temp1 != null)
  65.         {
  66.             list_3.insertLast(temp1.getElement());
  67.             temp1 = temp1.getSucc();
  68.         }
  69.  
  70.  
  71.         // elementite so ostanale od lista 2 dodadi gi na lista 3
  72.         while (temp2 != null)
  73.         {
  74.             list_3.insertLast(temp2.getElement());
  75.             temp2 = temp2.getSucc();
  76.         }
  77.  
  78.         // print result
  79.         System.out.println(list_3);
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement