2 Attachment(s)
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::operator()(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;
}