E đang làm bài Chèn, duyệt, xóa 1 nút trên cây nhị phân tìm kiếm ( yêu cầu input từ 1 file và output ra 1 file) Em làm đc phần input rồi, h chỉ cần code in ra file output thôi (bh vẫn là xuất ra màn hình). Ai giúp em với.
Code:
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iomanip.h>
#include <malloc.h>
struct Node
{
 int info;
 struct Node *right,*left;
};
typedef Node Tree;
void InsertNode(Node **T, int x);
void NLR(Tree *T);
void LNR(Tree *T);
void LRN(Tree *T);
void DeleteNode(Node **m,int x);
main()

{
 int  n;
 int  m;
 Tree *c;
 c=NULL;
 FILE *f;
 f=fopen ("cay-nptk.inp.txt","rt");
 fscanf (f,"%d/n",&n);
 for (int i=0;i<n;i++) {
   fscanf (f,"%d",&m);
   InsertNode(&c,m);
}
printf("duyet cay NLR: ");NLR(c);
printf("\nduyet cay LNR: ");LNR(c);
printf("\nduyet cay LRN: ");LRN(c);
printf ("\nban muon xoa gia tri nao: ");
scanf ("%d",&m);
DeleteNode(&c,m);
printf("duyet cay NLR sau khi xoa: ");NLR(c);
printf("\nduyet cay LNR sau khi xoa: ");LNR(c);
printf("\nduyet cay LRN sau khi xoa: ");LRN(c);
getch();
}

void InsertNode(Node **T, int x)
{
 if (*T!=NULL){
   if  (x<(*T)->info) InsertNode(&(*T)->left,x);
   else InsertNode(&(*T)->right,x);
              }
 else {
    *T=(Node*)malloc(sizeof(Tree));
   (**T).left=NULL;
   (**T).right=NULL;
   (**T).info=x;
      }
}
void NLR(Tree *k){
   if (k!=NULL){
      printf("%d, ", k->info);
      NLR(k->left);
      NLR(k->right);
   }
}

void LNR(Tree *w){
   if (w!=NULL){
      NLR(w->left);
      printf("%d, ", w->info);
      NLR(w->right);
   }
}

void LRN(Tree *q){
   if (q!=NULL){
      NLR(q->left);
      NLR(q->right);
      printf("%d, ", q->info);
   }
}
void DeleteNode(Node **m,int x)
{
 if ((*m)==NULL) printf ("\nKhong co gia tri nay.");
 else if (x<(*m)->info) DeleteNode(&(**m).left,x);
 else if (x>(*m)->info) DeleteNode(&(**m).right,x);
 else
  {
    Tree *v,*c,*l;
    v=*m;
    if ((**m).right==NULL)
     {
       *m=v->left;
       free (v);
     }
    else if ((*m)->left==NULL)
     {
      *m=v->right;
      free (v);
     }
    else
     {
      c=v->left;
      if (c->right==NULL)
       {
        c->right=v->right;
        *m=c;
        free (v);
       }
      else
       {
        l=c->right;
        while (l!=NULL){c=l;l=l->right;}
      l->right=v->right;
      c->right=l->left;
      l->left=v->left;
      *m=l;
      free (v);
       }
     }
  }
}