Last change
on this file was 127, checked in by Wouter Pasman, 6 years ago |
#41 ROLL BACK of rev.126 . So this version is equal to rev. 125
|
File size:
1.1 KB
|
Rev | Line | |
---|
[127] | 1 | package agents.anac.y2015.xianfa;
|
---|
| 2 |
|
---|
| 3 | import java.util.ArrayList;
|
---|
| 4 |
|
---|
| 5 | public class Tree {
|
---|
| 6 | private Node root;
|
---|
| 7 | //private int depth=0;
|
---|
| 8 | private ArrayList<ArrayList<Node>> nodes = new ArrayList<ArrayList<Node>>();
|
---|
| 9 | boolean setRoot = false;
|
---|
| 10 |
|
---|
| 11 | public Tree() {
|
---|
| 12 |
|
---|
| 13 | }
|
---|
| 14 |
|
---|
| 15 | public void addNewDepth() {
|
---|
| 16 | if (!setRoot) {
|
---|
| 17 | setRoot = true;
|
---|
| 18 | root = new Node();
|
---|
| 19 | ArrayList<Node> lvl1 = new ArrayList<Node>();
|
---|
| 20 | lvl1.add(root);
|
---|
| 21 | nodes.add(lvl1);
|
---|
| 22 | } else {
|
---|
| 23 | ArrayList<Node> newLvl = new ArrayList<Node>();
|
---|
| 24 | nodes.add(newLvl);
|
---|
| 25 | }
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | public void addNodeInDepth(Node node, int depth) {
|
---|
| 29 | nodes.get(depth).add(node);
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | public void setRoot(Node node) {
|
---|
| 33 | root = new Node();
|
---|
| 34 | ArrayList<Node> lvl1 = new ArrayList<Node>();
|
---|
| 35 | lvl1.add(root);
|
---|
| 36 | nodes.add(lvl1);
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | public Node getRoot() {
|
---|
| 40 | return root;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | public void addNode(Node node) {
|
---|
| 44 |
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | public int getSizeOfLevel(int depth) {
|
---|
| 48 | return nodes.get(depth).size();
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | public Node getMemberInLevel(int depth, int member) {
|
---|
| 52 | return nodes.get(depth).get(member);
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | public int getLevels() {
|
---|
| 56 | return nodes.size();
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.