Languages :: Pascal :: procedure insert(var avl:avltree; e:stdelement; var inserted:boolean) AVL trees |
|||
| By: as_clouds |
Date: 20/04/2003 00:00:00 |
Points: 125 | Status: Answered Quality : Excellent |
|
hi, im takeing a data structrue course(in pascal) . In our text book i found the algorithm of the following procedure: procedure insert(var avl:avltree; e:stdelement; var inserted:boolean) ; requires:full(avl)false. results:if the avl didnt contain an element with the same value e.key prior to this operation,then avl containes e as its current element and inserted is true;otherwise inserted is false. the operation must yield a tree that is an AVL tree. u can find the algorithm in the following site-(slide number#26)- <A HREF="http://www.math.miami.edu/~sarkar/csc517/trees.PDF">http://www.math.miami.edu/~sarkar/csc517/trees.PDF</a> i wish i could find the code that matches this algorithm.:) thanx lolo |
|||
| By: mlmcc | Date: 20/04/2003 10:20:00 | Type : Comment |
|
| Is this a homework problem you are trying to solve? mlmcc |
|||
| By: VGR | Date: 20/04/2003 16:21:00 | Type : Comment |
|
| huh 1) WHY do you need AVL tree ? 2) DO YOU need AVL trees ? :D 3) if yes, then code for this I have 4) BUT it would eb better learning if you tried doing it yourself. Begin by implementing the AVL structure 8-)) |
|||
| By: as_clouds | Date: 21/04/2003 07:39:00 | Type : Comment |
|
| nope it not a homework mlmcc:) i uesually do my homeworks by my self . VGR 1)AVL might be a good option if i get to program later on,that's why i wana understand the hole idea, its good 2 exsamn various ways to solve a problem. 2)yes. 4)i already have the implemintation of a AVL trees structure, i just dont know how 2 get the code 2 walk back words inorder 2 change the balance along the search path & how to determin wich routaion 2 chosse(single or double). the structure implementaion is: type balance=(tallleft,equal,tall right) nodeptr=^node; node=recorde elt:stdelement; left:nopeptr; right:nodeptr; bal:balance; end; :) |
|||
| By: VGR | Date: 21/04/2003 08:21:00 | Type : Comment |
|
| good then 8-) a pal :D well, you have (classically) to : -create the node to add -add the node -re-balance the tree (rotation, etc) the best I can propose you is a copy from my book have a look here <A HREF="http://www.fecj.org/extra/AVL_1.jpg">http://www.fecj.org/extra/AVL_1.jpg</a> |
|||
| By: as_clouds | Date: 22/04/2003 07:47:00 | Type : Comment |
|
| thanx VGR that was great:),but i have a q: what dose the procedures RD(A) and RGD(A) do? lolo |
|||
| By: VGR | Date: 22/04/2003 07:58:00 | Type : Answer |
|
| good point ;-) RG = rotation on left RGD = rotation left + right they are : procedure RG (Var A : ARBRE); // ARBRE=tree var aux : ARBRE; Begin aux:=A^.d; A^.d:=aux^.g; aux^.g:=A; A:=aux; end; // RG procedure RD (Var A : ARBRE); var aux : ARBRE; Begin aux:=A^.g; A^.g:=aux^.d; aux^.d:=A; A:=aux; end; // RD procedure RGD (Var A : ARBRE); Begin RG(A^.g); RD(A); end; // RGD procedure RDG (Var A : ARBRE); Begin RD(A^.d); RG(A); end; // RDG |
|||
| By: as_clouds | Date: 22/04/2003 08:03:00 | Type : Comment |
|
| thanx VGR that was great:),but i have a q: what dose the procedures RD(A) and RGD(A) do? lolo |
|||
| By: as_clouds | Date: 22/04/2003 08:43:00 | Type : Comment |
|
| thank you VGR:D |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








