my
import java.util.*;
class Tttt
{
public static void main(String[] args)
{
int[] a1 = {1,2,4};
int[] a2 = {1,3,4};
get(a1, a2);
}
public static LinkedList get(int[] a1,int[] a2)
{
List<Integer> link1 = Ints.asList(a1);
//LinkedList<Integer> link1 = new LinkedList<Integer>(Arrays.asList(a1));
//LinkedList<Integer> link1 = Arrays.asList(a1);
//ArrayList< Integer> arrayList = new ArrayList< Integer>(a1.length);
//Collections.addAll(arrayList, a1);
LinkedList<Integer> link2 = new LinkedList<Integer>(Arrays.asList(a2));
/*
LinkedList<Integer> link1 = new LinkedList<Integer>();
link1.add(1);
link1.add(2);
link1.add(4);
sop(link1);
//List<Integer> link2 = new LinkedList<Integer>();
LinkedList<Integer> link2 = new LinkedList<Integer>();
link2.add(1);
link2.add(3);
link2.add(4);
sop(link2);
*/
link1.addAll(0,link2);
sop(link1);
Collections.sort(link1);
sop(link1);
}
// List<Integer> linkf = new LinkedList<Integer>();
//Iterator<Integer> it = link1.iterator();
/*
while(it.hasNext())
{
Integer temp = it.next();
sop(it.next)
}
}
*/
public static void sop(Object obj)
{
System.out.println(obj);
}
}
class MergeTwoSortedLists {
public ListNode mergeTwoLists(ListNode l1, ListNode l2)
{
//int val = 0;
ListNode head = new ListNode(0);
ListNode head = dummy;
while(l1 != null && l2 !=null)
{
if (l1.val < l2.val)
{
head.next = new ListNode(l1.val);
l1 = l1.next;
}
else
{
head.next = new ListNode(l2.val);
l2 = l2.next;
}
head = head.next;
}
if(l1 != null) head.next = l1;
if(l2 != null) head.next = l2;
return dummy.next;
}
public static void main(String[] args)
{
MergeTwoSortedLists sol = new MergeTwoSortedLists();
ListNode l1 = new ListNode(1);
l1.next = new ListNode(2);
l1.next.next = new ListNode(4);
ListNode l2 = new ListNode(1);
l2.next = new ListNode(3);
l2.next.next = new ListNode(4);
System.out.println(sol.mergeTwoLists(l1, l2));
}
}
class ListNode {
int val;
ListNode next;
//ListNode构造函数,三个
ListNode() {}
ListNode(int val) { this.val = val; }
ListNode(int val, ListNode next) { this.val = val; this.next = next; }
public String toString()
{
ListNode head = this;
StringBuilder sb = new StringBuilder();
while (head != null)
{
sb.append(head.val + "");
head = head.next;
}
return sb.toString();
}
}