← ppnm

Exercise "generic list"

Tasks

  1. Build a simple class that implements a generic list (a list that can hold items of any given type (all items must be of the same type though)). The list must be able to grow, that is, it must be possible to add items to the list.

    Basically only one method, "add", is needed. Something like

    Suppose you have an input file with a table of numbers separated by blanks and/or tabs, like this
    129.24 24.8             4.847
    		88.6   33.745 7.78
    30.39  99.811              6.723
        -1.33   96.3   2.23
    
    Create a Main function that reads such a table line by line from the standard input into a genlist<std::vector<double>> and then prints the numbers in the form of a neat table into standard output in exponential format. Something like

  2. (Extra) Implement "void remove(int i)" method that removes element number "i".

  3. (Extra) Improve the speed of the "add" method by increasing the capacity of the data-array not by one element, but instead by doubling it. That should decrease the amount of array copying significantly for the price of increased memory usage.

    
    

  4. (Extra) Implement generic list using a chain of nodes.