want to make stack
Posted: Fri Apr 20, 2012 1:56 am
;; 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))))
;;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))))