Haskell — Sorting

Implement some algorithms to sort lists.

  1. Define a function insert :: [Int] -> Int -> [Int] that, given a sorted list and an element, correctly inserts the new element in the list.

    Define a function isort :: [Int] -> [Int] that implements insertion sort using the previous function.

  2. Define a function remove :: [Int] -> Int -> [Int] that, given a list and an element xx, erases the first occurrence of xx from the list. You can assume that the element is always in the list.

    Define a function ssort :: [Int] -> [Int] that implements selection sort using the previous function.

  3. Define a function merge :: [Int] -> [Int] -> [Int] that, given two sorted lists, merges them to get a list with all the elements in sorted order.

    Define a function msort :: [Int] -> [Int] that implements merge sort using the previous function.

  4. Define a function qsort :: [Int] -> [Int] that implements quick sort.

  5. Generalize the previous function into genQsort :: Ord a => [a] -> [a] that sorts elements of any type.

Scoring

Each sorting algorithm scores 20 points.

Problem information

Author: Unknown
Translator: Jordi Petit

Generation: 2026-02-03T17:08:26.069Z

© Jutge.org, 2006–2026.
https://jutge.org