944,118 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1484
  • C++ RSS
Aug 20th, 2007
0

splaying algorithm

Expand Post »
hi, i recently heard about splay trees

and i am searching for a splaying algorithm...,i ve found one
but it isn't very easy to understand....so if anyone has to share an implementation followed by a short explanation it would be great!

PS: i 've undestand the basic concepts like zig, zig-zig, zig-zag but still the implementations out on the web utilize things that don't make much sense...

here is an alogorithm i found that i don't understand

c++ Syntax (Toggle Plain Text)
  1. void SplayTree::splay( const int & x, BinaryNode* t )
  2. {
  3. BinaryNode *leftTreeMax, *rightTreeMin;
  4. static BinaryNode header;
  5.  
  6. header.left = header.right = nullNode;
  7. leftTreeMax = rightTreeMin = &header;
  8.  
  9. nullNode->element = x; // Guarantee a match
  10.  
  11. for( ; ; )
  12. if( x < t->element )
  13. {
  14. if( x < t->left->element )
  15. rotateWithLeftChild( t );
  16. if( t->left == nullNode )
  17. break;
  18. // Link Right
  19. rightTreeMin->left = t;
  20. rightTreeMin = t;
  21. t = t->left;
  22. }
  23. else if( t->element < x )
  24. {
  25. if( t->right->element < x )
  26. rotateWithRightChild( t );
  27. if( t->right == nullNode ) //to neo t pou irthe apo to rotate....
  28. break;
  29. // Link Left
  30. leftTreeMax->right = t;
  31. leftTreeMax = t;
  32. t = t->right;
  33. }
  34. else
  35. break;
  36.  
  37. leftTreeMax->right = t->left;
  38. rightTreeMin->left = t->right;
  39. t->left = header.right;
  40. t->right = header.left;
  41. }

if anyone can shed some light, i would be gratefull!
Similar Threads
Reputation Points: 23
Solved Threads: 12
Posting Whiz in Training
n.aggel is offline Offline
202 posts
since Nov 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: How to sort alphabet
Next Thread in C++ Forum Timeline: Plz Solve this problem...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC