Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > nested loop use example

Reply
Thread Tools

nested loop use example

 
 
Willie
Guest
Posts: n/a
 
      11-01-2003
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
 
Reply With Quote
 
 
 
 
Thomas Matthews
Guest
Posts: n/a
 
      11-01-2003
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
Looking for simple nested gridview example ThatsIT.net.au ASP .Net 3 10-12-2007 01:33 PM
how to use recursive structure to build arbitrary levels' nested loop? so.intech C Programming 4 08-08-2006 11:09 PM
Compiler error with nested templates (simple example included) David Williams C++ 2 11-29-2005 09:34 PM
'example.com' == 'example.com.' => false... is this intended? Sam Roberts Ruby 15 02-07-2005 04:36 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57