-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.clj
More file actions
47 lines (41 loc) · 904 Bytes
/
stack.clj
File metadata and controls
47 lines (41 loc) · 904 Bytes
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
43
44
45
46
(ns clojurelogic.stack)
(declare push)
(declare pop)
(def my-list [])
(def list-size 3)
(def counter 0)
(defn stack-example []
(println "I am here")
(push 10)
(println my-list)
(push 20)
(println my-list)
(push 30)
(println my-list)
(push 40)
(println my-list)
(pop)
(println my-list)
(pop)
(println my-list)
(pop)
(println my-list)
(pop)
(println my-list))
(defn- push [num]
(if (= (count my-list)
list-size)
(println "Stack is full")
(do
(def my-list (conj my-list
num))
(def counter (inc counter)))))
(defn- pop []
(if (zero? counter)
(println "Stack is empty")
(let [ind-last-item (.indexOf my-list
(last my-list))]
(def my-list (subvec my-list
0
ind-last-item))
(def counter (dec counter)))))