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


Download 252.68 Kb.
bet3/5
Sana28.01.2023
Hajmi252.68 Kb.
#1136223
1   2   3   4   5
Bog'liq
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

Download 252.68 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling