Pagini recente » Cod sursa (job #2629825) | Cod sursa (job #1469682) | Cod sursa (job #236756) | Cod sursa (job #274254) | Cod sursa (job #1310138)
#include <fstream>
#include <algorithm>
#include <iomanip>
using namespace std;
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
int h[100],intrare[100],n,i,tip,x,nrelecur,nrele,poz[100];
void schimb(int x, int y)
{
int aux = h[x];
h[x] = h[y];
h[y] = aux;
poz[h[x]] = x;
poz[h[y]] = y;
}
void urcare(int p)
{
while(p > 1 && intrare[h[p]] < intrare[h[p/2]])
{
schimb(p, p/2);
p /= 2;
}
}
int main()
{
fin>>n;
for(i=1;i<=n;i++)
{
fin>>tip;
if(tip==1)
{
fin>>x;
nrele++;
nrelecur++;
intrare[nrele]=x;
h[nrelecur]=nrele;
poz[h[nrelecur]]=nrelecur;
urcare(nrelecur);
}
if(tip==2)
{
fin>>x;
}
}
return 0;
}