class hash
{
private:
static const int tableSize = 1000;
struct item
{
string name;
unsigned int reps;
item* next;
};
item* HashTable[tableSize];
}
In my program I constructed my hashtable with this structure, and I am using chaining. These items holds very similar strings, and an integer variable with them, storing how many times they occur in a text file. I want to write a function to print most frequent K strings in the context.
void PrintTopFrequentList(int K);
My resulting hash table is actually very big,maybe 100.000 entries? What I have got so far is this...
void hash::PrintTopFrequentList(int length)
{
vector<item*> row;
vector<item*> sorted;
int no;
for ( int i = 0 ; i<tableSize ; i++)
{
item* Ptr= HashTable[i];
while ( Ptr->next!=NULL )
{
row.push_back(Ptr);
Ptr=Ptr->next;
}
sort(row.begin(),row.end());
sorted.insert(sorted.end(), row.begin(),row.end());
sort(sorted.begin(),sorted.end());
}
My problems are, first of all those sort
functions at the end of PrintTopFreq
. Function does not seem to work, after the for loop I add this part to control sorting, but it didn't work.
What I actually need to do is to customize this sort function such that my result vector will be in Descending order. I tried some function overloading inside class definition I looked from other posts but couldn't make it work.
I tried reading this post but it didn't help.