Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Singly-linked list

Status
Not open for further replies.

samsa

Instructor
Aug 12, 2003
6
CA
Should a singly-linked list class use a node class (containing, e.g., a next pointer and "int data"), or can I get by without one?
 
Well Samsa,

The answer to it would be situational! If the node class is too big, better cascade it (wrapping). You can always have the complete thing in one class. In this case, there would be a pointer (may be *next) that would be of its own type.

class linked_list;

class linked_list
{
int int_data;
char str[20];
linked_list *next;
public:
<<your_methods>>
};

have fun linking...;-)

Roy.
user.gif
 
Hey, Roy -
Thanks for the help. Btw, I noticed that you included an array of 20 char's as possible data to be linked, in addition to integers. I've seen this kind of thing elsewhere (&quot;linking strings of 20 or fewer characters&quot;, etc.). Is this a standard? Do linked lists ever hold string of more than 20 characters? Why did you choose 20? Is that a convenction? Is it also a convention to concatenate (hook-up) char's as an array?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top