Question

In: Computer Science

LISP Programming Language Write a Bubble Sort program in the LISP Programming Language called “sort” that...

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:

  1. Invoke your LISP sort function by (sort '(34 56 4 10 77 51 93 30 5 52))
  2. Use the Bubble Sort Algorithm to sort the array in ascending order
  3. LISP will automatically display the array when the sort function completes

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)

>

Solutions

Expert Solution

 

(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)

)


Related Solutions

Scheme is a dialect of a programming language called Lisp, which was developed at MIT in...
Scheme is a dialect of a programming language called Lisp, which was developed at MIT in 1959. Alice 1.0 was released in 2006 from CMU, and Python in 1994. Based on what you know of the Scheme language, describe the major differences between how it works and how Alice or Python works. What advantages might Scheme have over Alice/Python? What advantages might Alice/Python have over Scheme?
Write Insertion Sort and Bubble Sort Program for C# also write their algorithm and Explain their...
Write Insertion Sort and Bubble Sort Program for C# also write their algorithm and Explain their working.
Write a program and test a program that translates the following Bubble Sort algorithm to a...
Write a program and test a program that translates the following Bubble Sort algorithm to a bubblesort function. The function's prototype is, void bubblesort(int a[], int size); Bubble Sort The inner loop moves the largest element in the unsorted part of the array to the last position of the unsorted part of the array; the outer loop moves the last position of the unsorted part of the array. The Bubble sort exchanges elements with adjacent elements as it moves the...
Using C# programming language, Write a program that sort three numbers entered by the user using...
Using C# programming language, Write a program that sort three numbers entered by the user using only if and nested if statements. If for instance the user entered 5, 2, and 7; the program should display 2,5,7.
Write a program to implement and analyzing the Bubble Sort. a. Write a C++ function for...
Write a program to implement and analyzing the Bubble Sort. a. Write a C++ function for Bubble Sort b. Use a dynamic array of integers in a variable size of n. c. Display the following information: 1) Total counts of comparisons 2) Total counts of shifts / moves / swaps, whichever applies d. Write a main() function to test a best, and an average cases in terms of time efficiency i. Fill out the array with random numbers for an...
The programming language is C. In its simplest algorithm, the bubble sort technique compares each two...
The programming language is C. In its simplest algorithm, the bubble sort technique compares each two adjacent elements of an array of size “N” and exchanges their values if they are out of order. The process of comparing and exchanging is repeated for N array passes. For sorting array elements in ascending order, the smaller values “bubble” to the top of the array (toward element 0), while the larger values sink to the bottom of the array. Assuming that: double...
Write and test a C program to implement Bubble Sort. . In your C program, you...
Write and test a C program to implement Bubble Sort. . In your C program, you should do: Implement the array use an integer pointer, get the size of the array from standard input and use the malloc function to allocate the required memory for it. Read the array elements from standard input. Print out the sorted array, and don’t forget to free the memory. Debug your program using Eclipse C/C++ CDT.
Write a program that performs a merge-sort algorithm without using a recursion. c++ programming language(Only #inlclude...
Write a program that performs a merge-sort algorithm without using a recursion. c++ programming language(Only #inlclude <iostream>)
in MARIE simulator, write assembly language to BUBBLE SORT 30 hexadecimals store in two array.
in MARIE simulator, write assembly language to BUBBLE SORT 30 hexadecimals store in two array.
1.   Bubble Sort Implement a bubble sort program that will read from a file “pp2.txt” from...
1.   Bubble Sort Implement a bubble sort program that will read from a file “pp2.txt” from the current directory a list of intergers (10 numbers to be exact), and the sort them, and print them to the screen. You can use redirection to read data from a given file through standard input, as opposed to reading the data from the file with the read API (similar to Lab #1). You can assume the input data will only have 10 numbers...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT