title: How should I approach the task of visualizing a B+ tree in C++?
body: <p>me and my friends have to implement a simple DBMS for our class on databases.</p>
  
  <p>The main part of DBMS is ready to use, which means that all the commands(insert, delete, update, select) have been tested thoroughly and seem to work pretty fine.</p>
  
  <p>Now for the last feature we have to implement a B+ tree, which is very difficult in my honest opinion.</p>
  
  <p>What we tried to do is first to implement a simple B+ tree that would work in the main memory(before implementing the file based version). After reading online about B+ theory and also studying various pseudocodes we have managed to create a recursive implementation and I used the debugger of VS2010 to test it and it seems like it works very well.</p>
  
  <p>The thing is, I would like to somewhat visualize the tree that is created because I believe this will make our life easier in debugging. I mean if you can see the tree like it actually is, then you can know for certain if the result is correct or not.</p>
  
  <p>So, let's take for example the simplest case.  Suppose the B+ tree has on its nodes 2 integers as data and three pointers to child nodes.</p>
  
  <p>Let's insert the numbers 40,50,48,20,57,49. From the following website: <a href="http://www.seanster.com/BplusTree/BplusTree.html" rel="nofollow noreferrer">http://www.seanster.com/BplusTree/BplusTree.html</a></p>
  
  <p>we get the following animation:</p>
  
  <p><img src="https://i.stack.imgur.com/mMRuy.png" alt="enter image description here"></p>
  
  <p>I added the arrows.</p>
  
  <p>Now I would like to print this tree in C++ in the following way:</p>
  
  <pre><code>          [48|50]
    [20|40] [48|49] [50|57]
  </code></pre>
  
  <p>however I'm not sure how I should do that. I have read about tree traversals for example preorder, postorder, inorder however I don't think they would help me achieve what I want.</p>
  
  <p>what I know is only the root node. From that root node, I must somewhat traverse the tree in the following way:</p>
  
  <ol>
  <li>visit root</li>
  <li>print root</li>
  <li>visit children of root</li>
  <li>print the values of each child</li>
  <li>for each child of the root, visit the children of it(which is the grandchildren of the root).</li>
  <li>print the values of the grand child</li>
  <li>do the same for the other grand children</li>
  <li>in the same way do the same for the children of the grand children etc</li>
  </ol>
  
  <p>What would be the best way to approach this problem? Thanks in advance</p>