Menu

Trendtrackerh Class Trendtracker Public Fills Provided Vector K Tweeted Hashtags Order Twe Q43898413

//trendtracker.h

class Trendtracker{

public:

// 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 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;
};

Need help on completing this function

//trendtracker.cpp

void Trendtracker::top_k_trends(vector<string> &T, intk){}

Tests for top_k_trends()

//main.cpp

#include <cassert>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <string>
#include “trendtracker.h”

//Test top_k_trends
   string weird = “#”;
   for (int i = ‘a’; i <= ‘z’; i++)
   {
       for (int j = ‘a’; j <= ‘z’;j++)
       {
           weird +=i;
           weird +=j;
           for (int i = 0;i < 3 * (weird[1] – ‘a’) + (weird[2] – ‘a’); i++)
              T4.tweeted(weird);
           weird =”#”;
       }
   }

   T4.top_k_trends(R, 50);

   test(R[2] == “#up”);
   test(R[5] == “#so”);
   test(R[10] == “#ok”);
   test(R[15] == “#me”);
   test(R[29] == “#finishing”);
   test(R[32] == “#quieting”);

Expert Answer


Answer to //trendtracker.h class Trendtracker{ public: // Fills the provided vector with the k most-tweeted hashtags, // in order …

OR