Inspiration
I made this project as part of Global Hack Week: Beginners Week Day 3
What it does
It is used for merging 2 different sorted lists.
How we built it
I used dart language to build it.
code
void main() {
var l1 = [1,3,5,7];
var l2 = [2,4,6,8];
var mergedList = mergeTwoLists(l1, l2);
print(mergedList);
}
List<int> mergeTwoLists(List<int> l1, List<int> l2){
int i = 0, j = 0;
var res = <int>[];
while(i < l1.length && j < l2.length){
if(l1[i] <= l2[j]){
res.add(l1[i++]);
}
else{
res.add(l2[j++]);
}
}
while(i < l1.length) {
res.add(l1[i++]);
}
while(j < l2.length) {
res.add(l2[j++]);
}
return res;
}
Built With
- dart
Log in or sign up for Devpost to join the conversation.