-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3.21.scm
53 lines (33 loc) · 1.08 KB
/
3.21.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(define (front-ptr q)
(car q))
(define (rear-ptr q)
(cdr q))
(define (set-front-ptr! q item)
(set-car! q item))
(define (set-rear-ptr! q item)
(set-cdr! q item))
(define (empty-queue? queue) (null? (front-ptr queue)))
(define (make-queue)
(cons '() '()))
(define (front-queue queue)
(if (empty-queue? queue)
(error "FRONT вызвана с пустой очередью" queue)
(car (front-ptr queue))))
(define (insert-queue! queue item)
(let ((new-pair (cons item '())))
(cond ((empty-queue? queue)
(set-front-ptr! queue new-pair)
(set-rear-ptr! queue new-pair)
queue)
(else
(set-cdr! (rear-ptr queue) new-pair)
(set-rear-ptr! queue new-pair)
queue))))
(define (delete-queue! queue)
(cond ((empty-queue? queue)
(error "DELETE! вызвана с пустой очередью" queue))
(else
(set-front-ptr! queue (cdr (front-ptr queue)))
queue)))
(define (print-queue queue)
(display (front-ptr queue)))