Computer programming - Lab 13

For problems 1 to 3, define a structure type which holds a pair of two lists.

1. Implement a function that takes a list (e.g. of integers) and an unsigned length len, and returns a pair of two lists: the list of the first len elements, and the list of any remaining ones. Return the pair of empty lists if len exceeds the length of the list.

2. Implement a function that takes a list and an element (e.g. integer), and returns a pair of two lists: the prefix before the first occurrence of the element, and the tail, after that occurrence. Return the pair of empty lists if the element is not found.

3. Implement a function that takes a list of integers and a function f from int to int and returns a pair of two lists: the list of those elements for which f is true (nonzero), and the list of the elements for which f is false (zero).

4. Implement a datastructure for lists of integer lists. Use it to store integers read until end of input (separated by whitespace), each input line resulting in a list.

5. Write a function that takes two sorted lists of integers and produces a merged lists of all integers in reverse order.
Write a function that takes a list of integers and splits it into two lists of (almost) equal size
Combine the two functions recursively to sort a list of integers (the procedure is called mergesort)

6. Implement and test a library for sets of bounded unsigned integers, using one bit per element. The maximum bound for a set element is given at set creation time.

Marius Minea
Last modified: Thu Dec 19 8:30:00 EET 2013