Eliminate Unsorted Assignment

From CSE425S Wiki
Jump to navigation Jump to search

follows Remove First

Code to Implement

file: src/main/sml/warmup_eliminate_unsorted/eliminate_unsorted.sml Smlnj-logo.png
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.

SML Error Messages