Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program B_S_T;
- procedure BST(T,x);
- begin
- P:=T; Q:=nil {Q luôn là cha của P}
- while P# nil do
- begin
- Q:=P;
- if x=P.data then
- break;
- if x<P.data then P:=P.P_L;
- if x>P.data then P:=P.P_R;
- end;
- if p=nil then {Không tìm thấy, bổ sung}
- begin
- new(p);
- p.data:=x;
- P.P_L:=nil;
- P.P_R:=nil
- if T=nil then T:=p
- else
- if(x<Q.data) then
- Q.P_L:=P
- else Q.P_R:=P;
- write('Không tìm thấy, đã bổ sung xong.');
- end;
- End;
- BEGIN
- Nhập cây;
- Nhập giá trị cần bổ sung X;
- BST(T,x);
- readln
- END.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement