I have written the code but unable to write the input format can you please help me out??
#include
using namespace std;
class medianfinder{
public:
priority_queue<int,vector> maxheap;
priority_queue<int,vector,greater> minheap;
medianfinder(){
}
void addnum(int num){
if(maxheap.empty() or maxheap.top()>num){
maxheap.push(num);
}else{
minheap.push(num);
}
if(minheap.size()+1<maxheap.size()){
minheap.push(maxheap.top());
maxheap.pop();
}
else if(maxheap.size()+1<minheap.size()){
maxheap.push(minheap.top());
minheap.pop();
}
}
double median(){
if(maxheap.size()==minheap.size()){
if(maxheap.size()==0){
return 0;
}else{
return (maxheap.top()+minheap.top())/2;
}
}
else{
return minheap.size()>maxheap.size() ? minheap.top():maxheap.top();
}
}
};
int main() {
return 0;
}
my code