class ListNode { val: number next: ListNode | null constructor(val?: number, next?: ListNode | null) { this.val = (val === undefined ? 0 : val) this.next = (next === undefined ? null : next) } } function mergeTwoLists(list1: ListNode | null, list2: ListNode | null): ListNode | null { if (!list1) return list2 if (!list2) return list1 if (!list1 && !list2) return null let sorted = new ListNode(), current = sorted while (list1 && list2) { if (list1.val < list2.val) { current.next = list1; list1 = list1.next } else { current.next = list2 list2 = list2.next } current = current.next } current.next = list1 || list2 return sorted.next };function Node(data) { this.data = data === undefined ? null : data; this.next = null; } function sortedMerge(first, second) { let a = new Node() const dummy = a while(first && second ){ if( first.data <second.data){ a.next = first first = first.next } else{ a.next= second second= second.next } a= a.next } if(first){ a.next=first } if(second){ a.next = second } return dummy.next }#include <stdio.h> #include <stdlib.h> struct node { int data; struct node *next; }; display(struct node *head) { if(head == NULL) { printf("NULL\n"); } else { printf("%d\n", head -> data); display(head->next); } } void concatenate(struct node *a,struct node *b) { if( a != NULL && b!= NULL ) { if (a->next == NULL) a->next = b; else concatenate(a->next,b); } else { printf("Either a or b is NULL\n"); } } int main() { struct node *prev,*a, *b, *p; int n,i; printf ("number of elements in a:"); scanf("%d",&n); a=NULL; for(i=0;i<n;i++) { p=malloc(sizeof(struct node)); scanf("%d",&p->data); p->next=NULL; if(a==NULL) a=p; else prev->next=p; prev=p; } printf ("number of elements in b:"); scanf("%d",&n); b=NULL; for(i=0;i<n;i++) { p=malloc(sizeof(struct node)); scanf("%d",&p->data); p->next=NULL; if(b==NULL) b=p; else prev->next=p; prev=p; } concatenate(a,b); return 0; }