implementing with map, and unordered map

This is a discussion on implementing with map, and unordered map within the C++ Programming forums, part of the General Programming Boards category; My program has two data structures currently. One is a type of unordered map, and the other is just map. ...

  1. #1
    Registered User
    Join Date
    Nov 2013
    Posts
    1

    implementing with map, and unordered map

    My program has two data structures currently. One is a type of unordered map, and the other is just map.

    my unordered map stores a value, and a key, and my map stores the key to the unordered map, but it has to be sorted by the value within the Hashmap. What will be the best way to implement it?
    I can't really use priority queue on this one because I need to have access to not only the mins or max.

    I attached 2 files on with the actual code, and another with complier error
    I don't think my code is either logically or gramatically right.. how should I write my code for this type of impelmentation?
    please HELP
    Thank you!


    #include <iostream>
    #include <unordered_map>
    #include <map>
    #include <utility>
    using namespace std;

    class comp {


    public:
    comp(unordered_map<int,int> & Hash);
    bool operator() (const int index1, const int index2) const;
    private:
    unordered_map<int,int>hashTable;
    };

    comp ::comp(unordered_map<int,int> & Hash){
    hashTable = Hash;
    }

    bool comp:perator()(int index1, int index2) const{
    pair<int,int> x = hashTable.find(index1);
    pair<int,int> y = hashTable.find(index2);
    if(x.second >y.second){
    return true;
    }
    return false;

    }

    int main(){
    int a = 3;
    int b = 3;
    unordered_map<int,int> Hash;
    map <int,int,comp(Hash)> BST;

    Hash.insert(make_pair<int,int>(3,3));
    Hash.insert(make_pair<int,int>(5,5));
    Hash.insert(make_pair<int,int>(4,4));
    pair<int,int> x = Hash.find(3);
    int val = x.second;
    int key = x.first;
    BST.insert(key);



    return 0;
    }
    Attached Files Attached Files
    Last edited by jaesungj; 11-08-2013 at 10:19 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 06-30-2011, 11:29 PM
  2. Implementing IRC protocol
    By cs_student in forum Networking/Device Communication
    Replies: 6
    Last Post: 07-14-2009, 12:25 PM
  3. Implementing RLE
    By stevesmithx in forum C Programming
    Replies: 14
    Last Post: 04-03-2008, 03:03 PM
  4. Need help implementing a class
    By jk1998 in forum C++ Programming
    Replies: 8
    Last Post: 04-05-2007, 04:13 PM
  5. Implementing CGI
    By peradox in forum Networking/Device Communication
    Replies: 4
    Last Post: 08-03-2005, 02:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21