Starting from:

$25

PL Assignment 4- Write a Haskell function maxlist Solved

1.      Write a Haskell function maxlist lt that computes the maximum element of list lt (Assume that the list lt contains at least one element).

E.g. maxlist [3,1,6,4,2,3] = 6   //the maximum element in the list is 6

 

2.    Write a Haskell function delete k lt that removes every kth element of a list lt.

E.g. delete 2 [3,4,5,6,7,8,9]  //remove the 2nd, 4th, and 6th element

           [3,5,7,9]

 

3.     Write a Haskell function isort lt that sorts an integer list lt into ascending order using the insertion sort. E.g. isort [7,3,9,2] = [2,3,7,9]

 

4.     Write a Haskell function rotate n lt that rotates a list lt n places to the right.  Assume that lt contains at least n elements.

E.g. rotate 3 [1,2,3,4,5,6,7] = [5,6,7,1,2,3,4]  // rotate the list 3 places to the right

 

5.   Write a Haskell function single lt that changes a list lt into a list of lists by making each element into a singleton list.

E.g. .  single [1,2,3,4]  = [[1],[2],[3],[4]]  

 

6.                  [15 points] Write a Haskell function double lt that doubles every element appearing the odd positions of lt.

    e.g. double [1,3,4,5] = [2,3,8,5]  //double 1 and 4

More products