From 0af3f8403acaf6622339a50fd9966b8d00a11ee8 Mon Sep 17 00:00:00 2001 From: Samuel Ortion Date: Fri, 31 Oct 2025 23:09:37 +0100 Subject: [PATCH] solve: 88. Merge two sorted list in Racket --- racket/88.merge-sorted-array.rkt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 racket/88.merge-sorted-array.rkt diff --git a/racket/88.merge-sorted-array.rkt b/racket/88.merge-sorted-array.rkt new file mode 100644 index 0000000..080aa53 --- /dev/null +++ b/racket/88.merge-sorted-array.rkt @@ -0,0 +1,20 @@ +; 88. Merge Sorted Array +; +; We consider that the function returns the sorted list +; instead of overwriting the nums1 list (as specified in the subject) + + +#lang racket + +(define/contract (merge nums1 nums2) + (-> (listof number?) (listof number?) (listof number?)) + "Merge recursively two sorted lists NUMS1 and NUMS2." + (cond + [(null? nums1) nums2] + [(null? nums2) nums1] + [(< (car nums1) (car nums2)) + (cons (car nums1) (merge (if (list? nums1) (cdr nums1) '()) nums2))] + [else (cons (car nums2) (merge (if (list? nums2) (cdr nums2) '()) nums1))])) + +(for/list ([item (merge '(1 2 3) '(1 3 5))]) + (println item))