Kênh Tên Miền chuyên cung cấp tên miền đẹp, giá rẻ! Hãy liên hệ kỹ thuật: 0914205579 - Kinh doanh: 0912191357 để được tư vấn, hướng dẫn miễn phí, Cảm ơn quý khách đã ủng hộ trong thời gian qua!
kiem tien, kiem tien online, kiem tien truc tuyen, kiem tien tren mang
Thứ Bảy, 19 tháng 5, 2012


#include "stdafx.h"
#include <stdio.h>
#include<conio.h>

struct Node
{
    Node* pLeft;
    Node* pRight;
    int iX;
};

typedef Node* Tree;

Node* TaoNode(int X)

{
    Node* p = new Node;
    if (p == NULL)
      return NULL;
    p->pLeft = NULL;
    p->pRight = NULL;
    p->iX=X;
    return p;
}

void ThemNodeVaoCay(Node* p, Tree &c)

{

    if (c == NULL)//nếu cây rỗng

        c = p;

    else //cây khác rỗng

    {
        if (p->iX < c->iX)
            ThemNodeVaoCay(p,c->pLeft);
        else if (p->iX > c->iX)
            ThemNodeVaoCay(p,c->pRight);
        else
            return;
    }

}

void Nhap(Tree &c)

{
    int chon = 0;
    do
    {
        int x;

        printf("\n Nhap nut : ");

        scanf_s("%d",&x);

        Node* p = TaoNode(x);

        ThemNodeVaoCay(p,c);

        printf(" Nhap 1 de tiep tuc nhap nut !   ");

        scanf_s("%d",&chon);

    }while(chon==1);

}


// Xuat gia tri nut lon hon a va nho hon b
void Xuat(Tree c, int a, int b)

{
int dem=0;
    if (c!=NULL)

    {

        if (c->pLeft != NULL)

            Xuat(c->pLeft,a,b);

        if (a<c->iX && c->iX<b)
{
printf("\n nut %d co dia chi %d ",c->iX,&c);
}
        if (c->pRight != NULL)

            Xuat(c->pRight,a,b);

    }
}

void NhapXY(int &a, int &b)

{

    printf("Nhap a: ");

    scanf_s("%d",&a);

    printf("Nhap b: ");

    scanf_s("%d",&b);

}

void main()
{

    Tree c = NULL;

    Nhap(c);

    int a,b;

printf("\n Nhap khoang [a,b] : \n");
    NhapXY(a,b);
    printf("\n Dia chi nut thuoc khoang [%d,%d] : ",a,b);
    Xuat(c,a,b);

getch();
}
19 May 2012

0 nhận xét:

Đăng nhận xét

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

domain, domain name, premium domain name for sales

Popular Posts