Java/Abstract Classes: Difference between revisions
From charlesreid1
(Created page with "<pre> public abstract class Tree { abstract Node root(); abstract Node parent(Node n); abstract int num_children(Node n); abstract Node children(Node n); } </pre>") |
No edit summary |
||
| Line 1: | Line 1: | ||
Example: defining an abstract Tree type that implements abstract methods for some of the methods required by the Tree ADT: | |||
* element() | |||
* root() | |||
* is_root | |||
* parent | |||
* num_children | |||
* is_leaf | |||
<pre> | <pre> | ||
public abstract class Tree { | public abstract class Tree { | ||
| Line 5: | Line 13: | ||
abstract int num_children(Node n); | abstract int num_children(Node n); | ||
abstract Node children(Node n); | abstract Node children(Node n); | ||
abstract boolean is_leaf(Node n); | |||
abstract int length(); | |||
abstract boolean isEmpty(); | |||
// positions() - iteration of all Nodes in the tree | |||
// iter() - iteration of all elements in the tree | |||
} | } | ||
</pre> | </pre> | ||
Revision as of 00:16, 7 June 2017
Example: defining an abstract Tree type that implements abstract methods for some of the methods required by the Tree ADT:
- element()
- root()
- is_root
- parent
- num_children
- is_leaf
public abstract class Tree {
abstract Node root();
abstract Node parent(Node n);
abstract int num_children(Node n);
abstract Node children(Node n);
abstract boolean is_leaf(Node n);
abstract int length();
abstract boolean isEmpty();
// positions() - iteration of all Nodes in the tree
// iter() - iteration of all elements in the tree
}