Comparison Exercise: List<>

The goal for this exercise is to practicing using the List<> class by implementing a solution to a small programming problem.

 

Note that in order to pass the NUnit tests, each value (each integer) should be printed out on its own line, with nothing else (not even blank spaces) on that line.  The values should be printed out in order, so that the smallest value is printed first and the largest value is printed last.

 Short version: use List<>, unless you have a good reason not to

Some examples of a good reason:

You need to call a method that returns an array or requires an array as a parameter

Windows.readImageFromFile returns a 2D array

Find other methods?

Lower-level work (OS’s often use arrays – network interfaces, images, etc)

Network response?

Arrays perform better - First write the program with List<>, then switch to array only if you need the perf benefit

You wrote the program using a List<>, and that List<> is the core of your program.  You use it a million times a second, and you'd like to increase the performance (increase the 'speed', reduce the time taken to compute, etc) of your program.

Arrays are good when you know you have a fixed-length storage need

read a file - each line has exactly 3 items (x, y, temperature)

Arrays are good for 2D storage (particularly dense/packed storage)

need to store a 2D image in memory

need to store a 2D matrix in memory

need to store a 3D or 4D matrix in memory (still arrays!)

 List<> is easier to use, and has more features.

What should you use 'by default'?

 What you need to do for this exercise: 

  1. In the provided starter solution, in a project named something like 03_PCE_StudentCode, in the Student_Answers.cs file, there is a class named BinarySearchTreeFor this exercise, you should implement the ‘Print’ method using recursion.

    This method MUST be implemented using Recursion.  You will get no points for a solution that does not use a recursive approach to solve this problem.