Announcement

Collapse
No announcement yet.

nhờ phát hiện lỗi ngữ nghĩa của hàm xoá số nguyên tố trong cây nhị phân tìm kiếm

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    luôn tiện đây mọi người giúp mình tìm cho mình cái lỗi ở hàm xóa,nó báo lỗi khi xóa phần tử đầu tiên trong dslk,sao lúc debug thì mình thấy nó gán lại head rùi mà khi in ra thì nó báo là truy cập bị lỗi do head=NULL,mọi người giúp mình nhá,đây là đề thi thực hành ctdl c23
    Code:
    #include"conio.h"
    #include"stdio.h"
    #include"stdlib.h"
    typedef struct toado
    {
    	int x;
    	int y;
    }toado;
    typedef struct node
    {
    	toado info;
    	struct node *next;
    }node;
    typedef struct list
    {
    	node *head;
    	node *tail;
    }list;
    void taolist(list &l)
    {
    	l.head=NULL;
    	l.tail=NULL;
    }
    node *taonode(toado &a)
    {
    	node *tam;
    	tam=new node;
    	if(tam==NULL)
    		exit(1);
    	else
    	{
    		tam->info=a;
    		tam->next=NULL;
    	}
    	return tam;
    }
    void nhaptoado(toado &a)
    {
    	printf("nhap toa do x:=");
    	scanf("%d",&a.x);
    	printf("nhap toa do y:=");
    	scanf("%d",&a.y);
    }
    void themnode(list &l,node *p)
    {
    	if(l.head==NULL)
    	{
    		l.head=p;
    		l.tail=l.head;
    	}
    	else
    	{
    		l.tail->next=p;
    		l.tail=p;
    	}
    }
    void nhapdstoado(list &l)
    {
    	toado a;
    	int n;
    	printf("nhap so luong diem:=");
    	scanf("%d",&n);
    	for(int i=0;i<n;i++)
    	{
    		printf("nhap toa do diem thu %d: ",i+1);
    		nhaptoado(a);
    		themnode(l,taonode(a));
    	}
    }
    void xoadau(list &l)
    {
    	node *p;
    	if(l.head!=NULL)
    	{
    		p=l.head;
    		l.head=p->next;
    		delete p;
    		if(l.head==NULL)
    			l.tail=NULL;
    	}
    	else
    		printf("danh sach rong: ");
    }
    void xoa(list l,toado b)
    {
    	node *p,*q;
    	p=l.head;
    	if((p->info.x==b.x)&&(p->info.y=b.y))
    	{
    		toado c;
    		c=p->info;
    		l.head=p->next;
    		delete p;
    		if(l.head==NULL)
    			l.tail=NULL;
    	}
    	else
    	{
    		while(p!=l.tail)
    		{
    			q=p->next;
    			if((q->info.x==b.x)&&(q->info.y=b.y))
    			{
    				toado c=q->info;
    				p->next=q->next;
    				delete q;
    				break;
    			}
    			else
    			{
    				p=q;
    			}
    		}
    		if(p=l.tail)
    			printf("Khong tim thay phan tu can xoa:" );
    	}
    
    }
    void intoado(list &l)
    {
    	node *tam;
    	tam=l.head;
    	int dem=1;
    	while(tam)
    	{
    		printf("TOA DO DIEM THU %d:(%d,%d)\n",dem,tam->info.x,tam->info.y);
    		tam=tam->next;
    		dem++;
    	}
    }
    void hoanvi(toado &a,toado &b)
    {
    	toado tam;
    	tam=a;
    	a=b;b=tam;
    }
    void sapxep(list &l)
    {
    	node *p,*q;
    	p=l.head;
    	while(p!=l.tail)
    	{
    		q=p->next;
    		while(q)
    		{
    			if(p->info.x>q->info.x)
    				hoanvi(p->info,q->info);
    			q=q->next;
    		}
    		p=p->next;
    	}		
    }
    void main()
    {
    	toado b;
    	list l;
    	taolist(l);
    	nhapdstoado(l);
    	intoado(l);
    	printf("nhap toa do can xoa: ");
    	nhaptoado(b);
    	xoa(l,b);
    	/*sapxep(l);*/
    	intoado(l);
    	getch();
    }
    Hà Tĩnh Quê Choa:sunglasses:
    FACEBOOK

    Comment


    • #17
      kaka bạn sai một số cái trong hàm xóa như sau:
      những chỗ đỏ là mình đã sửa rồi đó.
      mình chạy rồi mà không có báo lỗi chắc là đúng rồi hihi
      void xoa(list &l,toado b)
      if((p->info.x==b.x)&&(p->info.y==b.y))
      if(p==l.tail)
      hàm hoàn chỉnh như sau nè
      PHP Code:
      #include"conio.h"
      #include"stdio.h"
      #include"stdlib.h"
      typedef struct toado
      {
          
      int x;
          
      int y;
      }
      toado;
      typedef struct node
      {
          
      toado info;
          
      struct node *next;
      }
      node;
      typedef struct list
      {
          
      node *head;
          
      node *tail;
      }list;
      void taolist(list &l)
      {
          
      l.head=NULL;
          
      l.tail=NULL;
      }
      node *taonode(toado &a)
      {
          
      node *tam;
          
      tam=new node;
          if(
      tam==NULL)
              exit(
      1);
          else
          {
              
      tam->info=a;
              
      tam->next=NULL;
          }
          return 
      tam;
      }
      void nhaptoado(toado &a)
      {
          
      printf("nhap toa do x:=");
          
      scanf("%d",&a.x);
          
      printf("nhap toa do y:=");
          
      scanf("%d",&a.y);
      }
      void themnode(list &l,node *p)
      {
          if(
      l.head==NULL)
          {
              
      l.head=p;
              
      l.tail=l.head;
          }
          else
          {
              
      l.tail->next=p;
              
      l.tail=p;
          }
      }
      void nhapdstoado(list &l)
      {
          
      toado a;
          
      int n;
          
      printf("nhap so luong diem:=");
          
      scanf("%d",&n);
          for(
      int i=0;i<n;i++)
          {
              
      printf("nhap toa do diem thu %d: ",i+1);
              
      nhaptoado(a);
              
      themnode(l,taonode(a));
          }
      }
      void xoadau(list &l)
      {
          
      node *p;
          if(
      l.head!=NULL)
          {
              
      p=l.head;
              
      l.head=p->next;
              
      delete p;
              if(
      l.head==NULL)
                  
      l.tail=NULL;
          }
          else
              
      printf("danh sach rong: ");
      }
      void xoa(list &l,toado b)///////
      {
          
      node *p,*q;
          
      p=l.head;
          if((
      p->info.x==b.x)&&(p->info.y==b.y))////
          
      {
              
      toado c;
              
      c=p->info;
              
      l.head=p->next;
              
      delete p;
              if(
      l.head==NULL)
                  
      l.tail=NULL;
          }
          else
          {
              while(
      p!=l.tail)
              {
                  
      q=p->next;
                  if((
      q->info.x==b.x)&&(q->info.y=b.y))
                  {
                      
      toado c=q->info;
                      
      p->next=q->next;
                      
      delete q;
                      break;
                  }
                  else
                  {
                      
      p=q;
                  }
              }
              if(
      p==l.tail)//////////////
                  
      printf("Khong tim thay phan tu can xoa:\n" );
          }

      }
      void intoado(list &l)
      {
          
      node *tam;
          
      tam=l.head;
          
      int dem=1;
          while(
      tam)
          {
              
      printf("TOA DO DIEM THU %d:(%d,%d)\n",dem,tam->info.x,tam->info.y);
              
      tam=tam->next;
              
      dem++;
          }
      }
      void hoanvi(toado &a,toado &b)
      {
          
      toado tam;
          
      tam=a;
          
      a=b;b=tam;
      }
      void sapxep(list &l)
      {
          
      node *p,*q;
          
      p=l.head;
          while(
      p!=l.tail)
          {
              
      q=p->next;
              while(
      q)
              {
                  if(
      p->info.x>q->info.x)
                      
      hoanvi(p->info,q->info);
                  
      q=q->next;
              }
              
      p=p->next;
          }        
      }
      void main()
      {
          
      toado b;
          list 
      l;
          
      taolist(l);
          
      nhapdstoado(l);
          
      intoado(l);
          
      printf("nhap toa do can xoa: ");
          
      nhaptoado(b);
          
      xoa(l,b);
          
      /*sapxep(l);*/
          
      intoado(l);
          
      getch();

      :love:
      Tương lai khóc hay cười phụ thuộc vào độ lười của quá khứ.
      :cry:

      Comment


      • #18
        thank bạn nhiều nhé ! sai cơ bản quá :smile:
        Hà Tĩnh Quê Choa:sunglasses:
        FACEBOOK

        Comment


        • #19
          Trong danh sách liên kết mình thấy cái hàm Delete một Node
          có khóa k nó dài quá nên mình có làm thử theo dạng của cây. Mọi người xem thử cái hàm này đúng không nha. Mình viết cái này trong máy mình rồi nhưng không biết giờ ngồi ghi lại có giống không nữa (hi vong là đúng).
          Code:
          void DeleteOneNode(Node * &a, int k)
          {
                if (a)
                {
                     if (a->info!=k) DeleteOneNode(a->pNext,k);
                     else
                     {
                             Node *p=a;
                             p->info=a->info;
                             a=a->pNext;
                             delete p;
                             p=NULL;
                      }
                 }
          }
          Note: Khi gọi hàm thì a phải là pHead của List luôn nha.
          Last edited by 11520473; 13-06-2012, 16:22.
          http://picshome.com/getfile.php?id=1...ame=MySign.png

          Comment


          • #20
            Originally posted by 11520473 View Post
            Trong danh sách liên kết mình thấy cái hàm Delete một Node
            có khóa k nó dài quá nên mình có làm thử theo dạng của cây. Mọi người xem thử cái hàm này đúng không nha. Mình viết cái này trong máy mình rồi nhưng không biết giờ ngồi ghi lại có giống không nữa (hi vong là đúng).
            Code:
            void DeleteOneNode(Node * &a, int k)
            {
                  if (a)
                  {
                       if (a->info!=k) DeleteOneNode(a->pNext,k);
                       else
                       {
                               Node *p=a;
                               p->info=a->info;
                               a=a->pNext;
                               delete p;
                               p=NULL;
                        }
                   }
            }
            Note: Khi gọi hàm thì a phải là pHead của List luôn nha.
            mình nghĩ có thể là sai haa. mình chưa nói đến nội dung nhưng mà mình nghĩ a như vây là một con trỏ kiểu node thì sao lại là & được nữa nhị. Xem lại ý tưởng xóa node có info=a trong danh sách liên kết đơn, mình nghĩ là không xài đệ quy được hay.
            Last edited by 11520139; 13-06-2012, 17:03.
            :love:
            Tương lai khóc hay cười phụ thuộc vào độ lười của quá khứ.
            :cry:

            Comment


            • #21
              Originally posted by 11520139 View Post
              mình nghĩ chắc chắn là sai cái na. mình chưa nói đến nội dung nhưng mà mình nghĩ a như vây là một con trỏ kiểu node thì sao lại là & được nữa nhị
              & ở đây là để nó thay đổi List sau khi delete xong. Bạn cứ test thử đi rồi cho mình biết kết quả. Vì thực ra hàm này mình đã chạy trong máy mình Ok rồi, nhưng khi viết lại hàm này trên forum thì lại không nhớ lắm, và cũng không có máy để test luôn.
              http://picshome.com/getfile.php?id=1...ame=MySign.png

              Comment


              • #22
                Originally posted by 11520473 View Post
                & ở đây là để nó thay đổi List sau khi delete xong. Bạn cứ test thử đi rồi cho mình biết kết quả. Vì thực ra hàm này mình đã chạy trong máy mình Ok rồi, nhưng khi viết lại hàm này trên forum thì lại không nhớ lắm, và cũng không có máy để test luôn.
                uhm đúng thật nhị nhưng bạn ơi nếu bạn sử dụng step into bạn sẽ biết nếu xóa phần tử cuối cùng thì không đúng nak. l.tail khi đó bằng NULL kìa. hiz cùng sửa thêm nhé
                :love:
                Tương lai khóc hay cười phụ thuộc vào độ lười của quá khứ.
                :cry:

                Comment


                • #23
                  Originally posted by 11520045 View Post
                  Bạn chắc chứ ???
                  chắc chắn luôn

                  Comment


                  • #24
                    Lỗi này mình đã từng gặp,lỗi là do nếu node gốc mà SNT thì sau khi xóa xong gốc là NULL nên nó sẽ báo lỗi truy cập,cách khắc phục là duyệt từ bên trái_->bên phải->gốc hoặc phải->trái->gốc,đảm bảo chạy trơn tru nếu như hàm xóa đúng,debug là biết
                    Originally posted by 11520537 View Post
                    đây là code của em trong khi thực hành cây nhị phân tìm kiếm, em gặp phải vấn đề code của hàm xoá số nguyên tố trong cây(removenguyento), mong anh chị sửa lỗi ngữ nghĩa dùm!
                    PHP Code:
                    // cây nhị phân tìm kiếm.cpp : Defines the entry point for the console application.
                    //

                    #include "stdafx.h"
                    #include "stdio.h"
                    #include "conio.h"
                    #include "stdlib.h"
                    typedef struct tagnode
                    {
                        
                    int data;
                        
                    struct tagnode *R;
                        
                    struct tagnode *L;
                    }
                    node;
                    typedef nodetree;
                    void creattree(tree &t)
                    {
                        
                    NULL;
                    }
                    nodecreatnode(int x)
                    {
                        
                    node *p;
                        
                    p= new node;
                        
                    p->data x;
                        
                    p->p->NULL;
                        return 
                    p;
                    }
                    void addnode(tree &t,node *p)
                    {
                        if(
                    == NULL)
                            
                    p;
                        else
                        {
                            if(
                    t->data p->data)
                                
                    addnode(t->L,p);
                            else
                                if(
                    t->data p->data)
                                    
                    addnode(t->R,p);
                                else
                                    exit(
                    1);
                        }
                    }
                    void changeminR(tree &p,tree &t)
                    {
                        if(
                    t->!= NULL)
                            
                    changeminR(p,t->L);
                        else
                        {
                            
                    p->data t->data;
                            
                    p=t;
                            
                    t=t->R;
                        }
                    }
                    void removenode(tree &t,int x)
                    {
                        if(
                    != NULL)
                        {
                            if(
                    t->data x)
                                
                    removenode(t->R,x);
                            else
                            {
                                if(
                    t->data x)
                                    
                    removenode(t->L,x);
                                else
                    //tim thay x trong cay
                                
                    {
                                    
                    node *p;
                                    
                    p=t;//t,p cung tro toi 1 phan tu
                                    
                    if(t->== NULL)//co 1 nut con
                                        
                    t=t->R;
                                    else
                                    {
                                        if(
                    t->== NULL)//co 1 nut con
                                            
                    t=t->L;
                                        else
                    //co 2 nut con
                                            
                    changeminR(p,t->R);
                                    }
                                    
                    delete(p);
                                }
                            }
                        }
                        else
                            
                    printf("khong tim thay phan tu de xoa!");
                    }
                    nodesearchnode(tree t,int x)
                    {
                        if(
                    != NULL)
                            if(
                    t->data == x)
                                return 
                    t;
                            else
                                if(
                    t->data x)
                                    return 
                    searchnode(t->R,x);
                                else
                                    return 
                    searchnode(t->L,x);
                        return 
                    NULL;
                    }
                    nodenodemax(tree t)
                    {
                        if(
                    != NULL)
                            if(
                    t->== NULL)
                                return 
                    t;
                            else
                                return 
                    nodemax(t->R);
                        return 
                    NULL;
                    }
                    nodenodemin(tree t)
                    {
                        if(
                    != NULL)
                            if(
                    t->== NULL)
                                return 
                    t;
                            else
                                return 
                    nodemin(t->L);
                        return 
                    NULL;
                    }    
                    void inputtree(tree &t)
                    {
                        
                    int x;
                        
                    node *p;
                        
                    creattree(t);
                        
                    printf("moi ban nhap cac phan tu cho cay ket thuc bang so 0:\n");
                        do
                        {
                            
                    scanf("%3d",&x);
                            if(
                    == 0)
                                break;
                            
                    creatnode(x);
                            
                    addnode(t,p);
                        }while(
                    != 0);
                    }
                    int demnode(tree t)
                    {
                        
                    int dem =0;
                        if(
                    t!=NULL)
                            
                    dem =  demnode(t->L) + demnode(t->R);
                        return 
                    dem;
                    }
                    int sumnode(tree t)
                    {
                        
                    int sum 0;
                        if(
                    t!=NULL)
                            
                    sum =  t->data sumnode(t->L) + sumnode(t->R);
                        return 
                    sum;
                    }
                    int isnodechan(int x)
                    {
                        if(
                    x%== 0)
                            return 
                    1;
                        else
                            return 
                    0;
                    }
                    int demnodechan(tree t)
                    {
                        
                    int dem=0;
                        if(
                    t!=NULL)
                            if(
                    isnodechan(t->data) == 1)
                                
                    dem demnodechan(t->L) + demnodechan(t->R);
                            else
                                
                    dem demnodechan(t->L) + demnodechan(t->R);
                        return 
                    dem;
                    }
                    int sumnodechan(tree t)
                    {
                        
                    int sum=0;
                        if(
                    t!=NULL)
                            if(
                    isnodechan(t->data) == 1)
                                
                    sum t->data sumnodechan(t->L) + sumnodechan(t->R);
                            else
                                
                    sum sumnodechan(t->L) + sumnodechan(t->R);
                        return 
                    sum;
                    }
                    int isnutla(tree t)//kiem tr co phai nut la hay khong
                    {
                        if((
                    != NULL) && (t->== NULL) && (t->== NULL))
                            return 
                    1;
                        else
                            return 
                    0;
                    }
                    int demnodela(tree t)//dem nut la
                    {
                        
                    int dem 0;
                        if(
                    != NULL)
                        {
                            if(
                    isnutla(t) == 1)
                                
                    dem++;
                            else
                                
                    dem =  demnodela(t->L) + demnodela(t->R);
                        }
                        return 
                    dem;
                    }
                    int sumnodela(tree t)//tong cac nut la
                    {
                        
                    int sum=0;
                        if(
                    != NULL)
                            if(
                    isnutla(t) == 1)
                                
                    sum sum t->data
                            else
                                
                    sum sumnodela(t->L) + sumnodela(t->R);
                        return 
                    sum;
                    }
                    int isnode1con(tree t)
                    {
                        if(
                    != NULL)
                            if(((
                    t->== NULL) && (t->!= NULL)) || ((t->!= NULL) && (t->== NULL)))
                                return 
                    1;
                        return 
                    0;
                    }
                    int demnode1con(tree t)
                    {
                        
                    int dem=0;
                        if(
                    != NULL)
                            if(
                    isnode1con(t) == 1)
                                
                    dem +demnode1con(t->L) + demnode1con(t->R); 
                            else
                                
                    dem demnode1con(t->L) + demnode1con(t->R);
                        return 
                    dem;
                    }
                    int sumnode1con(tree t)
                    {
                        
                    int s=0;
                        if(
                    != NULL)
                            if(
                    isnode1con(t) == 1)
                                
                    =  t->data sumnode1con(t->L) + sumnode1con(t->R);
                            else
                                
                    =  sumnode1con(t->L) + sumnode1con(t->R);
                        return 
                    s;
                    }
                    int isnode2con(tree t)
                    {
                        if((
                    t!=NULL) && (t->!= NULL) && (t->!= NULL))
                            return 
                    1;
                        else
                            return 
                    0;
                    }
                    int demnode2con(tree t)
                    {
                        
                    int dem=0;
                        if(
                    t!=NULL)
                            if(
                    isnode2con(t)==1)
                                
                    dem demnode2con(t->L) + demnode2con(t->R);
                            else
                                
                    dem demnode2con(t->L) + demnode2con(t->R);
                        return 
                    dem;
                    }
                    int sumnode2con(tree t)
                    {
                        
                    int sum 0;
                        if(
                    t!=NULL)
                            if(
                    isnode2con(t)==1)
                                
                    sum =   t->data sumnode2con(t->L) + sumnode2con(t->R);
                            else
                                
                    sum =  sumnode2con(t->L) + sumnode2con(t->R);
                        return 
                    sum;
                    }
                    int max(int a,int b)
                    {
                        if(
                    a>b)
                            return 
                    a;
                        else 
                            return 
                    b;
                    }
                    int hight(tree t)
                    {
                        
                    int h=0;
                        if(
                    t!=NULL)
                        {
                            
                    h++;
                            
                    max(hight(t->L),hight(t->R));
                        }
                        return 
                    h;
                    }
                    int demlever(tree t,int x)
                    {
                        
                    int muc=0;
                        if(
                    t->data x)
                            {
                                
                    muc=demlever(t->R,x);
                                
                            }
                        else
                            if(
                    t->data x)
                            {
                                
                    muc demlever(t->L,x);
                                
                            }
                        return 
                    muc;
                    }
                    int isnguyento(int x)
                    {
                        
                    int i;
                        if(
                    x>=2)
                        {
                            for(
                    i=2;i<x;i++)
                                if(
                    x%== 0)
                                    break;
                                if(
                    x==i)
                                    return 
                    1;
                        }
                        return 
                    0;
                    }
                    void removenguyento(tree &t)
                    {
                        if(
                    t!=NULL)
                        {
                            if(
                    isnguyento(t->data)==1)
                                
                    removenode(t,t->data);
                            
                    removenguyento(t->L);
                            
                    removenguyento(t->R);
                        }
                    }
                    void outRNL(tree t)
                    {
                        if(
                    != NULL)
                        {
                            
                    outRNL(t->R);
                            
                    printf("%3d",t->data);
                            
                    outRNL(t->L);
                        }
                    }
                    void outLNR(tree t)
                    {
                        if(
                    != NULL)
                        {
                            
                    outLNR(t->L);
                            
                    printf("%3d",t->data);
                            
                    outLNR(t->R);
                        }
                    }
                    void outNRL(tree t)
                    {
                        if(
                    != NULL)
                        {
                            
                    printf("%3d",t->data);
                            
                    outNRL(t->R);
                            
                    outNRL(t->L);
                        }
                    }
                    void outNLR(tree t)
                    {
                        if(
                    != NULL)
                        {
                            
                    printf("%3d",t->data);
                            
                    outNLR(t->L);
                            
                    outNLR(t->R);
                        }
                    }
                    void main()
                    {
                        
                    tree t;
                        
                    node *p;
                        
                    int x,k;
                        
                    inputtree(t);
                        
                    printf("\ncay duoc in ra kieu LNR:\n");
                        
                    outLNR(t);
                        
                    printf("\nso nut trong cay la: %d ",demnode(t));
                        
                    printf("\ntong cac nut  trong cay la: %d ",sumnode(t));
                        
                    printf("\nso nut chan trong cay la: %d ",demnodechan(t));
                        
                    printf("\ntong cac nut chan trong cay la: %d ",sumnodechan(t));
                        
                    printf("\nso nut la trong cay la: %d ",demnodela(t));
                        
                    printf("\ntong cac nut la trong cay la: %d ",sumnodela(t));
                        
                    printf("\nso nut  1 con trong cay la: %d ",demnode1con(t));
                        
                    printf("\ntong so nut  1 con trong cay la: %d ",sumnode1con(t));
                        
                    printf("\nso nut  2 con trong cay la: %d ",demnode2con(t));
                        
                    printf("\ntong so nut 2 con trong cay la: %d ",sumnode2con(t));
                        
                    printf("\nchieu cao cua cay la:  %d",hight(t));
                        
                    printf("\nkhoa lon nhat cua cay la:");
                        if(
                    nodemax(t) == NULL)
                            
                    printf("cay rong!");
                        else
                            
                    printf("%d",nodemax(t)->data);
                        
                    printf("\nkhoa nho nhat cua cay la:");
                        if(
                    nodemin(t) == NULL)
                            
                    printf("cay rong!");
                        else
                            
                    printf("%d",nodemin(t)->data);
                        
                    removenguyento(t);
                        
                    printf("\ncay duoc in ra kieu LNR sau khi xoa nguyen to:\n");
                        
                    outLNR(t);
                        
                    printf("\nmoi ban nhap phan tu muon xoa:\n");
                        
                    scanf("%d",&x);
                        
                    removenode(t,x);
                        
                    printf("cay duoc in ra kieu LNR:\n");
                        
                    outLNR(t);
                        
                    printf("\nmoi ban nhap phan tu muon xac dinh muc hay do sau:\n");
                        
                    scanf("%d",&k);
                        
                    searchnode(t,k);
                        if(
                    == NULL)
                            
                    printf("khong tim thay!");
                        else
                        {
                            
                    printf("tim thay\n");
                            
                    printf("muc hay do sau cua phan tu vua nhap la:  %d",demlever(t,k));
                        }
                        
                    getch();

                    còn đây là code tách ra:

                    PHP Code:
                    int isnguyento(int x)
                    {
                        
                    int i;
                        if(
                    x>=2)
                        {
                            for(
                    i=2;i<x;i++)
                                if(
                    x%== 0)
                                    break;
                                if(
                    x==i)
                                    return 
                    1;
                        }
                        return 
                    0;
                    }
                    void removenguyento(tree &t)
                    {
                        if(
                    t!=NULL)
                        {
                            if(
                    isnguyento(t->data)==1)
                                
                    removenode(t,t->data);
                            
                    removenguyento(t->L);
                            
                    removenguyento(t->R);
                        }

                    Hà Tĩnh Quê Choa:sunglasses:
                    FACEBOOK

                    Comment

                    LHQC

                    Collapse
                    Working...
                    X