previous | index | next

RA-Stack Creation

Since this implementation imposes a stack size limit, we'll define the ADT constructor in terms of another:
     (define make-ra-stack
       (lambda ()
	 (make-ra-stack-with-at-most 8))) ; choose your own constant


     (define make-ra-stack-with-at-most
       (lambda (max-height)
	 (let ((header (make-vector 2))
	       (cells (make-vector max-height)))
	   (vector-set! header 0 0)     ; height
	   (vector-set! header 1 cells) ; stack itself
	   header)))
Note that only the header is returned, because the actual cells are accessed through it.

previous | index | next