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?
 

X-Istence

*
Political Access
Joined
5 Dec 2001
Messages
6,498
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.
 

NetRyder

Tech Junkie
Joined
19 Apr 2002
Messages
13,256
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.
 

Complete

OSNN Addict
Joined
25 Aug 2005
Messages
94
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

Tech Junkie
Joined
19 Apr 2002
Messages
13,256
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.
 

NetRyder

Tech Junkie
Joined
19 Apr 2002
Messages
13,256
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

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.
Terrahertz wrote on Electronic Punk's profile.
Yo fellas!
Electronic Punk wrote on Sazar's profile.
Where are you buddy?
Perris Calderon wrote on Electronic Punk's profile.
Hey EP! All good with me, applying for Microsoft MVP right now, should have done this a while ago.

Notifications don't work, I only found your response by coming back to hunt up some threads, if you want, give me your email address so we can keep in touch easier!
Perris Calderon wrote on Electronic Punk's profile.
EP, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there!

Forum statistics

Threads
61,997
Messages
673,411
Members
5,591
Latest member
nodee