LISPPA: Euler algorithm (paxPascal).


program EulerAlgorithm;

function Cycle(InitV, A: Variant): Variant;
var
  P, Stack, U, V;
begin
  result := nil;
  Stack := [InitV, nil];
  while Stack <> nil do
  begin
    V := Stack[0];
    P := @ A[V];
    if P <> nil then
    begin
      U := P[0];
      reduced P := P[1];
      Stack := [U, Stack];
      P := @ A[U];
      while P <> nil do
      begin
        if P[0] = V then
        begin
          reduced P := P[1];
          break;
        end;
        P := @ P[1];
      end;
    end
    else
    begin
      reduced Stack := Stack[1];
      result := [V, result];
    end;
  end;
end;

var 
  A[10], Path, P: Variant;

begin
  A[1] := [2, [3, nil]];
  A[2] := [1, [3, [7, [8, nil]]]];
  A[3] := [1, [2, [4, [5, nil]]]];
  A[4] := [3, [5, nil]];
  A[5] := [3, [4, [6, [8, nil]]]];
  A[6] := [5, [7, [8, [9, nil]]]];
  A[7] := [2, [6, [8, [9, nil]]]];
  A[8] := [2, [5, [6, [7, nil]]]];
  A[9] := [6, [7, nil]];

  Path := Cycle(1, @ A);

  writeln('Euler path:');
  P := @ Path;
  while P <> nil do
  begin
    writeln(P[0]);
    P := @ P[1];
  end;
end.


Copyright © 1999-2006 VIRT Laboratory. All rights reserved.