LISPPA: Euler algorithm (paxJavaScript).


function Cycle(InitV, A){
  var P, Stack, result, U, V;
  result = NULL;
  Stack = [InitV, NULL];
  while (Stack != NULL) {
    V = Stack[0];
    P = & A[V];
    if (P != NULL) {
      U = P[0];
      reduced P = P[1];
      Stack = [U, Stack];
      P = & A[U];
      while (P != NULL) {
        if (P[0] == V) {
          reduced P = P[1];
          break;
        }
        P = & P[1];
      }
    }
    else {
      reduced Stack = Stack[1];
      result = [V, result];
    }
  }
  return result;
}

var A[10], Path, P;

A[1] = [2, [3, NULL]];
A[2] = [1, [3, [7, [8, NULL]]]];
A[3] = [1, [2, [4, [5, NULL]]]];
A[4] = [3, [5, NULL]];
A[5] = [3, [4, [6, [8, NULL]]]];
A[6] = [5, [7, [8, [9, NULL]]]];
A[7] = [2, [6, [8, [9, NULL]]]];
A[8] = [2, [5, [6, [7, NULL]]]];
A[9] = [6, [7, NULL]];

Path = Cycle(1, A);

println 'Euler path: ';
P = & Path;
while (P != NULL) {
  println P[0];
  P = & P[1];
}


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