Week 7: Exercises

1. Sort

Write a function

void sort<T>(T[] a)

that can sort an array. You may use any sorting algorithm that you like.

2. Frequent Words

Write a method

string[] topWords(string filename, int n)

that reads a file and returns an array of the n most frequent words in the file, listed in descending order of frequency. A word is any sequence of non-whitespace characters; comparisons are case-sensitive. If the file has fewer than n distinct words, return an array of all words in the file. Use the C# collection classes.