Solved

Linked list of what?

Posted on 2000-02-17
12
221 Views
Last Modified: 2013-12-14
I want to build a double,branched, linked list.
Now what should I use ?
A linked list of structures or linked of
objects(I mean classes), Or a linked list inside an object (whole linked list as a member of object)
I want some sugggestions on memory point of view also.
0
Comment
Question by:sumant032199
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
12 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 90 total points
ID: 2531767
>> A linked list of structures or linked of
>> objects(I mean classes),
Yes.

In C++ structures and classes are the same.  

I suppose what you mean is should the structures/classes have member functions for maintaining the list.  That is up to you and depends on your needs.  Like if this code needs to compatible with C, then no.  However, most likely you would be best of using member functions.

I guess I would say that if there is no good reason to not use member functions, then you should.

>> I want some sugggestions on
>> memory point of view also.
What does that even mean?
0
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2531771
When it comes to "struct" and "class" in c++ there isn't a great deal of difference apart from everything is by default public: in a struct and in a class its private:

Can you not make use of STL (Standard Template Library). It will no doubt have an implementation of a bi-directional linked list that you could use with very little effort.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2531810
the STL has the list<> template class whose interface functions in a way that strongly suggests that it be implimented as a doubley linked list.  However, how it is actually implimented is intirely up the the STL implimenter.  (Although I can't image anyone not using a linked list for it.)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:sumant032199
ID: 2536208
One advantage I see in using objects as nodes of linked list is that I can perform various operations on nodes using member functions. And I can hide data. But in some popular books they have produced whole linked list as a member of only one object.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2536259
>> One advantage I see in using objects as
>> nodes of linked list is that I can perform
>> various operations on
>> nodes using member functions
Yes, definitely.  

But it may depend on your needs.  If yo have ot maintain C compatiblity, you can't do that.  If the objects in the linked list are to be of claeses that were already defined and connot be changed (like from a commercial library) you can't do this.

>>  But in some popular books
>> they have produced
>> whole linked list as a member
>> of only one object
What does that mean?  
0
 
LVL 3

Author Comment

by:sumant032199
ID: 2537350
Books.

struct list
{
      struct list *prev;
      .      
      .      
      struct list *next;
};
class linked_list
{
   private:        
          struct list *head;
   public:
                .
                .
                .
   
}LIST;
0
 
LVL 22

Expert Comment

by:nietod
ID: 2538006
I'm not sure what you mean by "whole linked list as a member of only one object"

How can it be a member?  How can anythjng be a member of only one object?  That makes no sense.

What is that weird code?  I would hope you wouldn't find that in any book.  That is a terrible mix of OLD style C stuff and C++ stuff
0
 
LVL 3

Author Comment

by:sumant032199
ID: 2538491
What I mean is since, head is a pointer to linked list starting and it is also private hence only member function can access it hence therotically whole linked list is hidden. If one can get the value of head(address of first node) then whole linked list will be "open".

0
 
LVL 22

Expert Comment

by:nietod
ID: 2538529
Yes, that is true.  But now I'm not sure what the question is.
0
 
LVL 3

Author Comment

by:sumant032199
ID: 2539484
I think my this question is somewhat weird. I am asking obvious things. I will be more prepared in my next question. Anyway thnaks a lot.

At last, one request(out of discussion).
Will you nietod tell me various uses/applications of typedef? I know only which are in C. Just give me idea where it can be used; like pointer to a member function. If you wish, just brief them or give some syntax.
0
 
LVL 3

Author Comment

by:sumant032199
ID: 2539491
I think my this question is somewhat weird. I am asking obvious things. I will be more prepared in my next question. Anyway thnaks a lot.

At last, one request(out of discussion).
Will you nietod tell me various uses/applications of typedef? I know only which are in C. Just give me idea where it can be used; like pointer to a member function. If you wish, just brief them or give some syntax.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2539636
Traditionally in C a struct was not a "complete type" the name of the struct had to be preceeded by a "struct" keyword to serve as a data type.    In C++ that is not the case (and I blieve that is not the case in C anymore.)  so

struct SomeStructType
{
   int x;
};

SomeStructType Str;

See?  no need to declare a typedef because SomeStructType is a type.  Same is true for classes of course.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question