Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. //Fa magassaga
  2.  
  3. height :: (Tree a) -> Int
  4. height Empty = 0
  5. height (Node a _ b)
  6. | height a == height b = (height a) + 1
  7. | height b > 0 = (height b) + 1
  8. | height a > 0 = (height a) + 1
  9.  
  10. //Fa ferdesege
  11.  
  12. skew :: (Tree a) -> Int
  13. skew Empty = 0
  14. skew (Node a _ b) = (height a) - (height b)
  15.  
  16. //Jobbra forgatas
  17.  
  18. rightRot :: (Tree a) -> Tree a
  19. rightRot (Node (Node a x b) y c) = Node a x (Node b y c)
  20.  
  21. //Balra forgatas
  22.  
  23. leftRot :: (Tree a) -> Tree a
  24. leftRot (Node a x (Node b y c)) = Node (Node a x b) y c
  25.  
  26. //Balra-jobbra forgatas
  27.  
  28. leftRightRot :: (Tree a) -> Tree a
  29. leftRightRot (Node x z d) = rightRot(Node (leftRot x) z d)
  30.  
  31. //Jobbra-balra forgatas
  32.  
  33. rightLeftRot :: (Tree a) -> Tree a
  34. rightLeftRot (Node x z d) = leftRot(Node x z (rightRot d))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement