title: Packing of rectangles with given width and length
body: <p>I have a tree with rectangles in the leaf nodes, and a 'V' or a 'H' in internal nodes. I want to pack the rectangles, given their width and height. If theres a 'V', I will pack the left and the right child, and if theres a 'H', i want to pack the left child on top of the right child. In the end I want to determine the coordinates of each rectangle. I have attached an image showing the tree and the constructed packing. </p>
  
  <p><img src="https://i.stack.imgur.com/DhsrE.jpg" alt="enter image description here"></p>
  
  <p>What I'm doing is, I am going through each node in the tree. When it reaches a leaf node, it builds a struct rectangle and stores it into an array. Then when it reaches a 'V', I simply change my x-coordinate of the last rectangle in the array by adding the width of the second last rectangle in the array. I construct a new rectangle, that that fits the entire set of last rectangles and put it in the array. If I get an 'H', I increment the y coordinate of the specific rectangles in the array. However, I am having trouble doing this, as I dont know which all rectangles y coordinate should be changes. There can be any number of such rectangles. PLEASEE HELP!!</p>