previous | index | next

Implementing RA-Stacks Using Nodes

RA-Stack Creation: Under this representation, a stack is only as big as it needs to be, so there is no need for make-ra-stack-with-at-most.
     (define make-ra-stack
       (lambda ()
	 (make-node 0 '()))) ; height 0, no other nodes
RA-Stack Height:
     (define height
       (lambda (ra-stack)
	 (node-element ra-stack)))
RA-Stack Emptiness: Since empty-ra-stack? was defined in terms of height in the first representation, it need not be changed:
     (define empty-ra-stack?
       (lambda (ra-stack)
	 (= 0 (height ra-stack))))

previous | index | next