RosettaCodeData/Task/Singly-linked-list-Element-insertion/Scheme/singly-linked-list-element-insertion-1.scm
2024-10-16 18:07:41 -07:00

8 lines
294 B
Scheme

(define (insert-after a b lst)
(if (null? lst)
lst ; This should be an error, but we will just return the list untouched
(let ((c (car lst))
(cs (cdr lst)))
(if (equal? a c)
(cons a (cons b cs))
(cons c (insert-after a b cs))))))