Difference between revisions of "Eliminate Unsorted Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
(Created page with "=Code to Implement= {{SMLToImplement|eliminate_unsorted|eliminate_unsorted|warmup_eliminate_unsorted}} ==eliminate_unsorted== Write a function fun eliminate_unsorted(xs :...")
 
Line 19: Line 19:
 
  [1, 6, 8, 9]
 
  [1, 6, 8, 9]
  
===Example [131,231,425]===
+
===Example [1, 1, 2, 3, 1, 3, 2, 4, 1, 3, 5, 1, 5, 0]===
For example:
+
Ties are retained in the result.  For example:
  
  sum_scan([131,231,425])
+
  eliminate_unsorted([1, 1, 2, 3, 1, 3, 2, 4, 1, 3, 5, 1, 5, 0])
  
 
would produce:
 
would produce:
  
  [131, 362, 787]
+
  [1, 1, 2, 3, 3, 4, 5, 5]
  
 
:{| class="wikitable" style="text-align:right;"
 
:{| class="wikitable" style="text-align:right;"

Revision as of 04:57, 5 September 2022

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 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]
xs 131 231 425
sum_scan(xs) 131 362 787

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