Advertisement
Hiteshw11

Merge Two Sorted Lists

Nov 24th, 2024
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.35 KB | Source Code | 0 0
  1. /* Write a function that merges two sorted lists into one sorted list. */
  2.  
  3. void main() {
  4.   List<int> list1=[1,3,5];
  5.   List<int> list2=[2,4,6];
  6.   print(mergeSortedLists(list1,list2));
  7. }
  8.  
  9. List<int> mergeSortedLists(List<int> list1,List<int> list2)
  10. {
  11.  List<int> list3=[];
  12.  list3.addAll(list1);
  13.  list3.addAll(list2);
  14.  list3.sort();
  15.  return list3;
  16. }
Tags: dart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement