add priority queue
This commit is contained in:
1
priority_queue/data/five/answer.txt
Normal file
1
priority_queue/data/five/answer.txt
Normal file
@ -0,0 +1 @@
|
||||
OKAY
|
52
priority_queue/data/five/code.cpp
Normal file
52
priority_queue/data/five/code.cpp
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user