RosettaCodeData/Task/Singly-linked-list-Element-insertion/Scheme/singly-linked-list-element-insertion-1.ss
Ingy döt Net 68f8f3e56b all tasks
2013-04-11 01:07:29 -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))))))