Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

F# Programming: Write an F# program lengthsort to sort a list of lists according the lengths of the element lists such that short lists first,

F# Programming:

Write an F# program lengthsort to sort a list of lists according the lengths of the element lists such that short lists first, longer lists later.

> lengthsort [[2;3];[1;2;3;4];[1;2;4;5;6];[2;3;4];[3]];; val it : int list list =

[[3]; [2; 3]; [2; 3; 4]; [1; 2; 3; 4]; [1; 2; 4; 5; 6]]

Hint: Use List.map to construct a tuple list from the given list such that the first element is the length of the element list, e.g [[2;3];[1;2;3;4];[1;2;4;5;6];[2;3;4];[3]] becomes [(2,[2;3]);(4,[1;2;3;4]);(5,[1;2;4;5;6]);(3,[2;3;4]);(1,[3])]. Write a function to sort the list based on the 1st element of the tuple, and then drop the 1st element in the tuples to obtain the final result.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions

Question

What is NoInformation rate?

Answered: 1 week ago