Language: C

void swap(int*,int,int);
void printHeap(int*);
void insert(int*,int);
int extract(int*);
int h=0;//size of heap
int main(void)
{
  int arr[N];//array (1-origin)
  char op[10];//operation
  int key;
  for(;;)
    {
      scanf("%s",op);
      if(strcmp(op,"insert")==0)
	{
	  scanf("%d",&key);
	  insert(arr,key);
	}
      if(strcmp(op,"extract")==0) printf("%d\n",extract(arr));
      if(strcmp(op,"print")==0) printHeap(arr);//for debugging
      if(strcmp(op,"end")==0) break;
      
    }
  return 0;
}
int parent(int i)
{
  return i/2;
}
int left(int i)
{
  return 2*i;
}
int right(int i)
{
  return 2*i+1;
}
void buildMaxHeap(int *arr)
{
  int i;//counter
  for(i=h/2;i>=1;i--) maxHeapify(arr,i);
}
void maxHeapify(int *arr,int i)
{
  int l=left(i);
  int r=right(i);
  int largest;
  if(l<=h&&arr[l]>arr[i]) largest=l;
  else largest=i;
  if(r<=h&&arr[r]>arr[largest]) largest=r;
  if(largest!=i)
    {
      swap(arr,i,largest);
      maxHeapify(arr,largest);
    }
}
void swap(int *arr,int x,int y)
{
  int temp;
  temp=arr[x];
  arr[x]=arr[y];
  arr[y]=temp;
}
void printHeap(int *arr)
{
  int i;
  for(i=1;i<=h;i++) printf(" %d",arr[i]);
  printf("\n");
}
void insert(int *arr,int key)
{
  int index;
  h++;
  arr[h]=key;
  for(index=parent(h);index>=1;index=parent(index))
    {
      if(arr[index]<arr[parent(index)]) break;
      maxHeapify(arr,index);
    }
}
int extract(int *arr)
{
  int ret=arr[1];
  arr[1]=arr[h];
  h--;
  maxHeapify(arr,1);
  return ret;
}



Compiler output:
main.c: In function 'main':
main.c:8:11: error: 'N' undeclared (first use in this function)
    8 |   int arr[N];//array (1-origin)
      |           ^
main.c:8:11: note: each undeclared identifier is reported only once for each function it appears in
main.c:13:7: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
   13 |       scanf("%s",op);
      |       ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | void swap(int*,int,int);
main.c:13:7: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
   13 |       scanf("%s",op);
      |       ^~~~~
main.c:13:7: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:14:10: error: implicit declaration of function 'strcmp' [-Wimplicit-function-declaration]
   14 |       if(strcmp(op,"insert")==0)
      |          ^~~~~~
main.c:1:1: note: include '<string.h>' or provide a declaration of 'strcmp'
  +++ |+#include <string.h>
    1 | void swap(int*,int,int);
main.c:19:35: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
   19 |       if(strcmp(op,"extract")==0) printf("%d\n",extract(arr));
      |                                   ^~~~~~
main.c:19:35: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:19:35: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:19:35: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c: In function 'buildMaxHeap':
main.c:41:23: error: implicit declaration of function 'maxHeapify' [-Wimplicit-function-declaration]
   41 |   for(i=h/2;i>=1;i--) maxHeapify(arr,i);
      |                       ^~~~~~~~~~
main.c: At top level:
main.c:43:6: warning: conflicting types for 'maxHeapify'; have 'void(int *, int)'
   43 | void maxHeapify(int *arr,int i)
      |      ^~~~~~~~~~
main.c:41:23: note: previous implicit declaration of 'maxHeapify' with type 'void(int *, int)'
   41 |   for(i=h/2;i>=1;i--) maxHeapify(arr,i);
      |                       ^~~~~~~~~~
main.c: In function 'printHeap':
main.c:67:21: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
   67 |   for(i=1;i<=h;i++) printf(" %d",arr[i]);
      |                     ^~~~~~
main.c:67:21: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:68:3: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
   68 |   printf("\n");
      |   ^~~~~~
main.c:68:3: note: include '<stdio.h>' or provide a declaration of 'printf'