[Cs3] Lab3
Mikhail Nesterenko
mikhail at cs.kent.edu
Tue Jun 23 15:40:56 EDT 2015
> Struggling with Lab3 premise somewhat. A list is just pointers and nodes.
> In the example you are creating a char list with dynamic nodes (for loop in
> main()). Are you saying that when I create an object of type Collection I
> just need to automatically create dynamic nodes of template type? By this
> I mean my Collection constructor just makes a dynamic node of template type
> and the addItem() method just makes another dynamic node of template type,
> sets the passed value of type and adjusts the pointers as necessary. In
> other words, emulating the creating list for loop from the example? So
> addItem(7) would dynamically add a node of type integer, set the data_
> member to 7 and adjust the pointers so that this node becomes the last
> linked node in the list. Sorry and I hope this makes sense.
The templated list is already there. Now you need to create an class
Collection that has this list as a dynamically allocated
member. Collection has to be templated as well. And the type parameter
is what the list is going to carry as payload. For the class
Collection you have to implement two member functions
* addItem() that takes the parameter of the parameterized type and
adds it to the list. That is, the signature of addItem() would be
addItem(T); // if parameter to be added to list is passed by value
or
addItem(const T&); // if parameter is passed by const reference
* printCollection() that prints the contents of the list.
Thanks,
--
Mikhail
More information about the cs3
mailing list