PLC: Assignment #1 (Sample Solution)

This is a sample solution in Java for the first assignment:

Please feel free to notify me if you think that you have a better solution or one that is particularly interesting. I might publish it as well along with my comments.

And here is finally even a sample solution for C++. Warning: This is fairly challenging as a simple template class doesn't do the trick because the List template class and the Element class are both valid elements of a list but they are not compatible to each other. The simplest fix would be to make the List template class an extension of Element but this is bad as there is no real is-a relationship between List and Element. Instead, a nested class Cell is declared which can hold either a List or an Element. Thanks to its constructors and its conversion operators all conversions are done automatically by C++. Enjoy...

However, if you come up with something that is simpler and does not violate OO principles, I would be glad to see it.


Andreas F. Borchert, March 18, 2002