44 lines
1.9 KiB
HTML
44 lines
1.9 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html>
|
|
<head>
|
|
<title>i231.tree.v4</title>
|
|
</head>
|
|
<body>
|
|
Write a method to build a tree from the right parenthetic string
|
|
representation (return the root node of the tree) and a method to
|
|
construct the left parenthetic string representation of a tree represented
|
|
by the root node <code>this</code>.
|
|
Tree is a pointer structure with two pointers
|
|
to link nodes of type <code>Node</code> - pointer to the first child
|
|
and pointer to the next sibling.
|
|
Build test trees and print the results in <code>main</code>-method,
|
|
do not forget to test a tree that consists of one node only.
|
|
Node name must be non-empty and must not contain round brackets, commas
|
|
and whitespace symbols.
|
|
In case of an invalid input string the <code>parsePostfix</code> method must
|
|
throw a <code>RuntimeException</code> with meaningful error message.
|
|
<br>
|
|
<br>
|
|
<code>public static Node parsePostfix (String s)</code>
|
|
<br>
|
|
<code>public String leftParentheticRepresentation()</code>
|
|
<br>
|
|
<br>
|
|
Koostage meetodid puu parempoolse suluesituse (<code>String</code>) järgi puu
|
|
moodustamiseks (<code>parsePostfix</code>, tulemuseks puu juurtipp) ning
|
|
etteantud puu vasakpoolse suluesituse leidmiseks stringina (puu juureks on
|
|
tipp <code>this</code>, meetod <code>leftParentheticRepresentation</code>
|
|
tulemust ei trüki, ainult tagastab <code>String</code>-tüüpi väärtuse).
|
|
Testige muuhulgas ka ühetipuline puu. Testpuude moodustamine ja tulemuse
|
|
väljatrükk olgu peameetodis. Puu kujutamisviisina kasutage viidastruktuuri
|
|
(viidad "esimene alluv" <code>firstChild</code> ja "parem naaber"
|
|
<code>nextSibling</code>, tipu tüüp on <code>Node</code>).
|
|
Tipu nimi ei tohi olla tühi ega sisaldada ümarsulge, komasid ega tühikuid.
|
|
Kui meetodile <code>parsePostfix</code> etteantav sõne on vigane, siis tuleb
|
|
tekitada asjakohase veateatega <code>RuntimeException</code>.
|
|
<br>
|
|
.
|
|
</body>
|
|
</html>
|