public static ListNode insertionSortList2(ListNode head) {//accepted after consulting answer
        if (head == null || head.next == null) {
            return head;
        }
        else {
            ListNode dummy = new ListNode(0);
            ListNode p = dummy;
            while (head != null) {
                ListNode toinsert = head;
                head = head.next;

                if (toinsert.val < p.val) {
                    p = dummy;//go back to the head;
                }
                while (p.next != null && toinsert.val > p.next.val) {
                    p = p.next;
                }
                toinsert.next = p.next;
                p.next = toinsert;
            }
            ListNode t = dummy.next;
            while (t != null) {
                System.out.println(t.val);
                t = t.next;
            }
            return dummy.next;
        }
    }