#include<iostream.h>
#include<strstream.h>
#include<stk.h>
#include<LINK/stkWrapper/LINK_STk.h>
#include<LINK/stkWrapper/Wrapper.h>
#include<LINK/algorithm/Algorithms.h>
#include<LINK/algorithm/Partitioning.h>
#include<LINK/basic/Sequence.h>
#include<LINK/graph/Graph.h>
#include<LINK/graph/UBinGraph.h>
#include<LINK/graph/Edge.h>
#include<LINK/graph/Vertex.h>

static PRIMITIVE GenPruferWrapper(SCM elements, int len)
{
        SCM vlist, elist;
        Graph *g, **gp;
        char vname[10];
        Sequence<int> seq;

        if (len == 0)
                return wrapGraph(new MUBinGraph);
        if (STRINGP(CAR(elements))) {
		g = GenPrufer(STRING(CAR(elements)));
        } else {
        	SCM l=elements;
        	for (;;) {
                	if (NULLP(l))
                        	break;
                	if (!INTEGERP(CAR(l)))
				Err("gen-prufer: integer expected", CAR(l));
                	seq.append(INTEGER(CAR(l)));
                	l = CDR(l);
        	}
        	g = GenPrufer(seq.size()+2, seq);
        }
        return wrapGraph(g);
}

void gen_Prufer_Wrapper()
{
        STk_add_new_cpp_primitive("gen-prufer", tc_lsubr,
				 (PRIMITIVE (*)(...))GenPruferWrapper);
}
