Read Heterogenous Linklist

While creating a heterogenous linklist we know that we use void pointer. But when we need to read the information, How will you do it? How will you figure out to what datatype does the data belong to?

Questions by unconquerable

Showing Answers 1 - 3 of 3 Answers

Sereche

  • Jul 8th, 2012
 

Some kind of information regarding the type is obviously required. If there is no way of determining it from the context (i.e., the previous node in the list somehow specifies the type), it must be stored prior to the actual data.

For example, you may include an integer with pre-defined values specifying a type (i.e. 0 is a 32-bit integer, 1 is a string, etc.), then store the data. Alternatively, the node could contain a pointer to data, instead of storing the data internally. The former is more efficient, but also a little more difficult to implement.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions