Language: C

#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

int main(){
  
  int n, i, x;
  char com[10];
  
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);

    if ( strcmp(com, "insert") == 0 ){
      scanf("%d", &x);
      insert(x);
    }
    else if ( strcmp(com, "print") == 0 ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if ( strcmp(com, "find") == 0 ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }
     else if ( strcmp(com, "delete") == 0 ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  return 0;
}

Node treeMinimum(Node x){
  while( x->left != NIL ) x = x->left;
  return x;
}
Node treeMaximum(Node x){
  while( x->right != NIL ) x = x->right;
  return x;
}

Node treeSearch(Node u, int k){
  while( u != NIL && k != u->key ){
    if ( k < u->key ) u = u->left;
    else u = u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  if ( x->right != NIL ) return treeMinimum(x->right);
  Node y = x->parent;
  while( y != NIL && x == y->right ){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if ( z->left == NIL || z->right == NIL ) y = z;
  else y = treeSuccessor(z);
  if ( y->left != NIL ) x = y->left;
  else x = y->right;

  if ( x != NIL ) x->parent = y->parent;

  if ( y->parent == NIL ){
    root = x;
  } else {
    if (y == y->parent->left) y->parent->left = x;
    else y->parent->right = x;
  }

  if ( y != z ){
    z->key = y->key;
  }

  free(y);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL ){
    y = x;
    if ( z->key < x->key ){
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->parent = y;
  if ( y == NIL ){
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node u){
  if ( u == NIL ) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
void preorder(Node u){
  if ( u == NIL ) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

Compiler output:
main.c: In function 'main':
main.c:25:10: error: implicit declaration of function 'strcmp' [-Wimplicit-function-declaration]
   25 |     if ( strcmp(com, "insert") == 0 ){
      |          ^~~~~~
main.c:3:1: note: include '<string.h>' or provide a declaration of 'strcmp'
    2 | #include<stdlib.h>
  +++ |+#include <string.h>
    3 | 
main.c:27:7: error: implicit declaration of function 'insert' [-Wimplicit-function-declaration]
   27 |       insert(x);
      |       ^~~~~~
main.c:30:7: error: implicit declaration of function 'inorder' [-Wimplicit-function-declaration]
   30 |       inorder(root);
      |       ^~~~~~~
main.c:32:7: error: implicit declaration of function 'preorder' [-Wimplicit-function-declaration]
   32 |       preorder(root);
      |       ^~~~~~~~
main.c:37:16: error: implicit declaration of function 'treeSearch' [-Wimplicit-function-declaration]
   37 |       Node t = treeSearch(root, x);
      |                ^~~~~~~~~~
main.c:37:16: error: initialization of 'Node' {aka 'struct node *'} from 'int' makes pointer from integer without a cast [-Wint-conversion]
main.c:43:7: error: implicit declaration of function 'treeDelete' [-Wimplicit-function-declaration]
   43 |       treeDelete(treeSearch(root, x));
      |       ^~~~~~~~~~
main.c: At top level:
main.c:58:6: error: conflicting types for 'treeSearch'; have 'struct node *(struct node *, int)'
   58 | Node treeSearch(Node u, int k){
      |      ^~~~~~~~~~
main.c:37:16: note: previous implicit declaration of 'treeSearch' with type 'int()'
   37 |       Node t = treeSearch(root, x);
      |                ^~~~~~~~~~
main.c:76:6: warning: conflicting types for 'treeDelete'; have 'void(struct node *)'
   76 | void treeDelete(Node z){
      |      ^~~~~~~~~~
main.c:43:7: note: previous implicit declaration of 'treeDelete' with type 'void(struct node *)'
   43 |       treeDelete(treeSearch(root, x));
      |       ^~~~~~~~~~
main.c:101:6: warning: conflicting types for 'insert'; have 'void(int)'
  101 | void insert(int k){
      |      ^~~~~~
main.c:27:7: note: previous implicit declaration of 'insert' with type 'void(int)'
   27 |       insert(x);
      |       ^~~~~~
main.c:132:6: warning: conflicting types for 'inorder'; have 'void(struct node *)'
  132 | void inorder(Node u){
      |      ^~~~~~~
main.c:30:7: note: previous implicit declaration of 'inorder' with type 'void(struct node *)'
   30 |       inorder(root);
      |       ^~~~~~~
main.c:138:6: warning: conflicting types for 'preorder'; have 'void(struct node *)'
  138 | void preorder(Node u){
      |      ^~~~~~~~
main.c:32:7: note: previous implicit declaration of 'preorder' with type 'void(struct node *)'
   32 |       preorder(root);
      |       ^~~~~~~~