Lecture 23: Quick sort
This assignment is due on Sunday, November 6 at 11:59pm. Submit it using Handin as assignment lecture23.
5 6 2 1 8 2 3 7 |
Use this app to draw the decomposition. Make a rectangle for every problem.
Click the “Copy to clipboard” button in the lower-left corner of the app.
- Paste the code as a comment, like this:
; Quick sort: ; <bpmn:definitions ..... ..... ..... ; ..... ..... ..... ..... ..... ..... ; ..... ..... ..... ..... ..... ..... ; ..... ..... </bpmn:definitions>
; A PivotTree is one of: ; - (make-no-pivot) ; - (make-pivot PivotTree Number PivotTree) (define-struct no-pivot []) (define-struct pivot [left val right]) (define pt0 (make-no-pivot)) (define pt1 (make-pivot pt0 1 (make-no-pivot))) (define pt2 (make-pivot pt1 2 (make-pivot (make-no-pivot) 3 (make-no-pivot))))
5 6 2 1 8 2 3 7 |
Exercise 3. Write the template for a function that processes a PivotTree. Make it look like a function called process-pivottree, and do not put it in a comment.
Exercise 5. What would happen if smaller used < instead of <=? Write a correct test for the quick-sort function that would detect the problem. In other words, the test should fail if smaller used < instead of <=.
The code written in the videos above is available for your reference. To download it, don’t use “Save Page As” or “Save As”; use “Save Link As” or “Download Linked File” in your Web browser. If you can’t find the command, try right-clicking or two-finger-tapping or long-pressing.