Generated on Thu Nov 2 14:49:35 2006 for Gecode/J by doxygen 1.5.0

PreOrderNodeVisitor.java

Go to the documentation of this file.
00001 /* -*- indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Marco Kuhlmann <kuhlmann@ps.uni-sb.de>
00005  *
00006  *  Copyright:
00007  *     Marco Kuhlmann, 2005
00008  *
00009  *  Last modified:
00010  *     $Date: 2006-10-26 11:31:58 +0200 (Thu, 26 Oct 2006) $ by $Author: tack $
00011  *     $Revision: 3796 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  See the file "LICENSE" for information on usage and
00018  *  redistribution of this file, and for a
00019  *     DISCLAIMER OF ALL WARRANTIES.
00020  *
00021  */
00022 
00023 package org.gecode.gist;
00024 
00025 
00026 public class PreOrderNodeVisitor extends DefaultNodeVisitor {
00027     
00028     public PreOrderNodeVisitor(NodeCursorInterface theCursor) {
00029         super(theCursor);
00030     }
00031     
00032     private void backtrack() {
00033         while (! cursor.mayMoveSidewards() && cursor.mayMoveUpwards()) {
00034             cursor.moveUpwards();
00035         }
00036         if (! cursor.mayMoveUpwards()) {
00037             cursor = null;
00038         } else {
00039             cursor.moveSidewards();
00040         }
00041     }
00042     
00043     public boolean next() {
00044         cursor.processCurrentNode();
00045         if (cursor.mayMoveDownwards()) {
00046             cursor.moveDownwards();
00047         } else if (cursor.mayMoveSidewards()) {
00048             cursor.moveSidewards();
00049         } else {
00050             backtrack();
00051         }
00052         return (cursor != null);
00053     }
00054         
00055 }