Stacks

Plant Architecture: Bracketed L-Systems. A fascinating algorithm for rendering images of plants involves perpetuating a string of coded characters that are, in turn, interpeted by a drawing pen or turtle. Two dimensional examples created by the class of 2006-7 appear at the right. Here's a 3D example. The orginal idea is credited to Astrid Lindenmayer, who proposed, in 1968, "an axiomatic theory of development" for plant structure. Hence the name L-Systems.

In this in-class exercise, you are asked to supply the code necessary to reproduce the images described on Page 25, using the driver Garden.java. Add the missing code to produce the graphic at the top right.


Reverse Polish Notation. In this assignment, you are to evaluate a simple arithmetic expression, supplied in postfix notation (also called Reverse Polish Notation). For example, consider the standard infix notation, 2*(3+4). Written as an RPN expression, it would appear as 234+*. Develop the class, Expression, that contains the methods,

public void setRPN(String rpn)

and

public double evaluate()

The ExpressionTest.java driver should return output similar to,


Bracket Matching. Create a project entitled Brackets and download the file Brackets.java as the driver. You will also require, ArrayStack.java and Stack.java in your project. Complete the body of the recursive method,

private static boolean BracketsMatch(String L, int i)

so the output yields,

Algorithm. The approach involves a push of the open (left) brackets onto a Stack as they are encountered. An occurrence of a close (right) brackets signals a pop (if possible) the top element from the Stack and a comparison to confirm it is a match. If it is, keep processing. The task is complete if the end of the String is encountered and there a no more eements on the Stack.