Menu

Trendtrackercpp Fills Provided Vector K Tweeted Hashtags Order Tweeted Least Tweeted Fewer Q43896670

//trendtracker.cpp

// Fills the provided vector with the k most-tweetedhashtags,
// in order from most-tweeted to least-tweeted.
//
// If there are fewer than k hashtags, then the vector isfilled
// with all hashtags (in most-tweeted to least-tweetedorder).
//
// Must run in O(nk) time.
void Trendtracker::top_k_trends(vector<string> &T, intk){}

Can I get help with solving this Function?

//trendtracker.h

#ifndef TRENDTRACKER_H
#define TRENDTRACKER_H

#include <vector>
#include <string>

using namespace std;

class Trendtracker
{
   // For the mandatory running times below:
   // n is the number of hashtags in theTrendtracker.

public:
   // Creates a new Trendtracker tracking nohashtags.
   //
   // Must run in O(1) time.
   Trendtracker();

   // Inserts a hashtag (tweeted 0 times) into theTrendtracker.
   // If the hashtag already is in Trendtracker, doesnothing.
   //
   // Must run in O(n) time.
   void insert(string ht);

   // Return the number of hashtags in theTrendtracker.
   //
   // Must run in O(1) time.
   int size();

   // Adds 1 to the total number times a hashtag hasbeen tweeted.
   // If the hashtag does not exist in TrendTracker, doesnothing.
   //
   // Must run in O(n) time.
   void tweeted(string ht);

   // Returns the number of times a hashtag has beentweeted.
   // If the hashtag does not exist in Trendtracker,returns -1.
   //
   // Must run in O(n) time.
   int popularity(string name);

   // Returns a most-tweeted hashtag.
   // If the Trendtracker has no hashtags, returns””.
   //
   // Must run in O(n) time.
   string top_trend();

   // Fills the provided vector with the 3most-tweeted hashtags,
   // in order from most-tweeted to least-tweeted.
   //
   // If there are fewer than 3 hashtags, then the vectoris filled
   // with all hashtags (in most-tweeted to least-tweetedorder).
   //
   // Must run in O(n) time.
   void top_three_trends(vector<string>&T);

   // Fills the provided vector with the kmost-tweeted hashtags,
   // in order from most-tweeted to least-tweeted.
   //
   // If there are fewer than k hashtags, then the vectoris filled
   // with all hashtags (in most-tweeted to least-tweetedorder).
   //
   // Must run in O(nk) time.
   void top_k_trends(vector<string> &T, intk);

private:
   // A simple class representing a hashtag and
   // the number of times it has been tweeted.
   class Entry
   {
   public:
       string hashtag;
       int pop;
   };

   // Entries containing each hashtag and itspopularity.
   vector<Entry> E;
};

#endif

Expert Answer


Answer to //trendtracker.cpp // Fills the provided vector with the k most-tweeted hashtags, // in order from most-tweeted to least…

OR