Language: C

#include <stdio.h>
#include <stdlib.h>
#define NIL NULL  
struct node{
  struct node *r;
  struct node *l;
  struct node *p;
  int key;
};

typedef struct node * Node;
Node root;
Node find(Node u, int k);
void insert(int k);
void inorderTreeWalk(Node x);
void preorderTreeWalk(Node x);
Node treeMinimum(Node x);
Node treeSearch(Node x,int k);
Node treeSuccessor(Node x);
void treeDelete(Node z);
int main()
{
  char str[7];
  int m,i,x,key;
  scanf("%d",&m);
  for( i=0 ; i<m ; i++ ){
    scanf("%s",str);
    if(str[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(str[0]=='p'){
      inorderTreeWalk(root);
      printf("\n");
      preorderTreeWalk(root);
      printf("\n");
    }
    else if(str[0]=='d'){
      scanf("%d",&key);
      if( find(root,key)==NIL ){
	printf("no\n");
      }else{
	printf("yes\n");
      }   
    }
    else{
      scanf("%d",&x);
      treeDelete(treeSearch(root,x));
    }
  }
  return 0;
   
}

Node find(Node u, int k){
      if( u == NIL || k == u->key ){
          return u;
      }  
      if( k < u->key ){
        return find(u->l,k);
      }else{
        return find(u->r,k);
      }
}

void insert(int k)
{
  Node x;
  Node y;
  Node z;
  y = NIL;
  x = root;
  z = (Node)malloc(sizeof(struct node));
  z->key = k;
  z->l = NIL;
  z->r = NIL;
   
  while(x!=NIL){
    y=x;
    if(z->key<x->key) x = x->l;
    else x = x->r;
  }
  z->p = y;
 
  if(y==NIL) root = z;
  else if(z->key<y->key) y->l = z;
  else y->r = z;
}
 
void inorderTreeWalk(Node x)
{
  if(x==NIL) return;
  inorderTreeWalk(x->l);
  printf(" %d",x->key);
  inorderTreeWalk(x->r);
}
 
void preorderTreeWalk(Node x)
{
  if(x==NIL) return;
    printf(" %d",x->key);
    preorderTreeWalk(x->l);
    preorderTreeWalk(x->r);
   
}
Node treeMinimum(Node x)
{
  while(x->left!=NIL) x = x->left;
  return x;
}
 
Node treeSearch(Node x,int k){
  if(x==NIL || k==x->key) return x;
  if(k<x->key) return treeSearch(x->left,k);
  
  else return treeSearch(x->right,k);
}
 
 
Node treeSuccessor(Node x)
{
  Node y;
  if(x->right!=NIL) return treeMinimum(x->right);
 
  y = x->parent;
  while(y!=NIL && x==y->right){
    x = y;
    y = y->parent;
  }
  return y;
}
 
 
void treeDelete(Node z)
{
  Node x, 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;
}

Compiler output:
main.c: In function 'treeMinimum':
main.c:108:10: error: 'struct node' has no member named 'left'
  108 |   while(x->left!=NIL) x = x->left;
      |          ^~
main.c:108:28: error: 'struct node' has no member named 'left'
  108 |   while(x->left!=NIL) x = x->left;
      |                            ^~
main.c: In function 'treeSearch':
main.c:114:35: error: 'struct node' has no member named 'left'
  114 |   if(k<x->key) return treeSearch(x->left,k);
      |                                   ^~
main.c:116:27: error: 'struct node' has no member named 'right'
  116 |   else return treeSearch(x->right,k);
      |                           ^~
main.c: In function 'treeSuccessor':
main.c:123:7: error: 'struct node' has no member named 'right'
  123 |   if(x->right!=NIL) return treeMinimum(x->right);
      |       ^~
main.c:123:41: error: 'struct node' has no member named 'right'
  123 |   if(x->right!=NIL) return treeMinimum(x->right);
      |                                         ^~
main.c:125:8: error: 'struct node' has no member named 'parent'
  125 |   y = x->parent;
      |        ^~
main.c:126:23: error: 'struct node' has no member named 'right'
  126 |   while(y!=NIL && x==y->right){
      |                       ^~
main.c:128:10: error: 'struct node' has no member named 'parent'
  128 |     y = y->parent;
      |          ^~
main.c: In function 'treeDelete':
main.c:137:7: error: 'struct node' has no member named 'left'
  137 |   if(z->left==NIL || z->right==NIL) y=z;
      |       ^~
main.c:137:23: error: 'struct node' has no member named 'right'
  137 |   if(z->left==NIL || z->right==NIL) y=z;
      |                       ^~
main.c:141:7: error: 'struct node' has no member named 'left'
  141 |   if(y->left!=NIL) x = y->left;
      |       ^~
main.c:141:25: error: 'struct node' has no member named 'left'
  141 |   if(y->left!=NIL) x = y->left;
      |                         ^~
main.c:143:13: error: 'struct node' has no member named 'right'
  143 |   else x = y->right;
      |             ^~
main.c:145:15: error: 'struct node' has no member named 'parent'
  145 |   if(x!=NIL) x->parent = y->parent;
      |               ^~
main.c:145:27: error: 'struct node' has no member named 'parent'
  145 |   if(x!=NIL) x->parent = y->parent;
      |                           ^~
main.c:147:7: error: 'struct node' has no member named 'parent'
  147 |   if(y->parent==NIL) root = x;
      |       ^~
main.c:149:15: error: 'struct node' has no member named 'parent'
  149 |   else if(y==y->parent->left) y->parent->left = x;
      |               ^~
main.c:149:32: error: 'struct node' has no member named 'parent'
  149 |   else if(y==y->parent->left) y->parent->left = x;
      |                                ^~
main.c:151:9: error: 'struct node' has no member named 'parent'
  151 |   else y->parent->right = x;
      |         ^~