Language: C

#include <stdio.h>
#define NIL -1
#define MAX 2000005
#define MIN -100000000

int T[MAX];
int hs;

void swap(int, int);
void maxHeapify(int);
void heapIncreaseKey(int, int);


int main()
{
  int i, a;
  char c[10];
 
  for(i=0; i<MAX; i++){
    A[i]=NIL;
  }

  for(i=1; ;i++){
    scanf("%s ",c);

    if(c[0]=='i'){
      scanf("%d", &a);
      maxHeapInsert(a);
    }
    else if(c[1]=='x'){
      a = heapExtractMax();
      printf("%d\n",a);
    }
    else break;
  }
  return 0;
}
  

void swap(int x, int y)
{
  int temp;
  temp=A[x];
  A[x]=A[y];
  A[y]=temp;
}


void maxHeapify(int i)
{
  int l = left(i);
  int r = right(i);
  int largest;

  if(l <= hs && A[l] > A[i]){
	largest = l;
  }
  else{
	largest = i;
  }
  if(r <= hs && A[r] > A[largest]){
	largest = r;
  }
  if(largest != i)
	{
	  swap(i, largest);
	  maxHeapify(largest);
	}
}


void heapIncreaseKey(int i, int key)
{
  if(key < A[i]) return;

  A[i] = key;
  while(i>1 && A[parent(i)] < A[i]){
    swap(i, parent(i));
    i = parent(i);
  }
}


void maxHeapInsert(int key)
{
  hs = hs + 1;
  A[hs] = MIN;
  heapIncreaseKey(hs, key);
}


int heapExtractMax()
{
  int max;

  if(hs < 1){
    return;
  }

  max = A[1];
  A[1] = A[hs];
  hs = hs - 1;
  maxHeapify(1);
  return max;
}

 
int parent(int i)
{
  return i/2;
}


int left(int i){
  return 2*i;
}


int right(int i){
  return 2*i+1;
}

Compiler output:
main.c: In function 'main':
main.c:20:5: error: 'A' undeclared (first use in this function)
   20 |     A[i]=NIL;
      |     ^
main.c:20:5: note: each undeclared identifier is reported only once for each function it appears in
main.c:28:7: error: implicit declaration of function 'maxHeapInsert' [-Wimplicit-function-declaration]
   28 |       maxHeapInsert(a);
      |       ^~~~~~~~~~~~~
main.c:31:11: error: implicit declaration of function 'heapExtractMax' [-Wimplicit-function-declaration]
   31 |       a = heapExtractMax();
      |           ^~~~~~~~~~~~~~
main.c: In function 'swap':
main.c:43:8: error: 'A' undeclared (first use in this function)
   43 |   temp=A[x];
      |        ^
main.c: In function 'maxHeapify':
main.c:51:11: error: implicit declaration of function 'left' [-Wimplicit-function-declaration]
   51 |   int l = left(i);
      |           ^~~~
main.c:52:11: error: implicit declaration of function 'right' [-Wimplicit-function-declaration]
   52 |   int r = right(i);
      |           ^~~~~
main.c:55:17: error: 'A' undeclared (first use in this function)
   55 |   if(l <= hs && A[l] > A[i]){
      |                 ^
main.c: In function 'heapIncreaseKey':
main.c:74:12: error: 'A' undeclared (first use in this function)
   74 |   if(key < A[i]) return;
      |            ^
main.c:77:18: error: implicit declaration of function 'parent' [-Wimplicit-function-declaration]
   77 |   while(i>1 && A[parent(i)] < A[i]){
      |                  ^~~~~~
main.c: At top level:
main.c:84:6: warning: conflicting types for 'maxHeapInsert'; have 'void(int)'
   84 | void maxHeapInsert(int key)
      |      ^~~~~~~~~~~~~
main.c:28:7: note: previous implicit declaration of 'maxHeapInsert' with type 'void(int)'
   28 |       maxHeapInsert(a);
      |       ^~~~~~~~~~~~~
main.c: In function 'maxHeapInsert':
main.c:87:3: error: 'A' undeclared (first use in this function)
   87 |   A[hs] = MIN;
      |   ^
main.c: In function 'heapExtractMax':
main.c:97:5: error: 'return' with no value, in function returning non-void [-Wreturn-mismatch]
   97 |     return;
      |     ^~~~~~
main.c:92:5: note: declared here
   92 | int heapExtractMax()
      |     ^~~~~~~~~~~~~~
main.c:100:9: error: 'A' undeclared (first use in this function)
  100 |   max = A[1];
      |         ^