Problem Description( Refer to Exercise 6 on Page 116) Write a quick sort function of type...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Problem Description( Refer to Exercise 6 on Page 116) Write a quick sort function of type int list -> int list. Here is a review for quick sort algorithm. First pick an element and call it pivot. (The head of the list is an easy choice for the pivot.) Partition the rest of the list into two sublists, one with all the elements less than the pivot and another one with all the elements not less than the pivot. Recursively sort the sublists. Combine two sublists and pivot into final sorted list. Requirement: The solution must follow the style of function merge sort on page 114. The help functions must be made inside let. Sample Run: Please see the screen shot below to see the sample run Project - run.x86-darwin - 80x24 Last login: Sat Jan 2 15:13:23 on ttys000 MACS-H-ZENG-MBA: ~ h_zeng $ cd Documents/CSCI461VA/Project MACS-H-ZENG-MBA: Project h_zeng$ sml Standard ML of New Jersey v110.79 [built: Sun Oct 4 14:45:06 2015] - use "CSCI461ProjTwo.sml"; [opening CSCI461Proj Two.sml] val partition = fn : int * int list -> int list * int list val quickSort = fn : int list -> int list val newQuickSort = fn: int list -> int list val it (): unit - val x = [3, 1, 4, 8, 9, 5, 7, 6, 2, 0]; val x = [3,1,4,8,9,5,7,6,2,0]: int list - quickSort x; val it = [0,1,2,3,4,5,6,7,8,9] int list Problem Description( Refer to Exercise 6 on Page 116) Write a quick sort function of type int list -> int list. Here is a review for quick sort algorithm. First pick an element and call it pivot. (The head of the list is an easy choice for the pivot.) Partition the rest of the list into two sublists, one with all the elements less than the pivot and another one with all the elements not less than the pivot. Recursively sort the sublists. Combine two sublists and pivot into final sorted list. Requirement: The solution must follow the style of function merge sort on page 114. The help functions must be made inside let. Sample Run: Please see the screen shot below to see the sample run Project - run.x86-darwin - 80x24 Last login: Sat Jan 2 15:13:23 on ttys000 MACS-H-ZENG-MBA: ~ h_zeng $ cd Documents/CSCI461VA/Project MACS-H-ZENG-MBA: Project h_zeng$ sml Standard ML of New Jersey v110.79 [built: Sun Oct 4 14:45:06 2015] - use "CSCI461ProjTwo.sml"; [opening CSCI461Proj Two.sml] val partition = fn : int * int list -> int list * int list val quickSort = fn : int list -> int list val newQuickSort = fn: int list -> int list val it (): unit - val x = [3, 1, 4, 8, 9, 5, 7, 6, 2, 0]; val x = [3,1,4,8,9,5,7,6,2,0]: int list - quickSort x; val it = [0,1,2,3,4,5,6,7,8,9] int list
Expert Answer:
Answer rating: 100% (QA)
Here is a quicksort function in SML that follows the style of the merge sort ... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
Why is it difficult to addresses a variety of readers who have different perspectives from those of the writer? What specific actions should you take to lessen or eliminate this issue?
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Refer to Exercise 6 on page 119 for a description of a study about walking speed. Exercise 6 In a double-blind study, 50 older adults who had difficulty keeping their balance and/or were slow walkers...
-
In Exercises find the vertex, focus, and directrix of the parabola, and sketch its graph. x 2 + = 0
-
A block with mass M = 5.0kg rests on a frictionless table and is attached by a horizontal spring (k = 130 N/m) to a wall. A second block, of mass m = 1.25 kg, rests on top of M. The coefficient of...
-
7. If your original loan amount for a 30-year fixed rate Interest Only (IO) mortgage loan is $300,000?, and the annual interest rate is 10%, what is the monthly payment
-
Exercise 3.31 introduced the dataset StatisticsPhD, which gives enrollment for all 82 graduate statistics programs in the US in 2009. Use StatKey or other technology to generate a sampling...
-
Creative Solutions purchased a patent from Russell Lazarus, an inventor. At the time of the purchase, the patent had two years remaining. The president of Creative Solutions decided to have the...
-
labour cost. Last year, the company sold 30,000 of these balls, with the following results: Sales (30,000 balls) $750,000 Variable expenses Contribution margin 450,000 300,000 Fixed expenses...
-
Southeastern Foods has hired you to analyze their distribution-system design. The company has 11 distribution centers, with monthly volumes as listed below. Seven of these sites can support...
-
Phosphatase enzymes catalyse what type of reaction. O Glycosylation. Acetylation. Phosphorylation (addition of a phosphoryl group (PO3) to an organic molecule). Catalytic removal of a phosphate group...
-
Suppose that E and F are two events and that N(E and F) = 210 and N(E) = 330. What is P(F|E)?
-
Two cans of pumpkin roll down a loading dock ramp. They have identical inertias, but one of them has a larger radius (and a shorter length) than the other. Which one, if either, makes it down the...
-
The owners of Bardoza Greeting Cards wish to introduce a new line of cards but need to raise \(\$ 200,000\) to do it. They decide to issue 10 -year bonds with a contract rate of \(6 \%\) paid...
-
The house key lengths of 15 statistics students are measured and rounded to the nearest centimeter, and all 15 values are the same, so the standard deviation is 0 cm. Decide whether the statement...
-
Indicate true or false for the following statements. If false, specify what change will make the statement true. _______ The sampling distribution of a proportion is approximated by the 2...
-
Symbolic integration in Matlab can be done, syms x f = x^2; int (f) For the definite integral, for example from 0 to 1 is den by int (f,0,1) Use this toolbox to find the integrals of S f(x) = xex, F...
-
From 1970 to 1990, Sri Lanka's population grew by approximately 2.2 million persons every five years. The population in 1970 was 12.2 million people.What is the best formula for P, Sri Lanka's...
-
a. Wilson filed his individual tax return on the original due date, but failed to pay $700 in taxes that were due with the return. If Wilson pays the taxes exactly 2 months late, calculate the amount...
-
For each of the following cases, indicate the filing status for the taxpayer(s) for 2012 using the following legend: A - Single B - Married, filing a joint return C - Married, filing separate returns...
-
Greg died on July 1, 2012, and left Lea, his wife, a $50,000 life insurance policy which she elects to receive at $5,000 per year plus interest for 10 years. In the current year, Lea receives $6,200....
-
The following financial information is available for Plummer SA. The weighted-average number of ordinary shares outstanding was 80,000 for 2024 and 100,000 for 2025. Instructions Calculate return on...
-
Gorton Ltd. has 30,000 shares of 10 par value ordinary shares outstanding when it announces a 2- for-1 share split. Before the split, the shares had a market price of 120 per share. After the split,...
-
The equity section of Ahab SA at December 31 is as follows. Instructions From a review of the equity section, as chief accountant, write a memo to the president of the company answering the following...
Study smarter with the SolutionInn App