views:

317

answers:

5

Is there a linked list in C++ that I could just #include? Or do I need to create my own if I want to use one?

+5  A: 
#include <list>
Idan K
+2  A: 

STL List

Traveling Tech Guy
+2  A: 

In c++ we have the STL, Standard Template Libraries which do contain a a lot of implemantations of popular algorithms like stacks, queues, linked lists and poular searching and sorting algorithms even.....

As already told by daniel you can include it by #include< list>

manugupt1
+10  A: 

As daniel notes, yes, std::list. Usage would be:

#include <list>
// ...
std::list<int> listOfInts;
listOfInts.push_back(1);
// ...

And so on.

You can find a complete list of STL classes here. The section you're after is 3.2, Container classes. Another useful reference of the C++ Standard Library is here.

GMan
thanks......................
This is a double linked list, which allows for Bidirectional traversal, the SGI STL (and some others) also define single linked lists, see http://www.sgi.com/tech/stl/Slist.html for example.
Matthieu M.
A: 
Hostile Fork
Recommending not using language features...hm.
GMan
No, I recommend developing an awareness of alternatives (especially when those alternatives are used in practice by many professional C++ programmers).
Hostile Fork