splaying algorithm

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2006
Posts: 202
Reputation: n.aggel is an unknown quantity at this point 
Solved Threads: 11
n.aggel's Avatar
n.aggel n.aggel is offline Offline
Posting Whiz in Training

splaying algorithm

 
0
  #1
Aug 20th, 2007
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

  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!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC