In: Computer Science
LISP Programming Language
Write a Bubble Sort program in the LISP Programming Language called “sort” that sorts the array below in ascending order. LISP is a recursive language so the program will use recursion to sort. Since there will be no loops, you will not need the variables i, j, and temp, but still use the variable name array for the array to be sorted.
Array to be sorted is 34, 56, 4, 10, 77, 51, 93, 30, 5, 52
The program should:
The output should look like the following:
Welcome to DrRacket, version 5.3.4 [3m].
Language: racket; memory limit: 128 MB.
'(4 5 10 30 34 51 52 56 77 93)
>
(defun bubble (n)
(format t "<<Bubble Sort for ~D numbers>> -> ~&" n)
(bubbleread n)
(do ((i 0 (+ i 1))) ((= i (- n 1)))
(do ((j 0 (+ j 1))) ((= j (- (- n i) 1)))
(if (> (aref arr j) (aref arr (+ j 1) ) )
(swap j (+ j 1))
)
)
)
(bubblewrite n)
)
(defun bubbleread(n)
(setf arr (make-array n))
(format t "Enter the numbers ~&")
(dotimes (x n t)
(setf (aref arr x) (read))
)
)
(defun bubblewrite(n)
(dotimes (x n t)
(print (aref arr x))
)
)
(defun swap(x y)
(setf temp (aref arr x))
(setf (aref arr x) (aref arr y))
(setf (aref arr y) temp)
)