Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] View of /sml/trunk/benchmarks/programs/tsp/tree.sml
ViewVC logotype

View of /sml/trunk/benchmarks/programs/tsp/tree.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 193 - (download) (annotate)
Fri Nov 20 17:43:59 1998 UTC (22 years, 10 months ago) by monnier
File size: 1079 byte(s)
Initial revision
(* tree.sml
 *
 * COPYRIGHT (c) 1994 AT&T Bell Laboratories.
 *
 * Trees for the TSP program.
 *)

structure Tree =
  struct

    datatype tree
      = NULL
      | ND of {
	    left : tree, right : tree,
	    x : real, y : real,
	    sz : int,
	    prev : tree ref, next : tree ref
	  }

    fun mkNode (l, r, x, y, sz) = ND{
	    left = l, right = r, x = x, y = y, sz = sz,
	    prev = ref NULL, next = ref NULL
	  }

    fun printTree (outS, NULL) = ()
      | printTree (outS, ND{x, y, left, right, ...}) = (
	  TextIO.output(outS, String.concat [
	    Real.toString x, " ", Real.toString y, "\n"]);
	  printTree (outS, left);
	  printTree (outS, right))

    fun printList (outS, NULL) = ()
      | printList (outS, start as ND{next, ...}) = let
	  fun cycle (ND{next=next', ...}) = (next = next')
	    | cycle _ = false
	  fun prt (NULL) = ()
	    | prt (t as ND{x, y, next, ...}) = (
		TextIO.output(outS, String.concat [
		    Real.toString x, " ", Real.toString y, "\n"
		  ]);
		if (cycle (!next))
		  then ()
		  else prt (!next))
	  in
	    prt start
	  end

  end;


root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0