tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
25
Task/Queue-Definition/Scheme/queue-definition-2.ss
Normal file
25
Task/Queue-Definition/Scheme/queue-definition-2.ss
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
(define (make-queue)
|
||||
(let ((q (cons '() '())))
|
||||
(lambda (cmd . arg)
|
||||
(case cmd
|
||||
((empty?) (null? (car q)))
|
||||
((put) (let ((a (cons (car arg) '())))
|
||||
(if (null? (car q))
|
||||
(begin (set-car! q a) (set-cdr! q a))
|
||||
(begin (set-cdr! (cdr q) a) (set-cdr! q a)))))
|
||||
((get) (if (null? (car q)) 'empty
|
||||
(let ((x (caar q)))
|
||||
(set-car! q (cdar q))
|
||||
(if (null? (car q)) (set-cdr! q '()))
|
||||
x)))
|
||||
))))
|
||||
|
||||
(define q (make-queue))
|
||||
(q 'put 1)
|
||||
(q 'put 6)
|
||||
(q 'get)
|
||||
; 1
|
||||
(q 'get)
|
||||
; 6
|
||||
(q 'get)
|
||||
; empty
|
||||
Loading…
Add table
Add a link
Reference in a new issue