AtomicChip
Programmer
Ok... This question may seem a little basic, but it's something that's been eating away at me for a little while...
When implementing a linked list, most tutorials on that interweb thing show a list's node structure something like the following:
Here's my question: If you were to implement a templated linked list, would you really want the data portion to be a copy of the data and not a pointer to it (the way some of the older C implementations used the void*)? So, something like this:
That way, when dealing with larger data structs, they would not be copied in memory?
I also realize that there may be scope issues with implementing it this way (i.e. the data value being deleted before the list is done with it).
Any thoughts? Suggestions?
Thanks.
-----------------------------------------------
"The night sky over the planet Krikkit is the least interesting sight in the entire universe."
-Hitch Hiker's Guide To The Galaxy
When implementing a linked list, most tutorials on that interweb thing show a list's node structure something like the following:
Code:
struct Node
{
int data;
Node * next;
Node * prev;
}
Here's my question: If you were to implement a templated linked list, would you really want the data portion to be a copy of the data and not a pointer to it (the way some of the older C implementations used the void*)? So, something like this:
Code:
template<typename T>
class List
{
//....
struct Node
{
T * data;
Node * next;
Node * prev;
}
}
That way, when dealing with larger data structs, they would not be copied in memory?
I also realize that there may be scope issues with implementing it this way (i.e. the data value being deleted before the list is done with it).
Any thoughts? Suggestions?
Thanks.
-----------------------------------------------
"The night sky over the planet Krikkit is the least interesting sight in the entire universe."
-Hitch Hiker's Guide To The Galaxy