Aha! So here are conventional enqueue and dequeue operations in Scheme
(sorry I'm more familiar with scheme than with lisp :) ). The set-car!
and set-cdr! are self-explanatory.
(define (enqueue! queue item)
(let ((new-pair (cons item nil)))
(cond ((empty-queue? queue)
(set-front-ptr! queue new-pair)
(set-rear-ptr! queue new-pair)
queue)
(else
(set-cdr! (rear-ptr queue) new pair)
(set-rear-ptr! queue new-pair)
queue))))
(define (dequeue! queue)
(cond ((empty-queue? queue)
(error "Empty queue" queue))
(else
(set-front-ptr! queue (cdr (front-ptr-queue)))
queue)))
So basically the difference, as you said, is that in the above method
we are mutating the pointers in the cells. That makes complete sense,
when thinking in terms of functional programming! Although I'm familiar
with functional languages, as you can see I think procedurally :D
Thanks again!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---