Solved

Linked list of what?

Posted on 2000-02-17
12
218 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
  • 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

809 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