473,509 Members | 2,912 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jul 22 '05 #1
11 2064
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++".

Jul 22 '05 #2
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.
Jul 22 '05 #3
> 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/li...ry/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
Jul 22 '05 #4

"Jonathan Bartlett" <jo*****@eskimo.com> wrote in message
news:41******@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
Jul 22 '05 #5

"hana1" <ha***@rogers.com> schrieb im Newsbeitrag
news:Y4********************@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;

Jul 22 '05 #6
* 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?
Jul 22 '05 #7

"Alf P. Steinbach" <al***@start.no> schrieb im Newsbeitrag
news:41****************@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
Jul 22 '05 #8
[ ... ]
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.

Jul 22 '05 #9
* 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?
Jul 22 '05 #10
[ ... ]
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.

Jul 22 '05 #11
* 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?
Jul 22 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4806
by: Chris Ritchey | last post by:
Hmmm I might scare people away from this one just by the title, or draw people in with a chalange :) I'm writting this program in c++, however I'm using char* instead of the string class, I am...
10
15099
by: Kent | last post by:
Hi! I want to store data (of enemys in a game) as a linked list, each node will look something like the following: struct node { double x,y; // x and y position coordinates struct enemy...
1
12825
by: Booser | last post by:
// Merge sort using circular linked list // By Jason Hall <booser108@yahoo.com> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> //#define debug
12
2492
by: Jonathan Bartlett | last post by:
Just finished a new IBM DeveloperWorks article on linked lists, and thought you all might be interested. It's not an introduction -- it instead covers some of the more interesting aspects of...
3
3257
by: s_subbarayan | last post by:
Dear all, 1)In one of our implementation for an application we are supposed to collate two linked lists.The actual problem is like this: There are two singularly linked lists, the final output...
4
3585
by: MJ | last post by:
Hi I have written a prog for reversing a linked list I have used globle pointer Can any one tell me how I can modify this prog so that I dont have to use extra pointer Head1. When I reverse a LL...
3
472
by: Little | last post by:
Could someone tell me what I am doing wrong here about declaring mutiple double linked lists. This is what the information is for the project and the code wil be below that. Thank your soo much for...
12
3928
by: joshd | last post by:
Hello, Im sorry if this question has been asked before, but I did search before posting and couldnt find an answer to my problem. I have two classes each with corresponding linked lists, list1...
19
7800
by: Dongsheng Ruan | last post by:
with a cell class like this: #!/usr/bin/python import sys class Cell: def __init__( self, data, next=None ): self.data = data
51
8566
by: Joerg Schoen | last post by:
Hi folks! Everyone knows how to sort arrays (e. g. quicksort, heapsort etc.) For linked lists, mergesort is the typical choice. While I was looking for a optimized implementation of mergesort...
0
7234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7412
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4730
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
441
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.