Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
22
Task/Queue-Definition/Racket/queue-definition-1.rkt
Normal file
22
Task/Queue-Definition/Racket/queue-definition-1.rkt
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#lang racket
|
||||
|
||||
(define (make-queue) (mcons #f #f))
|
||||
(define (push! q x)
|
||||
(define new (mcons x #f))
|
||||
(if (mcar q) (set-mcdr! (mcdr q) new) (set-mcar! q new))
|
||||
(set-mcdr! q new))
|
||||
(define (pop! q)
|
||||
(define old (mcar q))
|
||||
(cond [(eq? old (mcdr q)) (set-mcar! q #f) (set-mcdr! q #f)]
|
||||
[else (set-mcar! q (mcdr old))])
|
||||
(mcar old))
|
||||
(define (empty? q)
|
||||
(not (mcar q)))
|
||||
|
||||
(define Q (make-queue))
|
||||
(empty? Q) ; -> #t
|
||||
(push! Q 'x)
|
||||
(empty? Q) ; -> #f
|
||||
(for ([x 3]) (push! Q x))
|
||||
(pop! Q) ; -> 'x
|
||||
(list (pop! Q) (pop! Q) (pop! Q)) ; -> '(0 1 2)
|
||||
Loading…
Add table
Add a link
Reference in a new issue