Question: can you do this code faster? it need a better searching algorithm. you can oly use #include #include - - - - - - -
can you do this code faster? it need a better searching algorithm. you can oly use #include
#include
#include "trendtracker.h
Trendtracker::Trendtracker
Eclear;
void Trendtracker::insertstd::string ht
for Entry& entry : E
if entryhashtag ht
return;
Entry newEntry;
newEntry.hashtag ht;
newEntry.pop ;
EpushbacknewEntry;
int Trendtracker::size
return Esize;
void Trendtracker::tweetedstd::string ht
for Entry& entry : E
if entryhashtag ht
entry.pop;
return;
int Trendtracker::popularitystd::string ht
for const Entry& entry : E
if entryhashtag ht
return entry.pop;
return ;
std::string Trendtracker::toptrend
if Eempty
return ;
int maxPop Epop;
std::string topHashtag Ehashtag;
for const Entry& entry : E
if entrypop maxPop
maxPop entry.pop;
topHashtag entry.hashtag;
return topHashtag;
void Trendtracker::topthreetrendsstd::vector& T
Sort the entries based on popularity
for sizet i ; i Esize; i
for sizet j i ; j Esize; j
if Ejpop Eipop
std::swapEi Ej;
Tclear;
for const Entry& entry : E
Tpushbackentryhashtag;
if Tsize
break;
void Trendtracker::removestd::string ht
for auto it Ebegin; it Eend; it
if ithashtag ht
Eeraseit;
break;
void Trendtracker::topktrendsstd::vector& T int k
Sort the entries based on popularity
for sizet i ; i Esize; i
for sizet j i ; j Esize; j
if Ejpop Eipop
std::swapEi Ej;
Tclear;
for const Entry& entry : E
Tpushbackentryhashtag;
if Tsize k
break;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
