Solved

Linked list of what?

Posted on 2000-02-17
12
214 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
Comment Utility
>> 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
Comment Utility
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
Comment Utility
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
 
LVL 3

Author Comment

by:sumant032199
Comment Utility
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
Comment Utility
>> 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
Comment Utility
Books.

struct list
{
      struct list *prev;
      .      
      .      
      struct list *next;
};
class linked_list
{
   private:        
          struct list *head;
   public:
                .
                .
                .
   
}LIST;
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 22

Expert Comment

by:nietod
Comment Utility
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
Comment Utility
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
Comment Utility
Yes, that is true.  But now I'm not sure what the question is.
0
 
LVL 3

Author Comment

by:sumant032199
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now