Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SpecialSLLJoin {
- public static void pecati(SLL<Integer> lista)
- {
- SLLNode<Integer> tmp = lista.getFirst();
- while(tmp != null)
- {
- System.out.print(tmp.element + " ");
- tmp = tmp.succ;
- }
- }
- public static SLL<Integer> joinList (SLL<Integer> lista1, SLL<Integer> lista2)
- {
- SLL<Integer> finalList = new SLL<Integer>();
- SLLNode<Integer> tmp1 = lista1.getFirst();
- SLLNode<Integer> tmp2 = lista2.getFirst();
- while(tmp1 != null && tmp1.succ !=null && tmp2 != null && tmp2.succ != null)
- {
- finalList.insertLast(tmp1.element);
- finalList.insertLast(tmp1.succ.element);
- finalList.insertLast(tmp2.element);
- finalList.insertLast(tmp2.succ.element);
- if(tmp1.succ.succ != null && tmp2.succ.succ != null)
- {
- tmp1 = tmp1.succ.succ;
- tmp2 = tmp2.succ.succ;
- }
- }
- if(tmp1 != null)
- {
- while(tmp1 != null)
- {
- finalList.insertLast(tmp1.element);
- tmp1 = tmp1.succ;
- }
- }
- if(tmp2 != null)
- {
- while(tmp2 != null)
- {
- finalList.insertLast(tmp2.element);
- tmp2 = tmp2.succ;
- }
- }
- return finalList;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement