0

I am having a homework that requires me to write a program that could store the data of persons(name,contact number,address) using linked-list. Templates must be used. How could I declare multiple type for the template? And how to store multiple data per node?

Tom Jones
  • 19
  • 5
  • 2
    This is probably what you need : http://stackoverflow.com/questions/11108207/c-linkedlist-using-template http://stackoverflow.com/questions/2079296/c-templates-linkedlist – Mehdi Karamosly Apr 24 '13 at 19:05

1 Answers1

1

You do not "declare" multiple types for templates; templates are there for multiple types. Just use it.

Multiple data can be stored in two ways: have the data embedded in your node, or have a pointer in your node that will point to the data.

The first way is easier; the second is probably the right way, but you will need to take into account the question who needs to allocate and free the data - whose ownership the data stored in the node is.

Elazar
  • 20,415
  • 4
  • 46
  • 67