C++ Linked List or Hash Table

Complete

OSNN Addict
Joined
25 Aug 2005
Messages
94
In the C++ Standard Template Library (STL) is there a ready-to-use Hash Table? If not, is there a good linked list?

What advantages are there to me writing one fron scratch? What about using one of the MFC classes?
 
std::list is a linked list. Doubly linked.

As for hash table, how are you planning on using this structure? Show us some usage scenario's and maybe we can suggest something that will work well.
 
The STL doesn't include a hash table implementation. It does include a doubly linked list though - see list.

Advantages over writing from scratch? It'll save you development time. :) The STL data structures are also well-tested and widely used, so you can be reasonably sure that there aren't any major bugs in their implementations.
 
std::list is a linked list. Doubly linked.

As for hash table, how are you planning on using this structure? Show us some usage scenario's and maybe we can suggest something that will work well.

I think I will keep it as simple as possible.
But using STL is brand new to me.

I want to use nodes with two strings.

This is all I have thus far:

Code:
#include <list> // list class-template definition
using namespace std; 
class Node
{
   CString string1;
   CString string2;
}
 
list<Node> MyList;

Now, how would one add a new node and "push" it into the list?
 
NetRyder: the STL implementation from SGI does include an hash_map:

http://www.sgi.com/tech/stl/hash_map.html

However it is not included in all of the current compilers available. Which is why I was requesting more info.

However, if you need something that functions a lot like that, and it has to be standard C++, check out http://www.sgi.com/tech/stl/Map.html
Yeah, I was aware of the SGI hash_map, but didn't want to suggest something that's not included by default. And yes, a map or multi_map would work well if you need to store key-value pairs.
 
This is all I have thus far:

Code:
#include <list> // list class-template definition
using namespace std; 
class Node
{
   CString string1;
   CString string2;
}
 
list<Node> MyList;
Now, how would one add a new node and "push" it into the list?
You would then create an instance of Node and pass it in as an argument to MyList.push_front() or MyList.push_back(), depending on whether you want the node to be added to the head or tail end of the list.
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back