I am working on a program where I am trying to solve a tree structure using the Node function

I have to perfomr a arithmetic operation example ((1+2)*3) using a tree structure with left and right child. the complexity being I need to randomly generate the constants as well as the operators.

I am using the below structure to create and evaluate the nodes.

Please help me to assign random values to the operands. I am done gicing random values to the constants how I can intoduce random values to the operands in the below expression?

Node n = new Operand1(new Operand2(new Const(1), new Const(2)),new Const(3));

Create a small array of operands (do you mean operators, or maybe operations?) and use a random int to select one element from the array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.