Difference between revisions of "Eliminate Unsorted Assignment"
Jump to navigation
Jump to search
Line 20: | Line 20: | ||
===Example [1, 1, 2, 3, 1, 3, 2, 4, 1, 3, 5, 1, 5, 0]=== | ===Example [1, 1, 2, 3, 1, 3, 2, 4, 1, 3, 5, 1, 5, 0]=== | ||
− | Ties are retained in the result. For example: | + | Ties are to be retained in the result. For example: |
eliminate_unsorted([1, 1, 2, 3, 1, 3, 2, 4, 1, 3, 5, 1, 5, 0]) | eliminate_unsorted([1, 1, 2, 3, 1, 3, 2, 4, 1, 3, 5, 1, 5, 0]) | ||
Line 27: | Line 27: | ||
[1, 1, 2, 3, 3, 4, 5, 5] | [1, 1, 2, 3, 3, 4, 5, 5] | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=Test= | =Test= | ||
{{SMLUnitTesting|run_eliminate_unsorted_testing|warmup_eliminate_unsorted}} | {{SMLUnitTesting|run_eliminate_unsorted_testing|warmup_eliminate_unsorted}} |
Revision as of 04:58, 5 September 2022
Contents
Code to Implement
file: | src/main/sml/warmup_eliminate_unsorted/eliminate_unsorted.sml | |
functions: | eliminate_unsorted |
eliminate_unsorted
Write a function
fun eliminate_unsorted(xs : int list) : int list
which produces a list of the already sorted items, eliminated any unsorted items.
Example [1, 6, 1, 8, 0, 3, 3, 9, 8, 8, 7]
For example:
eliminate_unsorted([1, 6, 1, 8, 0, 3, 3, 9, 8, 8, 7])
would produce:
[1, 6, 8, 9]
Example [1, 1, 2, 3, 1, 3, 2, 4, 1, 3, 5, 1, 5, 0]
Ties are to be retained in the result. For example:
eliminate_unsorted([1, 1, 2, 3, 1, 3, 2, 4, 1, 3, 5, 1, 5, 0])
would produce:
[1, 1, 2, 3, 3, 4, 5, 5]
Test
source folder: | src/test/sml/warmup_eliminate_unsorted |
how to run with CM.make verbosity off: | sml -Ccm.verbose=false run_eliminate_unsorted_testing.sml |
how to run with CM.make verbosity on: | sml run_eliminate_unsorted_testing.sml |
note: ensure that you have removed all printing to receive credit for any assignment.