Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Stack/Clojure/stack-1.clj
Normal file
20
Task/Stack/Clojure/stack-1.clj
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
(deftype Stack [elements])
|
||||
|
||||
(def stack (Stack (ref ())))
|
||||
|
||||
(defn push-stack
|
||||
"Pushes an item to the top of the stack."
|
||||
[x] (dosync (alter (:elements stack) conj x)))
|
||||
|
||||
(defn pop-stack
|
||||
"Pops an item from the top of the stack."
|
||||
[] (let [fst (first (deref (:elements stack)))]
|
||||
(dosync (alter (:elements stack) rest)) fst))
|
||||
|
||||
(defn top-stack
|
||||
"Shows what's on the top of the stack."
|
||||
[] (first (deref (:elements stack))))
|
||||
|
||||
(defn empty-stack?
|
||||
"Tests whether or not the stack is empty."
|
||||
[] (= () (deref (:elements stack))))
|
||||
Loading…
Add table
Add a link
Reference in a new issue