I am working on a binary search tree.. I am having a problem getting the nodes to left align on output. I am printing array order, pre-order,inorder,postorder... Array order format is left aligned like i want it to be.. Im basically using the same code( setw and left; in the same order) as array order as i am with preo order, and the rest.. However, it wont left align..
I have tried everything.. any tricks?
correct output..
Database Of Great Computer Scientists
>>> array order:
name leaf? index
---- ----- -----
Ralston, Anthony 0
Liang, Li 1
Von Neumann, John 2
Jones, Doug 3
Trigoboff, Michael 5
Goble, Colin leaf 7
Knuth, Donald 8
Turing, Alan leaf 12
Kay, Alan leaf 17
(items printed) (9)
>>> preorder:
name leaf? index
---- ----- -----
Ralston, Anthony 0
Liang, Li 1
Jones, Doug 3
Goble, Colin leaf 7
Knuth, Donald 8
Kay, Alan leaf 17
Von Neumann, John 2
Trigoboff, Michael 5
Turing, Alan leaf 12
(items printed) (9)
>>> inorder:
name leaf? index
---- ----- -----
Goble, Colin leaf 7
Jones, Doug 3
Kay, Alan leaf 17
Knuth, Donald 8
Liang, Li 1
Ralston, Anthony 0
Trigoboff, Michael 5
Turing, Alan leaf 12
Von Neumann, John 2
(items printed) (9)
>>> postorder:
name leaf? index
---- ----- -----
Goble, Colin leaf 7
Kay, Alan leaf 17
Knuth, Donald 8
Jones, Doug 3
Liang, Li 1
Turing, Alan leaf 12
Trigoboff, Michael 5
Von Neumann, John 2
Ralston, Anthony 0
(items printed) (9)
>>> retrieve Trigoboff, Michael
Trigoboff, Michael
>>> retrieve Kaye, Danny
not found
here is the code for inorder. The rest of the functions are almost identical in the way its set up to output..
void BST::displayInOrder(ostream& out, int parent)const
{
if (parent <= maxsize)
{
this->displayInOrder(out, 2 * parent + 1);
if (!items[parent].empty)
{
out << left
<< setw(27) << items[parent].instanceData;
out << right
<< setw(10);
if(!items[parent].isLeaf)
{
out << left
<< setw(11) << "leaf";
}
out << setw(12) << parent;
out << endl;
}
this->displayInOrder(out, 2 * parent + 2 );
}
if(!parent)
{
itemsPrinted(out,size);
}
}
and here is the array order code that left aligns..
void BST::displayArrayOrder (ostream& out) const
{
out << ">>> array order:" << endl;
displayHeaders(out);
for(int index=0; index < maxsize+1; index++)
{
if (!items[index].empty)
{
out << left
<< setw(27) << items[index].instanceData;
out << right
<< setw(10);
if(index > size)
{
items[index].isLeaf = false;
out << left
<< setw(10) << "leaf";
}
if(items[2*index+1].empty && items[2*index+2].empty && index < size)
{
items[index].isLeaf = false;
out << left
<< setw(11) << "leaf";
}
out << setw(12) << index;
out << endl;
}
}
if(!parent)
{
itemsPrinted(out,size);
}
}