Mavzu: binar daraxtlar bilan ishlash reja maʼlumotlar tuzilmasida Binar daraxtlar



Yüklə 252,68 Kb.
səhifə3/5
tarix28.01.2023
ölçüsü252,68 Kb.
#122694
1   2   3   4   5
malumotlar tuzilmasi

Infiks oʻtish


Infiks ifodasi chop etilganda, har bir ifodaning boshiga va oxiriga ochilish va yopish qavslari qoʻshilishi kerak. Har bir pastki daraxt pastki ifodani ifodalaganligi sababli, uning boshida ochilish qavslari va barcha sonlarni qayta ishlagandan soʻng, yopish qavslari chop etiladi.
Psevdokod:
Algoritm infix ( daraxt )
Algorithm infix (tree)
/*Print the infix expression for an expression tree.
Pre : tree is a pointer to an expression tree
Post: the infix expression has been printed*/
if (tree not empty)
if (tree token is operator)
print (open parenthesis)
end if
infix (tree left subtree)
print (tree token)
infix (tree right subtree)
if (tree token is operator)
print (close parenthesis)
end if
end if
end infix

Postfiksdan oʻtish[tahrir | manbasini tahrirlash]


Postfiks ifodasi har qanday binar daraxtning asosiy buyruqdab keyingi oʻtish orqali hosil boʻladi. Qavslar kerak emas.
Algoritm postfiks ( daraxt )
Algorithm postfix (tree)
/*Print the postfix expression for an expression tree.
Pre : tree is a pointer to an expression tree
Post: the postfix expression has been printed*/
if (tree not empty)
postfix (tree left subtree)
postfix (tree right subtree)
print (tree token)
end if
end postfix

Prefiks oʻtish[tahrir | manbasini tahrirlash]


Psevdokod:
Algoritm prefiks ( daraxt )
Algorithm prefix (tree)
/*Print the prefix expression for an expression tree.
Pre : tree is a pointer to an expression tree
Post: the prefix expression has been printed*/
if (tree not empty)
print (tree token)
prefix (tree left subtree)
prefix (tree right subtree)
end if
end prefix

Yüklə 252,68 Kb.

Dostları ilə paylaş:
1   2   3   4   5




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©muhaz.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin