2 Replies - 2896 Views - Last Post: 15 November 2007 - 05:54 PM Rate Topic: -----

#1 complete  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 104
  • Joined: 12-April 07

What is best, linked lists or hash tables?

Post icon  Posted 14 November 2007 - 09:08 PM

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?

Is This A Good Question/Topic? 0
  • +

Replies To: What is best, linked lists or hash tables?

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4364
  • View blog
  • Posts: 12,182
  • Joined: 18-April 07

Re: What is best, linked lists or hash tables?

Posted 14 November 2007 - 11:31 PM

Wow, a lot of questions here. So I guess I should get to work...

1) Which is better? As always it depends. Do remember though that they are slightly different. Hash tables are great for quick in memory indexing of values using a key. The keys are hashed and they are great for quickly accessing elements and one great use of them is for eliminating doubles from a list of values. Since a value is hashed to one key, any doubles overwrite the same spot thus eliminating them.

Linked lists are nodes which point to other nodes to form chains. They are great because they can often be used to chain big objects together using pointers, and you can usually take out a node from the chain quickly and efficiently. They are wonderful for theoretical search trees, binary trees etc.

2) Yes, STL has a list template class which takes advantage of a double-linked list. It also has a map which is similar to hash_map in functionality.

3) Advantages to writing it from scratch... you learn how they work, you can increase the functionality to your own specifications, how can leave out functionality if need be, you can control memory and resource usage based on how you chose to implement it.

4) Advantages to using MFC taken from MSDN...

MFC is the easiest way for you to achieve two kinds of portability:

* Portability among different operating systems
* Portability among different processors

MFC is designed to wrap your C/C++ applications to work on almost any operating system with little or no modification, including 32-bit Windows and UNIX if a UNIX MFC library is present. MFC is also designed to be completely portable among different processors.

Hope these questions help you out.

Enjoy!

"At DIC we be multi-question answering code ninjas!" :snap:
Was This Post Helpful? 0
  • +
  • -

#3 complete  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 104
  • Joined: 12-April 07

Re: What is best, linked lists or hash tables?

Posted 15 November 2007 - 05:54 PM

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?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1