CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2006
    Posts
    1

    Data Structure with 3 keys

    Hello,

    I am looking for a data structure to help me with the following:

    Given either city, state or zip, I need to be able to get a value or list of values of the other.

    So I want to store city, state and zip info in a data structure. Then if I get any one of the values, I want access to the other two.

    What kind of data structure can I use?

    Thanks,
    T.

  2. #2
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Data Structure with 3 keys

    A simple data structure would be:
    Code:
    struct LocationInfo
    {
       std::string m_City;
       std::string m_State;
       std::string m_Zip;
    };
    typedef std::list<LocationInfo> ListOfLocations;
    You'd have to search the list linearly, since there's no possible ordering that would satisfy all three conditions.

    Or, you could actually use pointers to the above struct; and store them in three different sets, each with it's own version of "less".

    Viggy

  3. #3
    Join Date
    Mar 2006
    Posts
    7

    Re: Data Structure with 3 keys

    I think linked list is a good solution
    the data structure would be :
    struct locInfo
    {
    char city[20];
    char state[20]
    char zip[6];
    struct locInfo *pNext;
    }headNode;

    so simple traversing may solve problem;

  4. #4
    Join Date
    Feb 2006
    Location
    London
    Posts
    238

    Re: Data Structure with 3 keys

    Quote Originally Posted by telesto
    Hello,

    I am looking for a data structure to help me with the following:

    Given either city, state or zip, I need to be able to get a value or list of values of the other.

    So I want to store city, state and zip info in a data structure. Then if I get any one of the values, I want access to the other two.

    What kind of data structure can I use?

    Thanks,
    T.
    Here

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured