Re: [Dev-C++] my delete function in my linked list
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Jason H. <jas...@bt...> - 2001-11-10 02:26:03
|
The main reason was to avoid the use of *&, I personally believe that =
using reference to a pointer, in main(), is a bad way of doing things. =
Using a container (I believe) is representative of better design, =
although it does look silly in the case of it containing only one =
member. I find it easier to deal with the list that way, and by using =
abstraction and such you can help avoid coding errors. Of course if I =
was using C++ I would create a linked list object and have methods to =
work upon the container.
You could create a global pointer for the list, and by putting it in =
'list' namespace you can avoid exposing it to global scope. I can't =
remember the exact best way of doing it this way off the top of my head =
though. What is currently being done is OK for demonstrating the use of =
a linked list, but what I have mentioned is more applicable for an =
implementation you are more likely to use in a real world application.
I don't use references much myself so I don't know much about thier =
syntax. Something I did read in Stroustrup was that you should avoid =
modifying values passed as arguments and instead use return values, =
because the user may not be aware that you have modified a value they =
passed.
In the end the choice is yours, so use what you want. It may be helpful =
to be aware of the alternatives. My explanation might not be very good =
as I'm having trouble trying to explain what I feel is right. I tend to =
rely on intuition a bit when deciding on how to go about a piece of =
code. Ask your teacher and see what he/she thinks about it?
In the end this is all over the top for what is needed so just ignore =
me. ;)
Jason.
----- Original Message -----=20
From: Jason Silverman=20
To: dev...@li...=20
Sent: Saturday, November 10, 2001 1:43 AM
Subject: Re: [Dev-C++] my delete function in my linked list
Hey everyone,
Why would you use a struct like that over just using a pointer =
like he has?
I've just been taught linked lists recently in school, have a test =
monday on them actually...but I don't see the advantage of using the =
struct over the pointer if you are only going to keep the start pointer. =
Of course like you said, if you want an end pointer or the size of the =
struct...
As well, I was taught *& too, p is before r in the alphabet was =
the little way to remember it.
Jay
----- Original Message -----=20
From: Jason Hardman=20
To: Dev-C++=20
Sent: Friday, November 09, 2001 8:20 PM
Subject: Re: [Dev-C++] my delete function in my linked list
I'm a bit confused by your use of *&list in the arguments. I assume =
you you
want a reference to the list pointer so you can modify it, but I =
would have
thought that the correct notation would be &*list, or maybe =
&(*list)? I
don't have any experience in doing that as it is probably a bad way =
of
programming (no offence). Usualy when creating a list you put it in =
a
container, i.e.
struct list
{
node *start;
};
You can then pass a pointer to the list struct and the fuctions will =
operate
on it's start member. In some lists you can also keep a pointer to =
the end,
or maintain number for the size of the list. I bet you are doing =
this for a
lesson, otherwise it would be easier to use the C++ STL container =
list.
|