Language: C++

#include <iostream>

using namespace std;

struct Heap{
	vector <int> Array;
	
	int pai(int input){
		return (input - 1)/2;
	}
	
	int filhoEsquerdo(int input){
		return (2*input + 1);
	}
	
	int filhoDireito(int input){
		return (2*input + 2);
	}
	
	// Arruma após inserção
	void HeapifyRemover(int arrumar){
		int esquerdo = filhoEsquerdo(arrumar);
		int direito = filhoDireito(arrumar);
		
		int maior = arrumar;
		
		//Vejo quem é maior
		if (esquerdo < size() && Array[esquerdo] > Array[arrumar]){
			maior = esquerdo;
		}
		if (direito < size() && Array[direito] > Array[arrumar]){
			maior = direito;
		}
		if (maior != arrumar){
			swap(Array[arrumar], Array[maior]);
			HeapifyRemover(maior);
		}
	}
	
	void HeapifyInserir(int arrumar){
		if (arrumar && Array[pai(arrumar)] < Array[arrumar]){
			swap(Array[pai(arrumar)], Array[arrumar]);
			HeapifyInserir(pai(arrumar));
		}
	}
	
	void inserirHeap(int valor){
		Array.push_back(valor);
		HeapifyInserir(size() - 1);
	}
	
	void printaRaiz(){
		printf("%i\n", Array.at(0));
	}
	
	int removerRaiz(){
		Array[0] = Array[size()-1];
		Array.pop_back();
		HeapifyRemover(0);
	}
};

int main(){
	Heap heap;
	string operacao; int valor;
	while(cin >> operacao){
		if (operacao == "insert"){
			cin >> valor;
			heap.inserirHeap(valor);
		} else if (operacao == "extract"){
			printaRaiz()
			heap.removerRaiz();
		} else {
			break;
		}
	}
	return 0;
}



Compiler output:
a.cc:6:9: error: 'vector' does not name a type
    6 |         vector <int> Array;
      |         ^~~~~~
a.cc: In member function 'void Heap::HeapifyRemover(int)':
a.cc:28:36: error: no matching function for call to 'size()'
   28 |                 if (esquerdo < size() && Array[esquerdo] > Array[arrumar]){
      |                                ~~~~^~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:262:5: note: candidate: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/range_access.h:272:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note:   candidate expects 1 argument, 0 provided
a.cc:28:42: error: 'Array' was not declared in this scope
   28 |                 if (esquerdo < size() && Array[esquerdo] > Array[arrumar]){
      |                                          ^~~~~
a.cc:31:35: error: no matching function for call to 'size()'
   31 |                 if (direito < size() && Array[direito] > Array[arrumar]){
      |                               ~~~~^~
/usr/include/c++/14/bits/range_access.h:262:5: note: candidate: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/range_access.h:272:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note:   candidate expects 1 argument, 0 provided
a.cc:31:41: error: 'Array' was not declared in this scope
   31 |                 if (direito < size() && Array[direito] > Array[arrumar]){
      |                                         ^~~~~
a.cc:35:30: error: 'Array' was not declared in this scope
   35 |                         swap(Array[arrumar], Array[maior]);
      |                              ^~~~~
a.cc: In member function 'void Heap::HeapifyInserir(int)':
a.cc:41:32: error: 'Array' was not declared in this scope
   41 |                 if (arrumar && Array[pai(arrumar)] < Array[arrumar]){
      |                                ^~~~~
a.cc: In member function 'void Heap::inserirHeap(int)':
a.cc:48:17: error: 'Array' was not declared in this scope
   48 |                 Array.push_back(valor);
      |                 ^~~~~
a.cc:49:36: error: no matching function for call to 'size()'
   49 |                 HeapifyInserir(size() - 1);
      |                                ~~~~^~
/usr/include/c++/14/bits/range_access.h:262:5: note: candidate: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/range_access.h:272:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note:   candidate expects 1 argument, 0 provided
a.cc: In member function 'void Heap::printaRaiz()':
a.cc:53:32: error: 'Array' was not declared in this scope
   53 |                 printf("%i\n", Array.at(0));
      |                                ^~~~~
a.cc: In member function 'int Heap::removerRaiz()':
a.cc:57:17: error: 'Array' was not declared in this scope
   57 |                 Array[0] = Array[size()-1];
      |                 ^~~~~
a.cc:57:38: error: no matching function for call to 'size()'
   57 |                 Array[0] = Array[size()-1];
      |                                  ~~~~^~
/usr/include/c++/14/bits/range_access.h:262:5: note: candidate: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/range_access.h:272:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note:   candidate expects 1 argument, 0 provided
a.cc:60:9: warning: no return statement in function returning non-void [-Wreturn-type]
   60 |         }
      |         ^
a.cc: In function 'int main()':
a.cc:71:25: error: 'printaRaiz' was not declared in this scope
   71 |                         printaRaiz()
      |                         ^~~~~~~~~~