Pagini recente » Cod sursa (job #1292842) | Cod sursa (job #2457232) | Cod sursa (job #908743) | Cod sursa (job #2717440) | Cod sursa (job #1294219)
#include <algorithm>
#include <fstream>
#include <math.h>
using namespace std;
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
int heap[100],vect[100],n,i,tip,element,k,marimeheap,pozitie[100];
void urcare(int x)
{
if(vect[heap[x/2]]>vect[heap[x]])
{
swap(heap[x/2],heap[x]);
swap(pozitie[x/2],pozitie[x]);
urcare(x/2);
}
}
int main()
{
fin>>n;
for(i=1;i<=n;i++)
{
fin>>tip;
if(tip==3)
{
fout<<vect[heap[1]]<<"\n";
}
if(tip==1)
{
fin>>element;
marimeheap++;
vect[++k]=element;
heap[marimeheap]=k;
pozitie[k]=marimeheap;
urcare(marimeheap);
}
//if(tip==2)
//{
// fin>>stergere;
//}
}
return 0;
}