Advertisement
AnaGocevska

Untitled

Oct 21st, 2015
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. public class SpecialSLLJoin {
  2.    
  3.     public static void pecati(SLL<Integer> lista)
  4.     {
  5.         SLLNode<Integer> tmp = lista.getFirst();
  6.        
  7.         while(tmp != null)
  8.         {
  9.             System.out.print(tmp.element + " ");
  10.             tmp = tmp.succ;
  11.         }
  12.     }
  13.  
  14.     public static SLL<Integer> joinList (SLL<Integer> lista1, SLL<Integer> lista2)
  15.     {
  16.         SLL<Integer> finalList = new SLL<Integer>();
  17.         SLLNode<Integer> tmp1 = lista1.getFirst();
  18.         SLLNode<Integer> tmp2 = lista2.getFirst();
  19.        
  20.         while(tmp1 != null && tmp1.succ !=null && tmp2 != null && tmp2.succ != null)
  21.         {
  22.             finalList.insertLast(tmp1.element);
  23.             finalList.insertLast(tmp1.succ.element);
  24.             finalList.insertLast(tmp2.element);
  25.             finalList.insertLast(tmp2.succ.element);
  26.            
  27.             if(tmp1.succ.succ != null && tmp2.succ.succ != null)
  28.             {
  29.                 tmp1 = tmp1.succ.succ;
  30.                 tmp2 = tmp2.succ.succ;
  31.             }
  32.            
  33.         }
  34.         if(tmp1 != null)
  35.         {
  36.             while(tmp1 != null)
  37.             {
  38.                 finalList.insertLast(tmp1.element);
  39.                 tmp1 = tmp1.succ;
  40.             }
  41.         }
  42.         if(tmp2 != null)
  43.         {
  44.             while(tmp2 != null)
  45.             {
  46.                 finalList.insertLast(tmp2.element);
  47.                 tmp2 = tmp2.succ;
  48.             }
  49.         }
  50.         return finalList;
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement