Linked lists in C/C++



 DEVELOP > c-Plus-Plus > Linked lists in C/C++

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "hana1"
Date: 17 Jan 2005 12:43:36 AM
Object: Linked lists in C/C++
Hello guys,
I just have a quick question about C++. I am moving from Java to C++. And as
many of Java users know, all linked list and trees are already implemented
and you just have to instantiate them. Is tehre a simiar thing in c++, or I
have to write my own Linked list class?
Thank you very much
Cheers
.

User: "Gernot Frisch"

Title: Re: Linked lists in C/C++ 18 Jan 2005 02:36:32 AM
"hana1" <hana1@rogers.com> schrieb im Newsbeitrag
news:Y4-dnTIDRqv_qXbcRVn-pA@rogers.com...

Hello guys,
I just have a quick question about C++. I am moving from Java to
C++. And as many of Java users know, all linked list and trees are
already implemented and you just have to instantiate them. Is tehre
a simiar thing in c++, or I have to write my own Linked list class?

Thank you very much
Cheers

If you need trees, you can use something like:
namespace std
{
template <class Alloc> class tree : public Alloc
{
public:
Alloc& childs() {return m_Childs;}
const Alloc& childs() const {return m_Childs;}
private:
Alloc m_Childs;
};
}
std::tree< std::map<std::string, std::string> > MyTree;
.
User: "Alf P. Steinbach"

Title: Re: Linked lists in C/C++ 18 Jan 2005 03:18:32 AM
* Gernot Frisch:


If you need trees, you can use something like:

namespace std
{
template <class Alloc> class tree : public Alloc

The standard forbids placing anything new in namespace 'std'.
It's only used as a non-portable hack for tweaking certain compilers
into standard-conformance.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
.
User: "Gernot Frisch"

Title: Re: Linked lists in C/C++ 18 Jan 2005 07:44:41 AM
"Alf P. Steinbach" <alfps@start.no> schrieb im Newsbeitrag
news:41ecd415.878911312@news.individual.net...

* Gernot Frisch:


If you need trees, you can use something like:

namespace std
{
template <class Alloc> class tree : public Alloc


The standard forbids placing anything new in namespace 'std'.

It's only used as a non-portable hack for tweaking certain compilers
into standard-conformance.

Sorry, didn't know that.
-Gernot
.

User: "Jerry Coffin"

Title: Re: Linked lists in C/C++ 18 Jan 2005 09:18:47 AM
[ ... ]

The standard forbids placing anything new in namespace 'std'.

This is is simply not true at all. See $17.4.3.1 of the standard for
the details, but the bottom line is that while there are restrictions,
it's entirely legitimate to add some things to namespace std.

It's only used as a non-portable hack for tweaking certain compilers
into standard-conformance.

That's not true either -- the permissions are there in the standard
because some things really can't be done any other way.
--
Later,
Jerry.
The universe is a figment of its own imagination.
.
User: "Alf P. Steinbach"

Title: Re: Linked lists in C/C++ 18 Jan 2005 09:52:17 AM
* Jerry Coffin:

[ ... ]

The standard forbids placing anything new in namespace 'std'.


This is is simply not true at all. See $17.4.3.1 of the standard for
the details, but the bottom line is that while there are restrictions,
it's entirely legitimate to add some things to namespace std.

The some things can not be new things, only specializations of existing
standard templates. std::tree, the class under discussion, is an
entirely new thing, and the effect of adding it to namespace std is
Undefined Behavior. In other words, you're wrong; what you write is
simply not true at all (under any sensible interpretation). ;-)

It's only used as a non-portable hack for tweaking certain compilers
into standard-conformance.


That's not true either -- the permissions are there in the standard
because some things really can't be done any other way.

It is not permitted to place anything new in namespace std. At most
you can place specializations of existing standard template classes.
So what you write here is not true either, sorry.
Cheers,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
.
User: "Jerry Coffin"

Title: Re: Linked lists in C/C++ 18 Jan 2005 01:07:09 PM
[ ... ]

The some things can not be new things, only specializations of

existing

standard templates. std::tree, the class under discussion, is an
entirely new thing, and the effect of adding it to namespace std is
Undefined Behavior. In other words, you're wrong; what you write is
simply not true at all (under any sensible interpretation). ;-)

So by your interpretation, it's sensible to call a new specialization,
"not new"?
--
Later,
Jerry.
The universe is a figment of its own imagination.
.
User: "Alf P. Steinbach"

Title: Re: Linked lists in C/C++ 18 Jan 2005 07:11:16 PM
* Jerry Coffin:

[ ... ]

The some things can not be new things, only specializations of

existing

standard templates. std::tree, the class under discussion, is an
entirely new thing, and the effect of adding it to namespace std is
Undefined Behavior. In other words, you're wrong; what you write is
simply not true at all (under any sensible interpretation). ;-)


So by your interpretation, it's sensible to call a new specialization,
"not new"?

What we have here is not a specialization, it's a derived class.
I don't think it's sensible to call a specialization "new" except in the
time sense perhaps.
And of course the rules of the language are not concerned with when
something was made (classes derived from std::youghurt must have been
originally created no earlier than january 2005) -- so in this context
the pure time sense of "new" seems to be ruled out.
Cheers, again,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
.






User: "Jonathan Bartlett"

Title: Re: Linked lists in C/C++ 17 Jan 2005 09:39:00 AM

I just have a quick question about C++. I am moving from Java to C++. And as
many of Java users know, all linked list and trees are already implemented
and you just have to instantiate them. Is tehre a simiar thing in c++, or I
have to write my own Linked list class?

In C++ the STL defines list (a doubly-linked list) and slist (a
singly-linked list). See here:
http://www.sgi.com/tech/stl/List.html
http://www.sgi.com/tech/stl/Slist.html
One thing, though, is that C/C++ only support homogenous lists -- i.e.
only one data type in each list, unless you are storing pointers instead
of values.
However, you can do more advanced type of stuff if you write your own,
like sharing list nodes and other fun stuff. See my article on linked
lists here:
http://www.ibm.com/developerworks/linux/library/l-listproc/
Also, coming from Java, if you decide that you miss garbage collection,
you can always add it back using the Boehm garbage collector.
http://www.hpl.hp.com/personal/Hans_Boehm/gc/
Jon
----
Learn to program using Linux assembly language
http://www.cafeshops.com/bartlettpublish.8640017
.
User: "Mike Wahler"

Title: Re: Linked lists in C/C++ 17 Jan 2005 12:08:18 PM
"Jonathan Bartlett" <johnnyb@eskimo.com> wrote in message
news:41ebeaa7@news.tulsaconnect.com...

I just have a quick question about C++. I am moving from Java to C++.

And as

many of Java users know, all linked list and trees are already

implemented

and you just have to instantiate them. Is tehre a simiar thing in c++,

or I

have to write my own Linked list class?


In C++ the STL defines list (a doubly-linked list) and slist (a
singly-linked list).

'slist' is not a standard container.

See here:

http://www.sgi.com/tech/stl/List.html
http://www.sgi.com/tech/stl/Slist.html

One thing, though, is that C/C++ only support homogenous lists -- i.e.
only one data type in each list, unless you are storing pointers instead
of values.

And those pointers all have the same type -- still homogenous.
-Mike
.


User: "red floyd"

Title: Re: Linked lists in C/C++ 16 Jan 2005 09:55:21 PM
hana1 wrote:

Hello guys,
I just have a quick question about C++. I am moving from Java to C++. And as
many of Java users know, all linked list and trees are already implemented
and you just have to instantiate them. Is tehre a simiar thing in c++, or I
have to write my own Linked list class?

Thank you very much
Cheers

The Standard Library has many containers, including vectors, deques,
lists, sets, and maps. I'm not sure if there's a stock "tree" class
(though sets and maps tend to be implemented as a red/black tree).
Get a copy of Josuttis' "The C++ Standard Library". Also, get
Koenig&Moo's "Accelerated C++".
.

User: "Gianni Mariani"

Title: Re: Linked lists in C/C++ 16 Jan 2005 11:30:15 PM
hana1 wrote:

Hello guys,
I just have a quick question about C++. I am moving from Java to C++. And as
many of Java users know, all linked list and trees are already implemented
and you just have to instantiate them. Is tehre a simiar thing in c++, or I
have to write my own Linked list class?

Just to add to Red's note, there are a number of web sites that have
documentation.
Even though it's a little out of date, I still find it the most useful
on-line reference:
http://www.sgi.com/tech/stl/
There are plenty of others :
http://www.codeproject.com/vcpp/stl/stlintroduction.asp
Many on-line examples have a ".h" in the include file. These are wrong.
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER