;; IN THIS PROGRAM I WANT TO CHANGE REMOVE-FRONT FUNCTION TO RETURN ;;VALUES IN REVERSE ORDER LIKE
;;IF I ENTER a c b it returns a then c then b but i want that b must be returned first ;;then c then a
(defstruct q
(key #'identity)
(last nil)
(elements nil))
(defun make-empty-queue () (make-q))
(defun empty-queue? (q)
"Are there no elements in the queue?"
(= (length (q-elements q)) 0))
(defun queue-front (q)
"Return the element at the front of the queue."
(elt (q-elements q) 0))
(defun remove-front (q)
"Remove the element from the front of the queue and return it."
(if (listp (q-elements q))
(pop (q-elements q))
))
(defun enqueue-at-front (q items)
"Add a list of items to the front of the queue."
(setf (q-elements q) (nconc items (q-elements q))))
want to make stack
Re: want to make stack
Please provide attribution when you reuse code from others.
http://aima.cs.berkeley.edu/lisp/utilities/queue.lisp
CL already has PUSH and POP for stack manipulations. If a normal project, these are the default choice. In a homework assignment, both should be avoided; here, you want tools like CONS, CAR, CDR, and SETF. Plus there's the built-in REVERSE function.
Are you working on SICP exercise 2.18? There are a few elegant recursive solutions to the problem, as well as the usual iterative solutions.
http://aima.cs.berkeley.edu/lisp/utilities/queue.lisp
CL already has PUSH and POP for stack manipulations. If a normal project, these are the default choice. In a homework assignment, both should be avoided; here, you want tools like CONS, CAR, CDR, and SETF. Plus there's the built-in REVERSE function.
Are you working on SICP exercise 2.18? There are a few elegant recursive solutions to the problem, as well as the usual iterative solutions.