Junio_13.lsp



; =========================================
; Inserta numeros acomodandolos en la lista
; Fecha: Junio 13 del 2007
; Autor: YO
; copyright: LC - FIE - UMSNH
; =========================================

(defun Muestra (LT)
  (dolist (X LT)
    (print X)
  )
)

(defun Inserta (Atomo Lista)
  (setq L1 NIL)
  (setq L2 lista)
  
  (dotimes (x (length lista)) (setq elemento (nth x lista))
    (cond
      ;;;;;;;;;;IF
      ((> Atomo elemento)
         (setq L1 (append (list elemento) L1))		; principio
	 (setq L2 (cdr L2))				; resto
	 ;;(setq Lista (cdr Lista))
      )
      ;;;;;;;;;;ELSE
      ((<= Atomo Elemento)
         (setq L2 (append L1 (append (list Atomo) L2)))
	 (return L2)
      )
    )
  )
)

(defun LeeDato (Lista)
  (setq Atomo (read))
  (cond 
    (
       (eql NIL Lista) (setq Lista (list Atomo))	; if
    )
    (T
       (setq Lista (Inserta Atomo Lista))		; else
    )
  )
  Lista
)

(defun ciclo ()
  (setq cont 1)			; variable del ciclo
  (setq LT NIL)			; lista inicial
  (loop (if (>= cont 9) (return 9))
	(setq LT (LeeDato LT))	; Pide dato y actualiza LT
	(PRInt LT)
	(setf cont (1+ cont))
  )
  (Muestra LT)
)

(defun Inicia ()
  (ciclo)
  'FIN
)