C++ Linked List or Hash Table

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

Post Reply
user_797
New Member
Posts: 1
Joined: Mon 17 Dec, 2007 12:00 pm

C++ Linked List or Hash Table

Post by user_797 »

I am not too experienced with the standard template library (STL) in C++. I am more experienced with Visual C++ and the Microsoft Foundation Class Library (MFC). I have heard some good things about STL. Is it ture that there is a ready-to-use linked list? Is there also a hash table?

What advantages would there be to writing one from scratch?

If I do go with MFC, what advantages are there?
User avatar
Halifax
Sir Posts-A-Lot
Posts: 225
Joined: Mon 01 Jan, 2007 10:39 am
Location: Pennsylvania, US

Post by Halifax »

Yeah, I would just go with writing your own:

* it isn't hard
* you will learn a very important data structure
* is practice ever bad?
* you will be able to handle every aspect of it
* no limitations
etc.
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

Reinventing the wheel is a bad thing. Writing your own containers is fine as an academic exercise, but once done delete the source files and use the standard ones instead. ;) If the STL doesn't offer what you need, turn to another standard-ish library like Boost.

(See here for an example).
user_797
New Member
Posts: 1
Joined: Mon 17 Dec, 2007 12:00 pm

Post by user_797 »

OK, I am going to use the STL list. I want to have each node have two strings. Here is how far I have gotten:

Code: Select all

#include <list> // list class-template definition

using namespace std; 

class Node
{
   CString string1;
   CString string2;
}



list<Node> MyList; 
I would I put nodes into this list?
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

list::push_back will append an item to the end of the list (for example).
User avatar
Halifax
Sir Posts-A-Lot
Posts: 225
Joined: Mon 01 Jan, 2007 10:39 am
Location: Pennsylvania, US

Post by Halifax »

Reinventing the wheel is the essence of learning. To use things blindly is probably the stupidest thing you could ever due, and reinventing the wheel generally leads to a better understanding of what is happening.

Maybe reinventing the wheel is a bad thing for linked lists, but sometimes it is needed, and it is better for the community. (Gives more choice.)

For one example you have:

CryEngine2, UE3, Irrlicht, NeoAxis, Ogre, Horde3d, etc.
CoBB
MCF Legend
Posts: 1601
Joined: Mon 20 Dec, 2004 8:45 am
Location: Budapest, Absurdistan
Contact:

Post by CoBB »

Reinventing the wheel is wrong if you want to put it on your car. On the other hand, there’s nothing wrong with playing around with new wheel designs as long as they don’t leave your garage before thorough testing. ;)

Studying existing wheels is a very useful way of spending your time, and part of the learning process is indeed creating some of your own. However, there’s no reason to use your own design in production as long as it is inferior to the widespread one. And when you are experimenting with chassis designs, you’ll surely want to take ready-made wheels in order to concentrate your efforts better.

Stupid analogy trip over. :P
User avatar
Halifax
Sir Posts-A-Lot
Posts: 225
Joined: Mon 01 Jan, 2007 10:39 am
Location: Pennsylvania, US

Post by Halifax »

Yes, CoBB, thanks for summing it up. I agree with that.
Post Reply