Cod sursa(job #318781)

Utilizator ada_sAda-Mihaela Solcan ada_s Data 29 mai 2009 11:51:41
Problema Heapuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.65 kb
#include <stdio.h>
int main()
{
	freopen("heapuri.in", "r", stdin);
	freoepn("heapuri.out", "w", stdout);
	scanf("%ld", &n);
	for (i=0; i<n; i++)
	{
		scanf("%d", &cod);
		if (cod<3)
		{
			scanf("%ld", &x);
			if (cod==1)
			{
				a[++ia]=x;
				heap[++iheap]=ia;
				poz[ia]=iheap;
				push(iheap);
			}//if
			else
				if (cod==2)
					pop(poz[x]);
		}//if
		else
			printf("%ld\n", &a[poz[1]]);
	}//for i
	return 0;
}//main

void push(long x)
{
  while (x/2)&&(a[heap[x]]<a[heap[x/2]])
  {
	  aux=heap[x];
	  heap[x]=heap[x/2];
	  heap[x/2]=aux;
	  poz[heap[x]]=x;
	  poz[heap[x/2]]=x/2;
	  x/=2;
  }//while
}//push