is there any funtion to test wherther the given list is in ascending or descendin order
I saw one funtion INSEQA but ts not working
any function is there
-
- Posts: 47
- Joined: Fri Jun 03, 2011 5:30 am
- Location: Behind you.
- Contact:
Re: any function is there
Perhaps something like this? Lol, it is late by me so my code may seem a little messy today and everything
Murali, I really get the feeling that you are needing this code and the previous for some assignment of some sort. You do not even post any code as a guide-line, which raises suspicion.
Here you go though:
Murali, I really get the feeling that you are needing this code and the previous for some assignment of some sort. You do not even post any code as a guide-line, which raises suspicion.
Here you go though:
Code: Select all
;;; By Indecipherable
;;; Checks if a list is in a disc. or asc. order, or neither.
(defun check (list)
(let ((list-dec (copy-list list)))
(let ((list-inc (copy-list list)))
(let ((alist (sort list-inc #'<)))
(let ((dlist (sort list-dec #'>)))
(cond
((equal alist list)
(format t "The list is in an ascending order."))
((equal dlist list)
(format t "The list is in a descending order.")))
(if
(not (equal alist list))
(if
(not (equal dlist list))
(format t "NO MATCH"))))))))
Don't take the FUN out of DEFUN !
Re: any function is there
Code: Select all
(apply #'< list)
-
- Posts: 47
- Joined: Fri Jun 03, 2011 5:30 am
- Location: Behind you.
- Contact:
Re: any function is there
Okay so obviously there are quite alot of waysKonfusius wrote:Code: Select all
(apply #'< list)
Don't take the FUN out of DEFUN !
Re: any function is there
That doesn't work, because it's supposed to check if the list is either ascending or descending. You could doKonfusius wrote:Code: Select all
(apply #'< list)
Code: Select all
(or (apply #'<= list) (apply #'>= list))
Code: Select all
(defun orderedp (list)
(let ((order nil) (last (first list)))
(dolist (x (rest list) (or order :EQUAL))
(cond ((< x last)
(if (and order (eq order :ASCENDING))
(return nil)
(setq order :DESCENDING)))
((> x last)
(if (and order (eq order :DESCENDING))
(return nil)
(setq order :ASCENDING))))
(setq last x))))