PDA

View Full Version : آموزش: الگوریتمی در ساختمان داده



farshidshd
جمعه 22 آبان 1388, 13:13 عصر
سلام دوستان محترم

کمک کنین تا این 3 تا الگوریتم رو بنویسم

1-الگوریتمی که یک درخت دودویی را کپی کند

2-درخت دودویی( پیمایش ) را آینه ای کند... مثلا LVR رو بکنه RVL یعنی اول زیر درخت راست رو پیماش کنه بعد چپ

3-الگوریتمی که عمق درخت دودویی را بدست آورد


البته الگوریتم 3 رو از اینجا پیدا کردم. ببینین درسته؟


function BinaryTreeDepth(Tree): Integer
var
LeftDepth, RightDepth: Integer
begin
if IsBranch(Tree.Left) then
LeftDepth := BinarTreeDepth(Tree.Left)
else
LeftDepth := 0
if IsBranch(Tree.Right) then
RightDepth := BinarTreeDepth(Tree.Right)
else
RightDepth := 0
if LeftDepth > RightDepth then
return LeftDepth + 1
else
return RightDepth + 1
end



ممنون میشم کمکم کنید

farshidshd
شنبه 23 آبان 1388, 14:44 عصر
کسی اگه میدونه کمکم کنه لطفا

farshidshd
سه شنبه 26 آبان 1388, 12:57 عصر
خودم کمک میکنم

کپی کردن::

node copy(node *T)
{
node *st
if (t != null)
{
st= new (node);
st -> left=copy(t->left)
st->right=copy(t->right)
st->data=t->data
return st;
else return null;
}






اینم معکوس یا آینه ای::


node c(node *T)
{
node *st
if (t != null)
{
st= new (node);
st -> left=c(t->right)
st->right=c(t->left)
st->data=t->data
return st;
else return null;
}


واقعا هیچکی تو این سایت کمک نمیکنه