Willie wrote:
I am trying to get an inner class IntNode to encapsulate the nodes of
the linked list with the outer class having having a simple integer
value for data storage. So far I just can't see how this becomes
useful as with my current implementation it is just a pain to declare
everything. There must be a better way or at least there must be a
great pay off in some situations to go through this information as to
either would be of great help thanks.
William
In a simple linked list, there is no need to have separate classes
for data and for links. Templates are very useful when you don't
know the data type or for having an algorithm or class work with
any data type.
template<class Data_Type>
struct Node
{
Data_Type data;
Node * next;
};
If you want to get complicated:
template<class Data_Type>
struct Double_Link_Node
: public Node<Data_Type>
{
Node<Data_Type> * previous;
};
Although for a doubly linked list, I would just put both link
fields in the same structure.
If this is not for homework, try the STL std::list<> container.
It is already written and tested.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq:
http://www.parashift.com/c++-faq-lite
C Faq:
http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library