solve hw-9
This commit is contained in:
35
hws/tiktok_trends/SoundInfo.h
Normal file
35
hws/tiktok_trends/SoundInfo.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "TopKVideoHolder.h"
|
||||
|
||||
struct SoundInfo {
|
||||
const std::string* musicId = nullptr;
|
||||
const std::string* musicName = nullptr;
|
||||
const std::string* musicAuthor = nullptr;
|
||||
long totalViews = 0;
|
||||
TopKVideoHolder topVideos;
|
||||
|
||||
SoundInfo() = default;
|
||||
|
||||
SoundInfo(const std::string* id, const std::string* name, const std::string* author)
|
||||
: musicId(id), musicName(name), musicAuthor(author), totalViews(0) {}
|
||||
};
|
||||
|
||||
struct CompareSoundPtr {
|
||||
bool operator()(const SoundInfo* a, const SoundInfo* b) const {
|
||||
if (a->totalViews != b->totalViews) return a->totalViews > b->totalViews;
|
||||
if (a->musicId && b->musicId) return *a->musicId < *b->musicId;
|
||||
if (a->musicId) return true;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
struct CompareSoundPtrForHeap {
|
||||
bool operator()(const SoundInfo* a, const SoundInfo* b) const {
|
||||
if (a->totalViews != b->totalViews) return a->totalViews > b->totalViews;
|
||||
if (a->musicId && b->musicId) return *a->musicId > *b->musicId;
|
||||
if (a->musicId) return false;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user