Hi Guys,

Here's the situation that im stuck in.
I have 2 Header files which cannot be changed named bintree and bindnode. These define tree structure, aswell as several other functions eg inserting node, printing node etc

I have 2 Classes.

1 Class is :

class mazePoint
{int x;
char c;

Which has declare int x (for a character position) and char c;

2 Class is :

class mazeRow
{ bintree<mazePoint> row;
int y;}

Which has declared a tree of the mazepoints, with a int y for row number.

My problem is as follows : When i print the points out itself i get the characters each in a new line. This is because the print function (which cannot be changed) is as follows

void print() const {
	     if (left != NULL) left->print();
		 std::cout << nodeData.toString() << "\n";
		 if (right != NULL) right->print();

the "\n" makes a new line for each character so out come is as follows



and so forth - versus
#######s # (how it should be - a row)

this is becuase i am doing the toString function in mazePoint.

string mazePoint::toString() const
   stringstream line;
   string s;
   line << c;
   return line.str();

i tried move the toString function to mazeRow, but dont know what to call i.e in the above one it is using the char c (which stores the value).

I want to be able to print c as a row, rather than just print c.

Does anyone know how to do this.

I was thinking using the -> from mazeRow for int value y to a char to print.
But dont know how to do this.

Anyone have an idea. this is really important (for an assignment due soon).

I would like to add that, if i remove the "\n" (for testing purposes) it works correctly. therefore i am assuming, it is printing each row correctly, but for each char it is doing a further "\n".

I believe the solution is to use toString from row, and call the print() from mazePoint. But dont know how to do this at all.

The print function is stored with the binnode.h File.

This article has been dead for over six months. Start a new discussion instead.