Esempio n. 1
0
  @SuppressWarnings("all")
  public static void main(String[] args) {

    LinkedTree<String> T = new LinkedTree<String>();
    // TreeNode<String> r = new TreeNode<String>();

    // Position<String> r = T.addRoot("r");

    // r=new TreeNode<String>("s",null,null);
    T.addRoot("s");
    Position<String> r = T.root();
    Position<String> a = T.addChild("a", r);
    Position<String> b = T.addChild("b", r);
    Position<String> c = T.addChild("c", a);
    Position<String> e = T.addChild("e", b);
    Position<String> f = T.addChild("f", b);
    Position<String> h = T.addChild("h", f);
    Position<String> i = T.addChild("i", f);

    Iterable<Position<String>> collezione = T.positions();
    for (Position<String> u : collezione) System.out.print(u.element() + " ");

    System.out.println(
        "\n\nNumero di foglie dell'albero radicato in "
            + T.root().element()
            + ": "
            + numberLeaves(T, T.root()));

    //		//System.out.println("Ancestor (b, g) : " + T.ancestor(b,g));
    //		System.out.println("Ancestor (a, b) : " + T.ancestor(a,b));
    //

    System.out.println("nodi a profondità 2 : ");
    NodePositionList<Position<String>> l = (NodePositionList<Position<String>>) atDepth(T, 2);
    for (Position<String> s : l) System.out.print(s.element() + " ");

    //		System.out.println("\n\nCammino da c a f: ");
    //		NodePositionList<Position<String>> x = (NodePositionList<Position<String>>) T.path(c, f);
    //		for(Position<String> s : x)
    //			System.out.print(s.element() + " ");

    //		System.out.println("\n\nCammino da c a i: ");
    //		x = (NodePositionList<Position<String>>) T.path(c, i);
    //		for(Position<String> s: x)
    //			System.out.print(s.element() + " ");
    //
    //		System.out.println("\n\nCammino da c a h: ");
    //		x = (NodePositionList<Position<String>>) T.path(c, h);
    //		for(Position<String> s: x)
    //			System.out.print(s.element() + " ");
    //

    System.out.println("\nMetodo traccia d'esame 14/01/2009 B : ");

    // T.remove(a);

    System.out.println("\nVisita preOrder dopo la rimozione di f: ");
    PositionList<Position<String>> preOrder = new NodePositionList<Position<String>>();
    T.preorderPositions(r, preOrder);
    for (Position<String> p : preOrder) System.out.print(p.element() + " ");
  }
 /** @return */
 @Override
 public String toString() {
   return currentLocation.toString() + " " + currentPosition.toString();
 }
 /** @return configuration if the rover rotated right maintaing the same location */
 public RoverConfiguration rotateRightConfiguration() {
   return new RoverConfiguration(currentPosition.rightPosition(), currentLocation);
 }
 /**
  * @return configuration if the rover moved one step maintaing the same position
  * @throws IllegalArgumentException if the next position lies beyond the plateau grid
  */
 public RoverConfiguration moveForwardConfiguration() {
   return new RoverConfiguration(currentPosition, currentPosition.nextLocation(currentLocation));
 }
 /** @return configuration if the rover rotated left maintaing the same location */
 public RoverConfiguration rotateLeftConfiguration() {
   return new RoverConfiguration(currentPosition.leftPosition(), currentLocation);
 }