Splay Tree C++, Please helping me

Hi, I am learning how to build my splay tree with C++.
I found some source on line.
http://www.cplusplus.happycodings.com/Data-Structures-and-Algorithm-Analysis-in-C++/code79.html
http://www.cplusplus.happycodings.com/Data-Structures-and-Algorithm-Analysis-in-C++/code80.html

I pasted pieces of codes and then ask some questions.
1
2
3
4
5
6
7
8
9
10
11
12
/**
* Construct the tree.
*/
template <class Comparable>
SplayTree<Comparable>::SplayTree( const Comparable & notFound )
          : ITEM_NOT_FOUND( notFound )
        {
            nullNode = new BinaryNode<Comparable>;
            nullNode->left = nullNode->right = nullNode;
            nullNode->element = notFound;
            root = nullNode;
        }

Question:
why the nullNode's left child and right child are both equal nullNode. Can you explain for me why and how the codes works like that.


Topic archived. No new replies allowed.