front-delete-deque.scm (1296B)
1 (define-library (sicp solutions chapter-3 exercise-23-stuff front-delete-deque) 2 (import (scheme base)) 3 (import (scheme write)) 4 5 (import (sicp solutions chapter-3 exercise-23-stuff empty-deque)) 6 (import (sicp solutions chapter-3 exercise-23-stuff front-ptr)) 7 (import (sicp solutions chapter-3 exercise-23-stuff rear-ptr)) 8 (import (sicp solutions chapter-3 exercise-23-stuff set-front-ptr)) 9 (import (sicp solutions chapter-3 exercise-23-stuff set-rear-ptr)) 10 (import (prefix (sicp solutions chapter-3 exercise-23-stuff doubly-linked-list) dll:)) 11 12 (export front-delete-deque!) 13 14 (begin 15 (define (front-delete-deque! deque) 16 "Delete frontmost item of DEQUE if DEQUE is not empty, otherwise raise an error." 17 18 (display (dll:doubly-linked-list->list (front-ptr deque))) (newline) 19 (cond 20 ((empty-deque? deque) 21 (error "FRONT-DELETE-DEQUE! called with an empty deque" deque)) 22 ((null? (dll:link-rear (front-ptr deque))) ; The front link's rear pointer would point at '() only if it is the only link in the DEQUE. 23 (set-front-ptr! deque '()) 24 (set-rear-ptr! deque '())) 25 (else 26 (set-front-ptr! deque 27 (dll:link-rear (front-ptr deque))) 28 (dll:delete-front! (front-ptr deque)))) 29 deque)))