diff options
| author | Mike Vink <mike1994vink@gmail.com> | 2023-03-24 23:01:25 +0100 |
|---|---|---|
| committer | Mike Vink <mike1994vink@gmail.com> | 2023-03-24 23:01:25 +0100 |
| commit | ac1bf1b75868c873037f742b727e79ee5a97bae2 (patch) | |
| tree | ee160b8cb5b69e1ce9f7e5c8869b8ff24022a945 /coding-exercises/2/61.rkt | |
| parent | 16582f2c4094249f15d9ab37c1b49beafe542103 (diff) | |
progress
Diffstat (limited to 'coding-exercises/2/61.rkt')
| -rw-r--r-- | coding-exercises/2/61.rkt | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/coding-exercises/2/61.rkt b/coding-exercises/2/61.rkt new file mode 100644 index 0000000..71d773d --- /dev/null +++ b/coding-exercises/2/61.rkt @@ -0,0 +1,14 @@ +#lang racket + +;; linear scan required for this one, but on average we save some time because sometimes we can quickly +;; adjoin small values and other times a full linear scan is required to add a high value. +(define (adjoin-set x myset) + (cond ((null? myset) (cons x '())) + ((= (car myset) x) myset) + ((> (car myset) x) (cons x myset)) + (else (cons (car myset) + (adjoin-set x (cdr myset)))))) + +(define test-set (list 1 2 3 4 5 7)) +(adjoin-set 6 test-set) +(adjoin-set 8 test-set) |
