I got a list of items to program in Visual C++.

I could write a linked list from scratch but I want to do something special and best. I am thinking about a hash table.

What is best, linked lists or hash tables?

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?

> What is best, linked lists or hash tables?
depends on what your requirement is. a list is a sequence container, used to keep a collection of elements. hash tables are associative containers, used for keeping a collection of key-value pairs with support for lookup on key.

> Is it ture that there is a ready-to-use linked list? Is there also a hash table?
there is a list implementation std::list<>
c++0x has a hash table, c++98 does not. but there is an implementation of an associative array std::map<> which would give you the same functionality.

> What advantages would there be to writing one from scratch?
you could learn quite a lot from the effort

> If I do go with MFC, what advantages are there?
support for ui programming in windows. everything else would be a disadvantage.
MFC and the standard c++ library are not mutually exclusive. look to MFC only if an equivalent facility is not available in the standard c++ library.

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:

#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?

> OK, I am going to use the STL list.
unless insertion or removal of elements from the middle of the sequence are a requirement, or you need very strong guarantees in the presence of exceptions, a list is not the ideal data structure (efficiency, random access). if this is not the case, consider using a std::vector<> ( or if you need to insert or remove elements from either end of the sequence ) a std::deque<>

> I want to have each node have two strings
a. if you do not need to pass these strings to MFC functions, use std::string instread of CString
b. if you require just two member variables in a structure, you could use the ready made std::pair<>

std::vector< std::pair<CString,CString> > MyList ;

> I would I put nodes into this list?
i did not realize on first reading that this might mean 'How would I put nodes into this list? '
standard library sequence containers provide the method push_back to add an element to the back of the sequence. there are also methods like insert, resize etc.

to add an element of type std::pair<CString,CString> to the back of a vector/deque/list

template< typename container > inline 
void foo( container& cntr, const CString& a, const CString& b )
{ cntr.push_back( std::make_pair(a,b) ) ; }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.