# GÓC SÁNG TẠO > Khu vực lập trình > C/C++ >  cây nhị phân tìm kiếm : duyệt cây theo mức

## ghostdarkgs

Mình đang học cây nhị phân tìm kiếm phần duyệt cây theo mức thầy giáo giảng mình ko hiểu lắm, bạn nào có đoạn code duyệt cây theo mức gửi cho minh được ko? thanks you! trước nhé.
:wub::wub::d

----------


## phatthu

Cái này là C nhé bạn, bạn không nói rõ là bạn đang học java hay C hay C++ nên mình post C cho bạn, nếu có cần về gì PM cho mình sau :

Code :


```

[COLOR=#000000][/COLOR][COLOR=#FF8000]#include <stdio.h>#include<stdlib.h>#include<conio.h>[/COLOR][COLOR=#0000BB]typedef int element_type[/COLOR][COLOR=#007700];[/COLOR][COLOR=#0000BB]typedef struct node [/COLOR][COLOR=#007700]{  [/COLOR][COLOR=#0000BB]element_type element[/COLOR][COLOR=#007700];  [/COLOR][COLOR=#0000BB]struct node [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]left[/COLOR][COLOR=#007700], *[/COLOR][COLOR=#0000BB]right[/COLOR][COLOR=#007700];} [/COLOR][COLOR=#0000BB]NODE[/COLOR][COLOR=#007700];[/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700];[/COLOR][COLOR=#0000BB]void khoi_tao_cay[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]** [/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]){  *[/COLOR][COLOR=#0000BB]root [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]NULL[/COLOR][COLOR=#007700];}[/COLOR][COLOR=#0000BB]void insert[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]**[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]){  if ([/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]element [/COLOR][COLOR=#007700]< (*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700])->[/COLOR][COLOR=#0000BB]element[/COLOR][COLOR=#007700])    if ((*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700])->[/COLOR][COLOR=#0000BB]left[/COLOR][COLOR=#007700])      [/COLOR][COLOR=#0000BB]insert[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700], &(*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700])->[/COLOR][COLOR=#0000BB]left[/COLOR][COLOR=#007700]);    else       (*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700])->[/COLOR][COLOR=#0000BB]left [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700];  else    if ((*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700])->[/COLOR][COLOR=#0000BB]right[/COLOR][COLOR=#007700])      [/COLOR][COLOR=#0000BB]insert[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700], &(*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700])->[/COLOR][COLOR=#0000BB]right[/COLOR][COLOR=#007700]);    else       (*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700])->[/COLOR][COLOR=#0000BB]right [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700];}[/COLOR][COLOR=#0000BB]void insert_node[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]element_type e[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]**[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]){   [/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700];   [/COLOR][COLOR=#0000BB]tmp [/COLOR][COLOR=#007700]= ([/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]*)[/COLOR][COLOR=#0000BB]malloc[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]sizeof[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]NODE[/COLOR][COLOR=#007700]));   [/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]element [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]e[/COLOR][COLOR=#007700];   [/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]left [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]NULL[/COLOR][COLOR=#007700];   [/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]right [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]NULL[/COLOR][COLOR=#007700];   if (*[/COLOR][COLOR=#0000BB]root [/COLOR][COLOR=#007700]== [/COLOR][COLOR=#0000BB]NULL[/COLOR][COLOR=#007700])     *[/COLOR][COLOR=#0000BB]root [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700];   else     [/COLOR][COLOR=#0000BB]insert[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]);}[/COLOR][COLOR=#0000BB]void nhap_cay[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]**[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]){  [/COLOR][COLOR=#0000BB]element_type e[/COLOR][COLOR=#007700];  do {    [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"Nhap element (-1 de ket thuc) : "[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]scanf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"%d"[/COLOR][COLOR=#007700], &[/COLOR][COLOR=#0000BB]e[/COLOR][COLOR=#007700]);    if ([/COLOR][COLOR=#0000BB]e [/COLOR][COLOR=#007700]!= -[/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700])      [/COLOR][COLOR=#0000BB]insert_node[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]e[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]);  } while ([/COLOR][COLOR=#0000BB]e [/COLOR][COLOR=#007700]!= -[/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700]);}[/COLOR][COLOR=#0000BB]void NLR[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]){  if ([/COLOR][COLOR=#0000BB]root [/COLOR][COLOR=#007700]!= [/COLOR][COLOR=#0000BB]NULL[/COLOR][COLOR=#007700])  {    [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"%d "[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]element[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]NLR[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]left[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]NLR[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]right[/COLOR][COLOR=#007700]);  }}[/COLOR][COLOR=#0000BB]void NRL[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]){  if ([/COLOR][COLOR=#0000BB]root [/COLOR][COLOR=#007700]!= [/COLOR][COLOR=#0000BB]NULL[/COLOR][COLOR=#007700])  {    [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"%d "[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]element[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]NRL[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]right[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]NRL[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]left[/COLOR][COLOR=#007700]);  }}[/COLOR][COLOR=#0000BB]void LNR[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]){  if ([/COLOR][COLOR=#0000BB]root [/COLOR][COLOR=#007700]!= [/COLOR][COLOR=#0000BB]NULL[/COLOR][COLOR=#007700])  {    [/COLOR][COLOR=#0000BB]LNR[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]left[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"%d "[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]element[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]LNR[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]right[/COLOR][COLOR=#007700]);  }}[/COLOR][COLOR=#0000BB]void LRN[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]){  if ([/COLOR][COLOR=#0000BB]root [/COLOR][COLOR=#007700]!= [/COLOR][COLOR=#0000BB]NULL[/COLOR][COLOR=#007700])  {    [/COLOR][COLOR=#0000BB]LRN[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]left[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]LRN[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]right[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"%d "[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]element[/COLOR][COLOR=#007700]);  }}[/COLOR][COLOR=#0000BB]void RNL[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]){  if ([/COLOR][COLOR=#0000BB]root [/COLOR][COLOR=#007700]!= [/COLOR][COLOR=#0000BB]NULL[/COLOR][COLOR=#007700])  {    [/COLOR][COLOR=#0000BB]RNL[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]right[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"%d "[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]element[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]RNL[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]left[/COLOR][COLOR=#007700]);  }}[/COLOR][COLOR=#0000BB]void RLN[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]){  if ([/COLOR][COLOR=#0000BB]root [/COLOR][COLOR=#007700]!= [/COLOR][COLOR=#0000BB]NULL[/COLOR][COLOR=#007700])  {    [/COLOR][COLOR=#0000BB]RLN[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]right[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]RLN[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]left[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"%d "[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]element[/COLOR][COLOR=#007700]);  }}[/COLOR][COLOR=#0000BB]void main[/COLOR][COLOR=#007700](){   [/COLOR][COLOR=#0000BB]khoi_tao_cay[/COLOR][COLOR=#007700](&[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]nhap_cay[/COLOR][COLOR=#007700](&[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"Duyet cay NLR : "[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]NLR[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"Duyet cay NRL : "[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]NRL[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"Duyet cay LNR : "[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]LNR[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"Duyet cay LRN : "[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]LRN[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"Duyet cay RNL : "[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]RNL[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"Duyet cay RLN : "[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]RLN[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]getch[/COLOR][COLOR=#007700]();}[/COLOR] 



```

----------


## tamdeptrai

*thanks*

mình đang học C mình wen ko nói rõ. Thanks you !:d

----------


## nanivodoi

> Cái này là C nhé bạn, bạn không nói rõ là bạn đang học java hay C hay C++ nên mình post C cho bạn, nếu có cần về gì PM cho mình sau :
> 
> Code :
> 
> 
> ```
> 
> [COLOR=#000000][/COLOR][COLOR=#FF8000]#include <stdio.h>#include<stdlib.h>#include<conio.h>[/COLOR][COLOR=#0000BB]typedef int element_type[/COLOR][COLOR=#007700];[/COLOR][COLOR=#0000BB]typedef struct node [/COLOR][COLOR=#007700]{  [/COLOR][COLOR=#0000BB]element_type element[/COLOR][COLOR=#007700];  [/COLOR][COLOR=#0000BB]struct node [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]left[/COLOR][COLOR=#007700], *[/COLOR][COLOR=#0000BB]right[/COLOR][COLOR=#007700];} [/COLOR][COLOR=#0000BB]NODE[/COLOR][COLOR=#007700];[/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700];[/COLOR][COLOR=#0000BB]void khoi_tao_cay[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]** [/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]){  *[/COLOR][COLOR=#0000BB]root [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]NULL[/COLOR][COLOR=#007700];}[/COLOR][COLOR=#0000BB]void insert[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]**[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]){  if ([/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]element [/COLOR][COLOR=#007700]< (*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700])->[/COLOR][COLOR=#0000BB]element[/COLOR][COLOR=#007700])    if ((*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700])->[/COLOR][COLOR=#0000BB]left[/COLOR][COLOR=#007700])      [/COLOR][COLOR=#0000BB]insert[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700], &(*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700])->[/COLOR][COLOR=#0000BB]left[/COLOR][COLOR=#007700]);    else       (*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700])->[/COLOR][COLOR=#0000BB]left [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700];  else    if ((*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700])->[/COLOR][COLOR=#0000BB]right[/COLOR][COLOR=#007700])      [/COLOR][COLOR=#0000BB]insert[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700], &(*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700])->[/COLOR][COLOR=#0000BB]right[/COLOR][COLOR=#007700]);    else       (*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700])->[/COLOR][COLOR=#0000BB]right [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700];}[/COLOR][COLOR=#0000BB]void insert_node[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]element_type e[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]**[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]){   [/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700];   [/COLOR][COLOR=#0000BB]tmp [/COLOR][COLOR=#007700]= ([/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]*)[/COLOR][COLOR=#0000BB]malloc[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]sizeof[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]NODE[/COLOR][COLOR=#007700]));   [/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]element [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]e[/COLOR][COLOR=#007700];   [/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]left [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]NULL[/COLOR][COLOR=#007700];   [/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]right [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]NULL[/COLOR][COLOR=#007700];   if (*[/COLOR][COLOR=#0000BB]root [/COLOR][COLOR=#007700]== [/COLOR][COLOR=#0000BB]NULL[/COLOR][COLOR=#007700])     *[/COLOR][COLOR=#0000BB]root [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700];   else     [/COLOR][COLOR=#0000BB]insert[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]tmp[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]);}[/COLOR][COLOR=#0000BB]void nhap_cay[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]**[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]){  [/COLOR][COLOR=#0000BB]element_type e[/COLOR][COLOR=#007700];  do {    [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"Nhap element (-1 de ket thuc) : "[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]scanf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"%d"[/COLOR][COLOR=#007700], &[/COLOR][COLOR=#0000BB]e[/COLOR][COLOR=#007700]);    if ([/COLOR][COLOR=#0000BB]e [/COLOR][COLOR=#007700]!= -[/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700])      [/COLOR][COLOR=#0000BB]insert_node[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]e[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]);  } while ([/COLOR][COLOR=#0000BB]e [/COLOR][COLOR=#007700]!= -[/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700]);}[/COLOR][COLOR=#0000BB]void NLR[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]){  if ([/COLOR][COLOR=#0000BB]root [/COLOR][COLOR=#007700]!= [/COLOR][COLOR=#0000BB]NULL[/COLOR][COLOR=#007700])  {    [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"%d "[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]element[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]NLR[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]left[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]NLR[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]right[/COLOR][COLOR=#007700]);  }}[/COLOR][COLOR=#0000BB]void NRL[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]){  if ([/COLOR][COLOR=#0000BB]root [/COLOR][COLOR=#007700]!= [/COLOR][COLOR=#0000BB]NULL[/COLOR][COLOR=#007700])  {    [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"%d "[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]element[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]NRL[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]right[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]NRL[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]left[/COLOR][COLOR=#007700]);  }}[/COLOR][COLOR=#0000BB]void LNR[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]){  if ([/COLOR][COLOR=#0000BB]root [/COLOR][COLOR=#007700]!= [/COLOR][COLOR=#0000BB]NULL[/COLOR][COLOR=#007700])  {    [/COLOR][COLOR=#0000BB]LNR[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]left[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"%d "[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]element[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]LNR[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]right[/COLOR][COLOR=#007700]);  }}[/COLOR][COLOR=#0000BB]void LRN[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]){  if ([/COLOR][COLOR=#0000BB]root [/COLOR][COLOR=#007700]!= [/COLOR][COLOR=#0000BB]NULL[/COLOR][COLOR=#007700])  {    [/COLOR][COLOR=#0000BB]LRN[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]left[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]LRN[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]right[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"%d "[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]element[/COLOR][COLOR=#007700]);  }}[/COLOR][COLOR=#0000BB]void RNL[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]){  if ([/COLOR][COLOR=#0000BB]root [/COLOR][COLOR=#007700]!= [/COLOR][COLOR=#0000BB]NULL[/COLOR][COLOR=#007700])  {    [/COLOR][COLOR=#0000BB]RNL[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]right[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"%d "[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]element[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]RNL[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]left[/COLOR][COLOR=#007700]);  }}[/COLOR][COLOR=#0000BB]void RLN[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]NODE [/COLOR][COLOR=#007700]*[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]){  if ([/COLOR][COLOR=#0000BB]root [/COLOR][COLOR=#007700]!= [/COLOR][COLOR=#0000BB]NULL[/COLOR][COLOR=#007700])  {    [/COLOR][COLOR=#0000BB]RLN[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]right[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]RLN[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]left[/COLOR][COLOR=#007700]);    [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"%d "[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]->[/COLOR][COLOR=#0000BB]element[/COLOR][COLOR=#007700]);  }}[/COLOR][COLOR=#0000BB]void main[/COLOR][COLOR=#007700](){   [/COLOR][COLOR=#0000BB]khoi_tao_cay[/COLOR][COLOR=#007700](&[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]nhap_cay[/COLOR][COLOR=#007700](&[/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"Duyet cay NLR : "[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]NLR[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"Duyet cay NRL : "[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]NRL[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"Duyet cay LNR : "[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]LNR[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"Duyet cay LRN : "[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]LRN[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"Duyet cay RNL : "[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]RNL[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]printf[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"Duyet cay RLN : "[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]RLN[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]root[/COLOR][COLOR=#007700]);   [/COLOR][COLOR=#0000BB]getch[/COLOR][COLOR=#007700]();}[/COLOR] 
> 
> ...


code gì mà rườm rà !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  !!!!!!!!!!

----------


## xuanninh164

Girl Hp!
Đặng Thị Miền
Tin trắc địa k52- đại học mỏ địa chất

----------


## Thinhquang75

*Đề bài hỏi là duyệt cây nhị phân theo mức (Không phải là LNR hay ...)!
Mình có ý tưởng thế này:
-Khai báo trong NODE một biến để chỉ mức ( hay hơn nữa để áp dụng cho những kiểu bải khác ta để biến này là thứ tự của NODE) của nó (cách nhập tùy vào từng loại cây ALV,...)
-Dùng LNR,...duyệt qua một lần. Những cái nào cùng mức thì cho vào một mảng.
-In các mảng theo mức là thỏa mãn đầu bài!
Mình thử duyệt cây theo mức theo kiểu như LNR nhưng không ra!
Bạn nào biết làm kiểu như LNR thì gửi code cho mình theo email này nha "[email protected]<script data-cfhash='f9e31' type="text/javascript">/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScr  ipt||function(){for(t=document.getElementsByTagNam  e('script'),e=t.length;e--if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if  (a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.l  ength-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString  (16)).slice(-2);p.replaceChild(document.createTextNode(decodeUR  IComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */</script>".
Cám ơn nhiều!
*

----------

