[ Back to the overview Matrix ]

Test case : Sort 2 using Algol 68

Lines used: 15
call by "a68g sort2.a68g - file-to-be-sorted
BEGIN FILE in, out; STRING s;
      VOID (open (in, argv (4 #sic# ), standin channel));
      VOID (open (out, "sorted.txt", standout channel));

      MODE STREE = STRUCT (STRING s, REF STREE left, right);
      REF STREE lines := NIL;
      PROC add = (STRING s, REF REF STREE marker) VOID:
	  ( marker IS REF STREE (NIL) | marker := HEAP STREE := (s, NIL, NIL)
	    | add (s, (s < s OF marker | left OF marker | right OF marker)) );
      PROC list = (REF STREE here) VOID:
	  ( here ISNT NIL | list (left OF here);
			    put (out, (s OF here, newline));
			    list (right OF here) );

      on logical file end (in, (REF FILE f) BOOL: (list (lines); stop));
      DO get (in, (s, newline));  add (s, lines) OD
END                                                    
Contributed by andrew.walker at nottingham.ac.uk