solve hw-9

This commit is contained in:
JamesFlare1212
2025-04-15 22:08:11 -04:00
parent 9ec5d3d32c
commit a109046498
17 changed files with 1498 additions and 7 deletions

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