-
Notifications
You must be signed in to change notification settings - Fork 0
/
3.22.scm
37 lines (35 loc) · 992 Bytes
/
3.22.scm
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
(define (make-queue)
(let ((front-ptr '())
(rear-ptr '()))
(define (empty?)
(if (eq? front-ptr '())
#t
#f))
(define (front-queue)
(if (empty?)
(error "Ololo empty queue!")
(front-ptr)))
(define (insert! item)
(let ((new-pair (cons item '())))
(cond ((empty?)
(set! front-ptr new-pair)
(set! rear-ptr new-pair))
(else
(set-cdr! rear-ptr new-pair)
(set! rear-ptr new-pair)))))
(define (delete!)
(cond ((empty?)
(error "Deletos"))
(else
(set! front-ptr (cdr front-ptr)))))
(define (print)
(display front-ptr))
(define (dispatch m)
(cond
((eq? m 'empty?) empty?)
((eq? m 'front-queue) front-queue)
((eq? m 'insert) insert!)
((eq? m 'delete) delete!)
((eq? m 'print) print)
(else "Unknown method")))
dispatch))