package edu.neu.ccs.demeterf.examples;

import edu.neu.ccs.demeterf.*;
import edu.neu.ccs.demeterf.stackless.*;

public class StackLess{
    static void p(String s){ System.out.println(s); }
    public static void main(String[] args){
        Traversal trav = new Traversal(new Str());
        Traversal htrav = new HeapTrav(new Str());
        BT leaf = new BT();
        BT t = new Nd(leaf,new Nd(new Nd(leaf,leaf),new Nd(new Nd(leaf,leaf),leaf)));
        p("  Tree : "+trav.traverse(t));
        p(" HTree : "+htrav.traverse(t));
        p("  Tree : "+trav.traverse(t,0));
        p(" HTree : "+htrav.traverse(t,0));
    }
    
    static class Str extends ID{
        int update(Nd n, Fields.any f, int i){ return i+1; }
        String combine(BT t){ return "0"; }
        String combine(BT t, int i){ return ""+i; }
        String combine(Nd t, String l, String r){ return "("+l+", "+r+")"; }
    }
    
    static class BT{}
    static class Nd extends BT{
        BT left, right;
        public Nd(BT l, BT r){ left = l; right = r; }
    }
}