add priority queue

This commit is contained in:
Henry He
2024-02-29 23:42:09 +08:00
parent f2542611b0
commit 1166e99c92
25 changed files with 3613 additions and 3 deletions

View File

@ -0,0 +1,52 @@
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <ctime>
#include <cstdlib>
#include "priority_queue.hpp"
int rand() {
static int reed = 1727417277;
return (reed += (reed << 5) + 172741827);
}
bool testmerge()
{
sjtu::priority_queue<int> pq1, pq2;
static int buffer[900000];
int pointer = 0;
const int MAXA = 400000;
const int MAXB = 400000;
for (int i = 1; i <= MAXA; i++) {
pq1.push(buffer[++pointer] = rand());
}
for (int i = 1; i <= MAXB; i++) {
pq2.push(buffer[++pointer] = rand());
}
pq1.merge(pq2);
if (!pq2.empty()) {
return false;
} else {
std::sort(buffer + 1, buffer + pointer + 1);
while (pointer > 0) {
if (pq1.top() != buffer[pointer]) {
return false;
}
pq1.pop();
pointer--;
}
}
return true;
}
int main(int argc, char *const argv[])
{
if (testmerge()) {
std::cout << "OKAY" << std::endl;
} else {
std::cout << "FAIL" << std::endl;
}
return 0;
}