Merge Sorted List

A
```// https://leetcode.com/problems/merge-two-sorted-lists/
import 'package:test/test.dart';

class ListNode {
int? val;
ListNode? next;
ListNode({this.val = 0, this.next});
}

ListNode? node = this;
while (node != null) {
print(node.val);
node = node.next;
}
}

List<int?> listValues() {
List<int?> values = [];
ListNode? node = this;
while (node != null) {
node = node.next;
}
return values;
}
}

ListNode? mergeTwoLists(ListNode? list1, ListNode? list2) {
if (list1 == null) {
return list2;
} else if (list2 == null) {
return list1;
}

if ((list1.val ?? 0) < (list2.val ?? 0)) {
list1 = list1.next;
} else {
list2 = list2.next;
}

while (list1 != null || list2 != null) {
if (list1 != null && list2 != null) {
if ((list1.val ?? 0) < (list2.val ?? 0)) {
node?.next = list1;
list1 = list1.next;
} else {
node?.next = list2;
list2 = list2.next;
}
} else if (list1 != null) {
node?.next = list1;
list1 = list1.next;
} else {
node?.next = list2;
list2 = list2?.next;
}

node = node?.next;
}
}

void main() {
test('test case 1', () {
ListNode(val: 1, next: ListNode(val: 2, next: ListNode(val: 4)));