-
Notifications
You must be signed in to change notification settings - Fork 0
/
ch2.clj
45 lines (31 loc) · 774 Bytes
/
ch2.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
(ns viksit.cljfsd)
; Basic stack functions from Chapter 2 (Okasaki)
(defn make-stack []
"Empty stack"
nil)
(defn stack-push [stack item]
"Return new stack with item pushed in"
(cons item stack))
(defn stack-top [stack]
"Top item on the stack"
(first stack))
(defn stack-empty? [stack]
"Check whether the stack is empty"
(empty? stack))
(defn stack-size [stack]
"Find no of items on the stack"
(count stack))
(defn map-stack [fun stack]
(map fun stack))
(defn stack-from-list [lst]
lst)
;; Exercise 2.1
;; Take a list and return a list of all suffixes in decreasing order of length
(defn suf [coll]
(loop [c coll
ret []]
(if (empty? c)
ret
(recur (next c)
(conj ret c)))))
;; 2.2 Binary Search Trees