Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. #ifndef TRENDTRACKER_H
  2. #define TRENDTRACKER_H
  3.  
  4. #include <vector>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. class Trendtracker
  10. {
  11. // For the mandatory running times below:
  12. // n is the number of hashtags in the Trendtracker.
  13.  
  14. public:
  15. // Creates a new Trendtracker tracking no hashtags.
  16. //
  17. // Must run in O(1) time.
  18. Trendtracker();
  19.  
  20. // Inserts a hashtag of the popularity pop into the Trendtracker.
  21. // If pop is a non-negative integer and the hashtag already is in Trendtracker,
  22. //add pop to the popularity of this hashtag in Trendtracker;
  23. // if pop is a non-negative integer but the hashtag does not exist, add
  24. // otherwise, pop is a negative value and then do nothing but insert a hashtag of popularity zero if it is not in Trendtracker.
  25. //
  26. // Must run in O(n) time.
  27. void insert(string ht, int pop);
  28.  
  29. // Return the number of hashtags in the Trendtracker.
  30. //
  31. // Must run in O(1) time.
  32. int size();
  33.  
  34. // Adds 1 to the total number times a hashtag has been tweeted.
  35. // If the hashtag does not exist in TrendTracker, does nothing.
  36. //
  37. // Must run in O(n) time.
  38. void tweeted(string ht);
  39.  
  40. // Returns the number of times a hashtag has been tweeted.
  41. // If the hashtag does not exist in Trendtracker, returns -1.
  42. //
  43. // Must run in O(n) time.
  44. int popularity(string name);
  45.  
  46. // Returns the nubmer of hashtags of popularity equal to k.
  47. // k must be a non-negative integer and if not, return -1.
  48. // If the Trendtracker has no hashtags with popularity k, returns 0.
  49. //
  50. // Must run in O(n) time.
  51. int k_trend(int k);
  52.  
  53. // Fills the provided vector with the 3 most-tweeted hashtags,
  54. // in order from most-tweeted to least-tweeted.
  55. //
  56. // If there are fewer than 3 hashtags, then the vector is filled
  57. // with all hashtags (in most-tweeted to least-tweeted order).
  58. //
  59. // Must run in O(n) time.
  60. void top_three_trends(vector<string> &T);
  61.  
  62. private:
  63. // A struct representing a hashtag and
  64. // the number of times it has been tweeted.
  65. struct Entry
  66. {
  67. public:
  68. string hashtag;
  69. int pop;
  70. };
  71.  
  72.  
  73. // Entries containing each hashtag and its popularity.
  74. vector<Entry> E;
  75. };
  76.  
  77. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement